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:
parent
7598a108ff
commit
a77cf1025c
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=249139
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user