incubator-stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Sebor <>
Subject [PATCH] problems in eval_options()
Date Thu, 03 Aug 2006 17:49:38 GMT
I've discovered a number of problems with the eval_options() function
(see below). The attached patch implements fixes for them all. Andrew,
let me know if you see any problems with it. If not, I'll commit it
later today.

Btw., as an FYI, C99 strtol() is declared to take a couple of restrict

     long int strtol(const char * restrict nptr,
                     char ** restrict endptr,
                     int base);

which means that the behavior of the function is undefined when
(nptr == &nptr) is true. I fixed this as well.


1. Undefined behavior for "-t"
$ ./exec -t
Segmentation Fault (core dumped)

2. Negative argument to -t not diagnosed:
$ ./exec -t -1; echo $?

3. Poor diagnostic of invalid argument to -t:
$ ./exec -t 1x
./exec: Unknown value for -t: x

4. Abort on missing option argument:
$ ./exec --exit
Assertion failed: 0 != opt, file /build/sebor/stdcxx/util/cmdopt.cpp, 
line 141
Abort (core dumped)

5. Missing text for invalid argument:
$ ./exec --exit=9999999999
./exec: Unknown value for --exit:

6. Invalid argument to --signal and --ignorte not diagnosed:
$ ./exec --signal 12345; echo $?
$ ./exec --ignore 12345; echo $?

With the patch applied:

$ ./exec -t
./exec: Missing argument for -t
$ ./exec -t -1
./exec: Bad argument for -t: -1
$ ./exec -t 1x
./exec: Bad argument for -t: 1x
$ ./exec --exit
./exec: Missing argument for --exit
$ ./exec --exit=9999999999
./exec: Bad argument for --exit: 9999999999
$ ./exec --signal 12345
./exec: kill(20842, SIG#12345) failed: Invalid argument
$ ./exec --ignore 12345 
      ./exec: sigaction(SIG#12345, ...) failed: Invalid argument

View raw message