Initialize optind before getopt 86/226886/2
authorKichan Kwon <k_c.kwon@samsung.com>
Fri, 6 Mar 2020 03:02:04 +0000 (12:02 +0900)
committerKichan Kwon <k_c.kwon@samsung.com>
Wed, 11 Mar 2020 11:23:07 +0000 (20:23 +0900)
- getopt doesn't initialize optind
- So, we must reset it on each subsequent call

Change-Id: I4f5bd874a8daeef12d7234a21e6975e9cbe7c846
Signed-off-by: Kichan Kwon <k_c.kwon@samsung.com>
src/battery_dump/bd_history_item.c

index 4dfbf84..6957e16 100644 (file)
@@ -1315,6 +1315,11 @@ int bd_callback(const int fd, const int argc, char **argv)
        int opt;
        bool checkin = false;
 
+       /**
+        * We must reset optind because it isn't initialized
+        * on subsequent getopt calls
+        */
+       optind = 1;
        while ((opt = getopt(argc, argv, "c")) != -1) {
                switch (opt) {
                case 'c':