getopt_long: avoid variable global initialization
authorCheng Li <72431553+chengli-rutgers@users.noreply.github.com>
Tue, 13 Oct 2020 17:03:12 +0000 (10:03 -0700)
committerCheng Li <chenglii@scarletmail.rutgers.edu>
Tue, 13 Oct 2020 18:23:48 +0000 (11:23 -0700)
Issue #1100 shows that an address sanitizer(ASAN) complains about a few
global variables that are initialized globally in the getopt_long.c file.
We look into these variables and found they do not need to be initialized
globally. This patch fixes the issue by cleaning up the global
initialization for these variables.

Fixes https://github.com/axboe/fio/issues/1100
Signed-off-by: Cheng Li <chenglii@cs.rutgers.edu>
oslib/getopt_long.c

index 8ec77413b7a7a6fe507dbb3b3fae90a761fb00eb..463919fb7ba2102ce5cc04748d6806929583c154 100644 (file)
@@ -16,8 +16,8 @@
 
 #include "getopt.h"
 
-char *optarg = NULL;
-int optind = 0, opterr = 0, optopt = 0;
+char *optarg;
+int optind, opterr, optopt;
 
 static struct getopt_private_state {
        const char *optptr;