This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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

Attachment: signature.asc
Description: OpenPGP digital signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]