From 6896d052f9bbf276d5ae7a7db03405ba5409773c Mon Sep 17 00:00:00 2001 From: Jihun Ahn Date: Fri, 12 May 2017 15:53:34 +0900 Subject: [PATCH] examples/timer: initialize index of options Currently, index isn't initialized, it caused abnormal behavior after someone calls getopt(). So, this commit add initialize the optind. Change-Id: I71afe5a90827cf5719ef28c56d5202af2e587d7f Signed-off-by: Jihun Ahn --- apps/examples/timer/timer_main.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/apps/examples/timer/timer_main.c b/apps/examples/timer/timer_main.c index 5e4c609..692546d 100644 --- a/apps/examples/timer/timer_main.c +++ b/apps/examples/timer/timer_main.c @@ -213,6 +213,8 @@ int timer_main(int argc, char *argv[]) int intval = -1; int repeat = -1; + optind = 0; + while ((opt = getopt(argc, argv, "t:n:f:h")) != -1) { switch (opt) { case 't': @@ -231,6 +233,12 @@ int timer_main(int argc, char *argv[]) } } + if (optind >= argc) { + fprintf(stderr, "timer: invalid option -- \'%s\'\n", argv[optind]); + fprintf(stdout, USAGE); + return EXIT_SUCCESS; + } + /* Open the timer device */ sprintf(path, TIMER_DEVNAME, dev); fprintf(stdout, "Open %s\n", path); -- 2.7.4