Replace a dozen lines of code with a call to strnlen() / wcsnlen().
This commit is contained in:
parent
9c5cb6d8ae
commit
353ce11c8b
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=189138
@ -822,22 +822,7 @@ reswitch: switch (ch) {
|
||||
}
|
||||
} else if ((cp = GETARG(char *)) == NULL)
|
||||
cp = "(null)";
|
||||
if (prec >= 0) {
|
||||
/*
|
||||
* can't use strlen; can only look for the
|
||||
* NUL in the first `prec' characters, and
|
||||
* strlen() will go further.
|
||||
*/
|
||||
char *p = memchr(cp, 0, (size_t)prec);
|
||||
|
||||
if (p != NULL) {
|
||||
size = p - cp;
|
||||
if (size > prec)
|
||||
size = prec;
|
||||
} else
|
||||
size = prec;
|
||||
} else
|
||||
size = strlen(cp);
|
||||
size = (prec >= 0) ? strnlen(cp, prec) : strlen(cp);
|
||||
sign = '\0';
|
||||
break;
|
||||
case 'U':
|
||||
|
@ -890,23 +890,7 @@ reswitch: switch (ch) {
|
||||
cp = convbuf;
|
||||
}
|
||||
}
|
||||
|
||||
if (prec >= 0) {
|
||||
/*
|
||||
* can't use wcslen; can only look for the
|
||||
* NUL in the first `prec' characters, and
|
||||
* wcslen() will go further.
|
||||
*/
|
||||
wchar_t *p = wmemchr(cp, 0, (size_t)prec);
|
||||
|
||||
if (p != NULL) {
|
||||
size = p - cp;
|
||||
if (size > prec)
|
||||
size = prec;
|
||||
} else
|
||||
size = prec;
|
||||
} else
|
||||
size = wcslen(cp);
|
||||
size = (prec >= 0) ? wcsnlen(cp, prec) : wcslen(cp);
|
||||
sign = '\0';
|
||||
break;
|
||||
case 'U':
|
||||
|
Loading…
Reference in New Issue
Block a user