Re: [PATCH v8 02/31] kallsyms: avoid hardcoding buffer size

From: Rasmus Villemoes
Date: Tue Aug 02 2022 - 05:45:33 EST


On 02/08/2022 10.29, David Laight wrote:
> From: Miguel Ojeda
>> Sent: 02 August 2022 02:50

>> - rc = fscanf(in, "%llx %c %499s\n", &addr, &type, name);
>> + rc = fscanf(in, "%llx %c %" _stringify(KSYM_NAME_LEN_BUFFER) "s\n", &addr, &type, name);
>
> Think I'd use "%*s" - simpler.
> Although I normally completely avoid scanf() - too easy to get wrong.

Indeed, and your suggestion is a perfect example: for scanf, * doesn't
mean "there's an int argument specifying the 'precision'", quite the
contrary. man fscanf:

• An optional '*' assignment-suppression character: scanf()
reads input as directed by the conversion specification, but
discards the input. No corresponding pointer argument is re‐
quired, and this specification is not included in the count of
successful assignments returned by scanf().

Rasmus