From 2d2e8f93303fc7b19ab19020013145144be90fa3 Mon Sep 17 00:00:00 2001 From: Richard Braun Date: Wed, 28 Jun 2017 01:02:34 +0200 Subject: kern/string: make strncmp handling of size 0 more intuitive --- kern/string.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'kern/string.c') diff --git a/kern/string.c b/kern/string.c index 7508e790..6c404783 100644 --- a/kern/string.c +++ b/kern/string.c @@ -21,6 +21,7 @@ #include #include +#include #include #ifndef STRING_ARCH_MEMCPY @@ -189,8 +190,9 @@ strncmp(const char *s1, const char *s2, size_t n) { char c1, c2; - c1 = '\0'; - c2 = '\0'; + if (unlikely(n == 0)) { + return 0; + } while ((n != 0) && (c1 = *s1) == (c2 = *s2)) { if (c1 == '\0') { -- cgit v1.2.3