This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: parameter type of -frandom-seed
- From: Martin Sebor <msebor at gmail dot com>
- To: Stephan Gatzka <stephan dot gatzka at gmail dot com>, gcc-help at gcc dot gnu dot org
- Date: Thu, 27 Aug 2015 09:31:08 -0600
- Subject: Re: parameter type of -frandom-seed
- Authentication-results: sourceware.org; auth=none
- References: <1440521295 dot 3861 dot 3 dot camel at gmail dot com> <55DCFD7A dot 3090609 at gmail dot com> <1440653742 dot 3277 dot 11 dot camel at gmail dot com>
On 08/26/2015 11:35 PM, Stephan Gatzka wrote:
Thanks for the answer.
but it looks like there's a bug in the option's specification that
prevents invalid (non-numeric) arguments from being diagnosed, making
GCC accept anything (including negative numbers).
True, it accept strings and negative decimal numbers and hexadecimal
numbers and even gives me identical binaries...
So you would say that the only valid parameter to -frandom-seed is an
unsigned decimal number?
-frandom-seed=18464 // correct
-frandom-seed=a48cb9 //wrong
-frandom-seed=foobar //wrong
That is what I said, yes.
GCC 5 documents a numeric argument. Earlier versions of gcc document
a string argument. This was changed in commit cf3579 without adjusting
the option specification to reject non-numeric or negative arguments.
The option argument is processed in the set_random_seed function in
toplev.c. The function takes a string argument and calls strtoul on
it to obtain the numeric random seed (strtoul is called with the base
argument of zero letting it detect it from the prefix). When strtoul
fails, set_random_seed calls crc32_string with the string argument.
So the function is capable of processing both numeric and string
arguments. I suppose the question is whether GCC should should be
changed back to accept string arguments as originally implemented,
or whether it should stay as is and the option specification changed
to match the documentation. Either way, there are problems here that
should be fixed.
Martin