[PATCH 01/15] stdio-common: Don't read real input beyond the field width in scanf [BZ #13988]
Florian Weimer
fweimer@redhat.com
Mon May 19 19:11:47 GMT 2025
* Maciej W. Rozycki:
> On Tue, 6 May 2025, Andreas Schwab wrote:
>
>> > @@ -1657,7 +1657,8 @@ __vfscanf_internal (FILE *s, const char
>> > break;
>> > else
>> > {
>> > - if (avail == 0 || inchar () == EOF)
>> > + if ((avail == 0 && (c = EOF))
>>
>> Please avoid assignment in a conditional.
>
> It is valid C and weighing pros and cons I concluded it'd be the most
> straightforward approach here. Rewriting this piece such as to avoid the
> inline assignment will make code more complex I'm afraid.
>
> I might be wrong, so may I ask for a second opinion?
Please follow Andreas' suggestion. I think this is equivalent to
if (avail == 0)
{
c = EOF;
errno = inchar_errno;
break;
}
but I'm not sure if this makes sense. In particular, we seem to call
ungetc (c, s) further down?
Thanks,
Florian
More information about the Libc-alpha
mailing list