incubator-stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Black <abl...@roguewave.com>
Subject Re: [PATCH] problems in eval_options()
Date Thu, 03 Aug 2006 21:12:44 GMT
Greetings Martin

I've glanced over the patch and have attached a revised version that I 
feel is a tad more consistent.
* Invalid/missing options error messages are now routed through the 
(new) bad_value and missing_value functions.  I prefer these to calling 
terminate(), as they also display the usage instructions when the option 
is incorrectly used.
* the -d and -x switches now check for a missing value for consistency 
with the -t switch.
* use 'sizeof option - 1' rather than a magic constant for parameter 3 
when calling get_long_val
* Removed superfluous assignment to optname for the compat and nocompat 
switches (This one's debatable).
* Moved declaration of act struct in one conditional

--Andrew Black

Martin Sebor wrote:
> 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
> pointers:
> 
>     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.
> 
> Martin
> 
> 1. Undefined behavior for "-t"
> $ ./exec -t
> Segmentation Fault (core dumped)
> 
> 2. Negative argument to -t not diagnosed:
> $ ./exec -t -1; echo $?
> 0
> 
> 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 $?
> 0
> $ ./exec --ignore 12345; echo $?
> 0
> 
> 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

Mime
View raw message