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
This commit is contained in:
Andriy Gapon 2013-04-05 09:14:30 +00:00
parent 7598a108ff
commit a77cf1025c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=249139

View File

@ -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