svn commit: r252876 - stable/8/sys/boot/common

Andriy Gapon avg at FreeBSD.org
Sat Jul 6 08:59:27 UTC 2013


Author: avg
Date: Sat Jul  6 08:59:27 2013
New Revision: 252876
URL: http://svnweb.freebsd.org/changeset/base/252876

Log:
  MFC r249139: strncmp for boot code: fix an off by one error

Modified:
  stable/8/sys/boot/common/util.c
Directory Properties:
  stable/8/sys/   (props changed)
  stable/8/sys/boot/   (props changed)

Modified: stable/8/sys/boot/common/util.c
==============================================================================
--- stable/8/sys/boot/common/util.c	Sat Jul  6 08:58:30 2013	(r252875)
+++ stable/8/sys/boot/common/util.c	Sat Jul  6 08:59:27 2013	(r252876)
@@ -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-stable-8 mailing list