Re: strstr.c:105:3: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
Orlando Arias
orlandoarias@gmail.com
Tue Aug 13 00:13:00 GMT 2019
On 8/12/19 8:05 PM, Howland, Craig D. - US via newlib wrote:
[snip]
>> for (int i = 0; i < ne_len; i++)
>> ^
[snip]
>
>
> A quick fix for you is to do what the error message suggests: add -std=gnu99 to CFLAGS before you configure Newlib, to have that as a default compiler flag when it is built.
> This is probably also the best solution for the real fix in Newlib. There are other cases of C99 constructs being used, anyway. (It has been 20 years. Seems totally reasonable to require it.)
> Craig
>
Greetings,
There is still a lingering bug in the code above, and the proposed patch
in [1]. It will trigger undefined behavior due to the comparison of a
signed type and an unsigned type. If the value of ne_len or similar is
over INT_MAX, the comparison will always fail and cause an integer
overflow, resulting in undefined behavior [signed overflow is UB per C
standard]. The datatype that should be used in these iterations is
size_t. I do agree however that requiring C99 or newer to compile newlib
should be a thing.
Cheers,
Orlando.
[1] https://sourceware.org/ml/newlib/2019/msg00469.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: OpenPGP digital signature
URL: <http://sourceware.org/pipermail/newlib/attachments/20190813/72ad9300/attachment.sig>
More information about the Newlib
mailing list