Re: strstr.c:105:3: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode

Orlando Arias <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <[email protected]>
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
signature.asc (application/pgp-signature, 195 B)
-----BEGIN PGP SIGNATURE-----

iFwEARECAB0WIQQNWDJzd34+k5noE3NTFb9QFn4uoQUCXVIBwwAKCRBTFb9QFn4u
ocZGAJQKor4KXfb7iqNAAd4X5yXIPuDRAJ99IKD1EgdohOKb7mKrjZPSP2eDMg==
=IymL
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.