aboutsummaryrefslogtreecommitdiff
path: root/libbb/getopt32.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-08-20 23:03:38 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-08-20 23:03:38 +0000
commite417be669766417bc6b0783e1e94fbf5d34e10d3 (patch)
treefdda51e1342049b8596eef1cb698f93dd29ae7e2 /libbb/getopt32.c
parentb9c262b0296de501c387539abd67d324e33ddcea (diff)
downloadbusybox-w32-e417be669766417bc6b0783e1e94fbf5d34e10d3.tar.gz
busybox-w32-e417be669766417bc6b0783e1e94fbf5d34e10d3.tar.bz2
busybox-w32-e417be669766417bc6b0783e1e94fbf5d34e10d3.zip
getopt32: do not return pointer to alloca() areas
Diffstat (limited to 'libbb/getopt32.c')
-rw-r--r--libbb/getopt32.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/libbb/getopt32.c b/libbb/getopt32.c
index 54dc7857d..8fb99b6cc 100644
--- a/libbb/getopt32.c
+++ b/libbb/getopt32.c
@@ -155,12 +155,20 @@ Special characters:
155 Allows any arguments to be given without a dash (./program w x) 155 Allows any arguments to be given without a dash (./program w x)
156 as well as with a dash (./program -x). 156 as well as with a dash (./program -x).
157 157
158 NB: getopt32() will leak a small amount of memory if you use
159 this option! Do not use it if there is a possibility of recursive
160 getopt32() calls.
161
158 "--" A double dash at the beginning of opt_complementary means the 162 "--" A double dash at the beginning of opt_complementary means the
159 argv[1] string should always be treated as options, even if it isn't 163 argv[1] string should always be treated as options, even if it isn't
160 prefixed with a "-". This is useful for special syntax in applets 164 prefixed with a "-". This is useful for special syntax in applets
161 such as "ar" and "tar": 165 such as "ar" and "tar":
162 tar xvf foo.tar 166 tar xvf foo.tar
163 167
168 NB: getopt32() will leak a small amount of memory if you use
169 this option! Do not use it if there is a possibility of recursive
170 getopt32() calls.
171
164 "-N" A dash as the first char in a opt_complementary group followed 172 "-N" A dash as the first char in a opt_complementary group followed
165 by a single digit (0-9) means that at least N non-option 173 by a single digit (0-9) means that at least N non-option
166 arguments must be present on the command line 174 arguments must be present on the command line
@@ -493,7 +501,10 @@ getopt32(char **argv, const char *applet_opts, ...)
493 pargv = argv + 1; 501 pargv = argv + 1;
494 while (*pargv) { 502 while (*pargv) {
495 if (pargv[0][0] != '-' && pargv[0][0] != '\0') { 503 if (pargv[0][0] != '-' && pargv[0][0] != '\0') {
496 char *pp = alloca(strlen(*pargv) + 2); 504 /* Can't use alloca: opts with params will
505 * return pointers to stack!
506 * NB: we leak these allocations... */
507 char *pp = xmalloc(strlen(*pargv) + 2);
497 *pp = '-'; 508 *pp = '-';
498 strcpy(pp + 1, *pargv); 509 strcpy(pp + 1, *pargv);
499 *pargv = pp; 510 *pargv = pp;