Fixed size_t comparison in memxxx and strxxx finctions.

This commit is contained in:
Serge Vakulenko
2014-05-07 20:57:09 -07:00
parent 2395d5a9fa
commit bca48c9a66
8 changed files with 9 additions and 9 deletions

View File

@@ -18,7 +18,7 @@ memccpy(vt, vf, c, n)
register char *t = vt;
register const char *f = vf;
while (--n >= 0)
while (n-- > 0)
if ((*t++ = *f++) == c)
return (t);
return (0);

View File

@@ -16,7 +16,7 @@ memchr(vs, c, n)
{
register const char *s = vs;
while (--n >= 0)
while (n-- > 0)
if (*s++ == c)
return (void*) --s;
return (0);

View File

@@ -15,7 +15,7 @@ memcmp (vs1, vs2, n)
{
register const char *s1 = vs1, *s2 = vs2;
while (--n >= 0)
while (n-- > 0)
if (*s1++ != *s2++)
return (*--s1 - *--s2);
return (0);

View File

@@ -17,7 +17,7 @@ memcpy (vt, vf, n)
register char *t = vt;
register const char *f = vf;
while (--n >= 0)
while (n-- > 0)
*t++ = *f++;
return vt;

View File

@@ -16,7 +16,7 @@ memset (vs, c, n)
{
register char *s = vs;
while (--n >= 0)
while (n-- > 0)
*s++ = c;
return vs;

View File

@@ -64,8 +64,8 @@ strncasecmp(s1, s2, n)
{
register char *cm = charmap;
while (--n >= 0 && cm[(unsigned char)*s1] == cm[(unsigned char)*s2++])
while (n-- > 0 && cm[(unsigned char)*s1] == cm[(unsigned char)*s2++])
if (*s1++ == '\0')
return(0);
return(n < 0 ? 0 : cm[(unsigned char)*s1] - cm[(unsigned char)*--s2]);
return(n == 0 ? 0 : cm[(unsigned char)*s1] - cm[(unsigned char)*--s2]);
}

View File

@@ -18,7 +18,7 @@ strncat(s1, s2, n)
;
--s1;
while ((*s1++ = *s2++))
if (--n < 0) {
if (n-- == 0) {
*--s1 = '\0';
break;
}

View File

@@ -10,7 +10,7 @@ strncpy(s1, s2, n)
register const char *s2;
size_t n;
{
register int i;
size_t i;
register char *os1;
os1 = s1;