Mercurial > gnulib
changeset 40211:5f58d2ac35ea
unistr/u8-cmp: Fix undefined behaviour.
Reported by Jeffrey Walton <noloader@gmail.com>.
* lib/unistr/u8-cmp.c (u8_cmp): Don't invoke memcmp if n is zero.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Fri, 08 Mar 2019 20:38:22 +0100 |
parents | 44073ad4207f |
children | 8da9577294da |
files | ChangeLog lib/unistr/u8-cmp.c |
diffstat | 2 files changed, 7 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Fri Mar 08 19:17:37 2019 +0100 +++ b/ChangeLog Fri Mar 08 20:38:22 2019 +0100 @@ -1,3 +1,9 @@ +2019-03-08 Bruno Haible <bruno@clisp.org> + + unistr/u8-cmp: Fix undefined behaviour. + Reported by Jeffrey Walton <noloader@gmail.com>. + * lib/unistr/u8-cmp.c (u8_cmp): Don't invoke memcmp if n is zero. + 2019-03-08 Bruno Haible <bruno@clisp.org> unictype/numeric: Fix undefined behaviour.
--- a/lib/unistr/u8-cmp.c Fri Mar 08 19:17:37 2019 +0100 +++ b/lib/unistr/u8-cmp.c Fri Mar 08 20:38:22 2019 +0100 @@ -26,5 +26,5 @@ 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); }