>From 7e7501fa24bcd2e1484fee5648d88b8d94f0bf38 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 8 Mar 2019 20:38:22 +0100 Subject: [PATCH 2/4] 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. --- ChangeLog | 6 ++++++ lib/unistr/u8-cmp.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 2e61261..074b1ca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 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. Reported by Jeffrey Walton . * lib/unictype/numeric.c (uc_numeric_value): Avoid undefined behaviour diff --git a/lib/unistr/u8-cmp.c b/lib/unistr/u8-cmp.c index bd2f11b..5349ec6 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); } -- 2.7.4