[PATCH] H8/300: Fix strcmp() behaviour in some rare corner cases.

Jeff Johnston jjohnstn@redhat.com
Mon Nov 3 20:11:41 GMT 2025


Patch pushed.  Thanks.

-- Jeff J.

On Sat, Nov 1, 2025 at 9:56 AM Jan Dubiec <jdx@o2.pl> 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  <jdx@o2.pl>
>
> newlib/ChangeLog:
>
>         * libc/machine/h8300/strcmp.S (_strcmp): First extend 8 bit
>         character codes to 16 bit integers and then compare them.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/newlib/attachments/20251103/b403563a/attachment.htm>


More information about the Newlib mailing list