1
0
mirror of https://git.FreeBSD.org/src.git synced 2025-01-20 15:43:16 +00:00

fix unsigned overflow

PR: 8437
This commit is contained in:
Andrey A. Chernov 1998-10-25 05:06:42 +00:00
parent 23a78098db
commit a4beee718b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=40635

View File

@ -127,22 +127,24 @@ wcstombs(s, pwcs, n)
size_t n;
{
char *e;
int cnt = 0;
int cnt, nb;
if (!pwcs || !s)
if (!pwcs || !s || n > INT_MAX)
return (-1);
while (n > 0) {
nb = n;
cnt = 0;
while (nb > 0) {
if (*pwcs == 0) {
*s = 0;
break;
}
if (!sputrune(*pwcs++, s, n, &e))
if (!sputrune(*pwcs++, s, nb, &e))
return (-1); /* encoding error */
if (!e) /* too long */
return (cnt);
cnt += e - s;
n -= e - s;
nb -= e - s;
s = e;
}
return (cnt);