aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/mbstring/u8cmp.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/mbstring/u8cmp.c b/lib/mbstring/u8cmp.c
index 0059020..e54f984 100644
--- a/lib/mbstring/u8cmp.c
+++ b/lib/mbstring/u8cmp.c
@@ -2,8 +2,13 @@
#include "mbstring.h"
+/* Technically you can’t pass nullptr to memcmp(), so we check for x.len and
+ y.len both being 0 */
+
int
u8cmp(struct u8view x, struct u8view y)
{
- return x.len != y.len ? (x.len > y.len ? +1 : -1) : memcmp(x.p, y.p, x.len);
+ if (x.len != y.len)
+ return x.len > y.len ? +1 : -1;
+ return x.len == 0 && y.len == 0 ? 0 : memcmp(x.p, y.p, x.len);
}