[SLOF] [PATCH slof 02/13] libc: Compile with -Wextra
Thomas Huth
thuth at redhat.com
Thu Jan 28 15:49:44 AEDT 2021
On 28/01/2021 04.29, Alexey Kardashevskiy wrote:
>
>
> On 27/01/2021 23:58, Thomas Huth wrote:
>> On 27/01/2021 09.57, Alexey Kardashevskiy wrote:
>>> -Wextra enables a bunch of rather useful checks which this fixes.
>>>
>>> Signed-off-by: Alexey Kardashevskiy <aik at ozlabs.ru>
>>> ---
>>> lib/libc/stdio/vsnprintf.c | 15 ++++++++-------
>>> lib/libc/string/memmove.c | 2 +-
>>> 2 files changed, 9 insertions(+), 8 deletions(-)
>>>
>>> diff --git a/lib/libc/stdio/vsnprintf.c b/lib/libc/stdio/vsnprintf.c
>>> index 21dd04dfe46f..1a44301f74da 100644
>>> --- a/lib/libc/stdio/vsnprintf.c
>>> +++ b/lib/libc/stdio/vsnprintf.c
>>> @@ -25,15 +25,15 @@ static int
>>> print_str_fill(char **buffer, size_t bufsize, char *sizec,
>>> const char *str, char c)
>>> {
>>> - int i, sizei, len;
>>> + unsigned i, sizei, len;
>>> char *bstart = *buffer;
>>> sizei = strtoul(sizec, NULL, 10);
>>> len = strlen(str);
>>> if (sizei > len) {
>>> for (i = 0;
>>> - (i < (sizei - len)) && ((*buffer - bstart) < bufsize);
>>> - i++) {
>>> + (i < (sizei - len)) && ((*buffer - bstart) < (int)bufsize);
>>
>> bufsize is of type size_t, so the correct way to cast would be "(ssize_t)"
>> instead of "(int)", I think.
>> Maybe it would also be worth the effort to introduce a new local variable
>> a la:
>>
>> ssize_t sbufsize = (ssize_t)bufsize;
>>
>> so that you don't have to do the cast again and again all over the place?
>
>
> This is done once per a function, does not seem worth the variable, unless I
> missed something? Thanks,
Oh, well, sorry, I misread the patch, thought that the hunks related to the
same functions. So never mind!
Thomas
More information about the SLOF
mailing list