From: Bruno Haible Date: Fri, 8 Mar 2019 19:38:22 +0000 (+0100) Subject: unistr/u8-cmp: Fix undefined behaviour. X-Git-Tag: v1.0~5052 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7e7501fa24bcd2e1484fee5648d88b8d94f0bf38;p=thirdparty%2Fgnulib.git unistr/u8-cmp: Fix undefined behaviour. Reported by Jeffrey Walton . * lib/unistr/u8-cmp.c (u8_cmp): Don't invoke memcmp if n is zero. --- diff --git a/ChangeLog b/ChangeLog index 2e6126105d..074b1caca4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2019-03-08 Bruno Haible + + unistr/u8-cmp: Fix undefined behaviour. + Reported by Jeffrey Walton . + * lib/unistr/u8-cmp.c (u8_cmp): Don't invoke memcmp if n is zero. + 2019-03-08 Bruno Haible unictype/numeric: Fix undefined behaviour. diff --git a/lib/unistr/u8-cmp.c b/lib/unistr/u8-cmp.c index bd2f11bea9..5349ec63d0 100644 --- a/lib/unistr/u8-cmp.c +++ b/lib/unistr/u8-cmp.c @@ -26,5 +26,5 @@ int u8_cmp (const uint8_t *s1, const uint8_t *s2, size_t n) { /* Use the fact that the UTF-8 encoding preserves lexicographic order. */ - return memcmp ((const char *) s1, (const char *) s2, n); + return n == 0 ? 0 : memcmp ((const char *) s1, (const char *) s2, n); }