[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] lib/vasnprintf.c: Add information to make integer comparison
From: |
Bruno Haible |
Subject: |
Re: [PATCH] lib/vasnprintf.c: Add information to make integer comparison logical |
Date: |
Sun, 23 Sep 2018 03:19:38 +0200 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-134-generic; KDE/5.18.0; x86_64; ; ) |
Bjarni Ingi Gislason wrote:
> A question (comment) from the compiler (gcc 8.2):
>
> ../lib/vasnprintf.c:5107:35: warning: comparison of integer expressions of
> different signedness: 'int' and 'size_t' {aka 'long unsigned int'}
> [-Wsign-compare]
> if (count < maxlen
> ^
Thanks for reporting this. I'm fine with silencing such warnings
through casts, if the casts don't introduce bugs.
> The value of "count" is tested to be non-negative, so a cast to
> "size_t" is valid.
count is known to be >= 0, yes. But 'size_t' may be smaller than 'int',
and in this case the cast introduces a bug. Such platforms are rare
nowadays (Windows 3.1 was such a platform), but if we want the code
to make as little assumptions as possible, a better patch is needed.
Bruno