summaryrefslogtreecommitdiff
path: root/nuttx
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-01-20 13:13:36 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-01-20 13:13:36 -0600
commit8d9d900abe1f1f70532ddcb9472b7ebb85af5a37 (patch)
treef2f1f92ae4eefefcdce81eb92345ac2c6aef9329 /nuttx
parent961781de129e7c63402cee78590d2d2d24b09b10 (diff)
downloadnuttx-8d9d900abe1f1f70532ddcb9472b7ebb85af5a37.tar.gz
nuttx-8d9d900abe1f1f70532ddcb9472b7ebb85af5a37.tar.bz2
nuttx-8d9d900abe1f1f70532ddcb9472b7ebb85af5a37.zip
getopt(): Could leave optind in undefined state if argc == 1
Diffstat (limited to 'nuttx')
-rw-r--r--nuttx/ChangeLog2
-rw-r--r--nuttx/libc/unistd/lib_getopt.c4
2 files changed, 6 insertions, 0 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog
index 8673c594f..51378242f 100644
--- a/nuttx/ChangeLog
+++ b/nuttx/ChangeLog
@@ -6485,4 +6485,6 @@
compiler option when building for a 32-bit target on a native 64-bit
compiler (2014-1-18).
* include/ctype.h: Typo in macro name: iscntrol, not iscontrol (2104-1-17)
+ * libc/unistd/lib_getopt.c: If there are no arguments (argc == 1), then
+ getopt() make like the optind variable in an undefined state (2014-1-20).
diff --git a/nuttx/libc/unistd/lib_getopt.c b/nuttx/libc/unistd/lib_getopt.c
index 1a9190976..4399e6140 100644
--- a/nuttx/libc/unistd/lib_getopt.c
+++ b/nuttx/libc/unistd/lib_getopt.c
@@ -264,6 +264,10 @@ int getopt(int argc, FAR char *const argv[], FAR const char *optstring)
return noarg_ret;
}
+ /* Restore the initial, uninitialized state */
+
g_binitialized = false;
+ optind = 1;
+ optopt = '?';
return ERROR;
}