Re: [PATCH] Add cast to unsigned char to strverscmp
Joel Sherrill <[email protected]>
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <CAF9ehCWLCgunfKxMa9bW+r4DXdy-BMWZv7e9zBBHfdTqQezocQ@mail.gmail.com> |
On Thu, Nov 7, 2024 at 1:06 PM <[email protected]> wrote: > On 2024-11-07 09:53, Jeremy Bettis wrote: > > GCC 14.2 with -Werror=sign-compare fails on this code. > > > > Signed-off-by: Jeremy Bettis <[email protected] <mailto: > [email protected]>> > > --- > > newlib/libc/string/strverscmp.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/newlib/libc/string/strverscmp.c > b/newlib/libc/string/strverscmp.c > > index 55966335f..e86718faa 100644 > > --- a/newlib/libc/string/strverscmp.c > > +++ b/newlib/libc/string/strverscmp.c > > @@ -76,7 +76,7 @@ int strverscmp(const char *l0, const char *r0) > > else if (c!='0') z=0; > > } > > > > - if (l[dp]<'1' + 9U && r[dp]<'1' + 9U) { > > I'd call that a false positive? > Is this a side-effect of the signedness of char being unspecified and varying by architecture? I'd lean to trying to taking the U off the 9. > > + if ((unsigned char)(l[dp]-'1')<9U && (unsigned char)(r[dp]-'1')<9U) { > > What happens when chars are '\0' or '\x80'? > > > /* If we're looking at non-degenerate digit sequences starting > > * with nonzero digits, longest digit string is greater. */ > > for (j=i; isdigit(l[j]); j++) > --joel > > -- > Take care. Thanks, Brian Inglis Calgary, Alberta, Canada > > La perfection est atteinte Perfection is achieved > non pas lorsqu'il n'y a plus rien à ajouter not when there is no more to > add > mais lorsqu'il n'y a plus rien à retirer but when there is no more to > cut > -- Antoine de Saint-Exupéry >