lkml.org 
[lkml]   [2022]   [Aug]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH v8 02/31] kallsyms: avoid hardcoding buffer size
From
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

\
 
 \ /
  Last update: 2022-08-02 11:46    [W:1.532 / U:0.000 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site