[parted-devel] Problem with Linux "3.0"

Jim Meyering jim at meyering.net
Tue Jun 7 15:53:15 UTC 2011


H. Peter Anvin wrote:

> On 06/06/2011 11:21 PM, Jim Meyering wrote:
>> H. Peter Anvin wrote:
>>> On 06/05/2011 09:17 AM, Jim Meyering wrote:
>>>>
>>>> diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
>>>> index aeaf98f..111816c 100644
>>>> --- a/libparted/arch/linux.c
>>>> +++ b/libparted/arch/linux.c
>>>> @@ -610,7 +610,11 @@ _get_linux_version ()
>>>>
>>>>          if (uname (&uts))
>>>>                  return kver = 0;
>>>> -        if (sscanf (uts.release, "%u.%u.%u", &major, &minor, &teeny) != 3)
>>>> +        if (sscanf (uts.release, "%u.%u.%u", &major, &minor, &teeny) == 3)
>>>> +                ; /* ok */
>>>> +        else if (sscanf (uts.release, "%u.%u", &major, &minor) == 2)
>>>> +                teeny = 0;
>>>> +        else
>>>>                  return kver = 0;
>>>>
>>>
>>> How about:
>>>
>>> major = minor = teeny = 0;
>>> sscanf(uts.release, "%u.%u.%u", &major, &minor, &teeny);
>>>
>>> return kver = KERNEL_VERSION(major, minor, teeny);
>>
>> Thanks, that would work, modulo an invalid uts.release -- admittedly
>> unlikely -- but I prefer not to ignore sscanf's return value.
>
> Uh... in that case you set the return value to zero anyway!

Yes, just like the original code.
The reason I prefer not to ignore the return value is to avoid
warnings from static analyzers.

Actually, if I really cared (i.e., if there were any risk of invalid input),
we would not use the crufty old sscanf in the first place.



More information about the parted-devel mailing list