[PATCH] stdio: make scanf(%f) eat the same number of characters as strtod() would

Miklós Máté mtmkls@gmail.com
Thu Jan 2 15:44:19 GMT 2025


On 02/01/2025 11:14, Florian Weimer wrote:
> * Miklós Máté:
>
>> diff --git a/stdio-common/vfscanf-internal.c b/stdio-common/vfscanf-internal.c
>> index 87f23b5845..c3d4e81476 100644
>> --- a/stdio-common/vfscanf-internal.c
>> +++ b/stdio-common/vfscanf-internal.c
>> @@ -2582,6 +2582,17 @@ digits_extended_fail:
>>   		*ARG (float *) = d;
>>   	    }
>>   
>> +          if (__glibc_unlikely (char_buffer_size (&charbuf) > tw - char_buffer_start (&charbuf)))
>> +            {
>> +              --charbuf.current; /* We have the read chars plus a '\0'.  */
>> +              int n = char_buffer_size (&charbuf) - (tw - char_buffer_start (&charbuf));
>> +              for (int i = 0; i < n; ++i)
>> +                {
>> +                  c = *(--charbuf.current);
>> +                  ungetc_not_eof (c, s);
>> +                }
>> +            }
>> +
> We cannot safely perform multiple ungetc calls like this because they
> might require the use of malloc, and we cannot report failure here.
>
> Thanks,
> Florian
>
The integer conversion does this in multiple places, though.


More information about the Libc-alpha mailing list