svn commit: r249139 - head/sys/boot/common
Andriy Gapon
avg at FreeBSD.org
Fri Apr 5 09:14:31 UTC 2013
Author: avg
Date: Fri Apr 5 09:14:30 2013
New Revision: 249139
URL: http://svnweb.freebsd.org/changeset/base/249139
Log:
strncmp for boot code: fix an off by one error
Before this change strncmp would access and _compare_ n+1 characters
in the case where the first n characters match.
MFC after: 5 days
Modified:
head/sys/boot/common/util.c
Modified: head/sys/boot/common/util.c
==============================================================================
--- head/sys/boot/common/util.c Fri Apr 5 09:06:59 2013 (r249138)
+++ head/sys/boot/common/util.c Fri Apr 5 09:14:30 2013 (r249139)
@@ -68,9 +68,9 @@ int
strncmp(const char *s1, const char *s2, size_t len)
{
- for (; *s1 == *s2 && *s1 != '\0' && len > 0; len--, s1++, s2++)
+ for (; len > 0 && *s1 == *s2 && *s1 != '\0'; len--, s1++, s2++)
;
- return ((unsigned char)*s1 - (unsigned char)*s2);
+ return (len == 0 ? 0 : (unsigned char)*s1 - (unsigned char)*s2);
}
void
More information about the svn-src-all
mailing list