summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/ungetc.c
diff options
context:
space:
mode:
authorpfg <pfg@FreeBSD.org>2017-04-07 16:08:04 +0000
committerpfg <pfg@FreeBSD.org>2017-04-07 16:08:04 +0000
commitfeaeb09c7553a3cb3242f6be7b39a5f4b4d5a3e7 (patch)
tree9779b1eeb4a9a1f1c6fccb20ee1fb04a426efb9d /lib/libc/stdio/ungetc.c
parent7317fc9c0522c902a4a0a67b17c5c5d25d04bff9 (diff)
downloadFreeBSD-src-feaeb09c7553a3cb3242f6be7b39a5f4b4d5a3e7.zip
FreeBSD-src-feaeb09c7553a3cb3242f6be7b39a5f4b4d5a3e7.tar.gz
MFC r315162:
libc: provide some bounds-checking through reallocarray(3). reallocarray(3) is a non portable extension that originated in OpenBSD. Given that it is already in FreeBSD's libc it is useful for the cases where reallocation involves a multiplication.
Diffstat (limited to 'lib/libc/stdio/ungetc.c')
-rw-r--r--lib/libc/stdio/ungetc.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/libc/stdio/ungetc.c b/lib/libc/stdio/ungetc.c
index 1695af7..88c9da5 100644
--- a/lib/libc/stdio/ungetc.c
+++ b/lib/libc/stdio/ungetc.c
@@ -73,14 +73,14 @@ __submore(FILE *fp)
return (0);
}
i = fp->_ub._size;
- p = realloc(fp->_ub._base, (size_t)(i << 1));
+ p = reallocarray(fp->_ub._base, i, 2);
if (p == NULL)
return (EOF);
/* no overlap (hence can use memcpy) because we doubled the size */
(void)memcpy((void *)(p + i), (void *)p, (size_t)i);
fp->_p = p + i;
fp->_ub._base = p;
- fp->_ub._size = i << 1;
+ fp->_ub._size = i * 2;
return (0);
}
OpenPOWER on IntegriCloud