Re: [PATCH] H8/300: Fix strcmp() behaviour in some rare corner cases.
Jeff Johnston <[email protected]>
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <CAOox84vR5ayJVErNmX-SQ4Y55=QoaaLDoWmfykMMBmQuSB17Eg@mail.gmail.com> |
Patch pushed. Thanks. -- Jeff J. On Sat, Nov 1, 2025 at 9:56 AM Jan Dubiec <[email protected]> wrote: > H8 port uses "optimized" version of strcmp() written in assembly > language. Unfortunately, the function fails in a few corner cases > mentioned at the end of newlib/testsuite/newlib.string/strcmp-1.c, i.e. > when the result of comparison exceeds the range of 8 bit signed integer > (aka "char"). The existing code first compares two 8 bit character codes > and then extends the result to 16 integer (or 32 bit in case of > -mint32). If the result of comparison is <= -128 or >= 127 the extension > gives wrong result, i.e. not what a human would expect. This patch fixes > the problem – first it extends 8 bit character codes to 16 bit integers > and then performs comparison. > > 2025-11-01 Jan Dubiec <[email protected]> > > newlib/ChangeLog: > > * libc/machine/h8300/strcmp.S (_strcmp): First extend 8 bit > character codes to 16 bit integers and then compare them.