if (bup + 3 + MAXNAMLEN + 1 >= eup) {
char *nup;
- if ((nup = realloc(up, upsize *= 2)) == NULL)
+ if ((nup = reallocarray(up, upsize, 2)) == NULL)
goto err;
+ upsize *= 2;
up = nup;
bup = up;
eup = up + upsize;
}
off = bpt - pt;
len = ept - bpt;
- if ((npt = realloc(pt, ptsize *= 2)) == NULL)
+ if ((npt = reallocarray(pt, ptsize, 2)) == NULL)
goto err;
+ ptsize *= 2;
pt = npt;
bpt = pt + off;
ept = pt + ptsize;
len = strlen(buf);
if (!len || buf[len - 1] == '\n' || feof(fp))
break;
- bufsize *= 2;
- cp = realloc(buf, bufsize);
+ cp = reallocarray(buf, bufsize, 2);
if (cp == NULL)
return -1;
+ bufsize *= 2;
buf = cp;
}
*bufp = buf;
return GLOB_NOSPACE;
}
- pathv = realloc(pglob->gl_pathv, newn * sizeof(*pathv));
+ pathv = reallocarray(pglob->gl_pathv, newn, sizeof(*pathv));
if (pathv == NULL)
goto nospace;
if (pglob->gl_pathv == NULL && pglob->gl_offs > 0) {
errno = EOVERFLOW;
return -1;
}
- nenvp = realloc(env.envp, nsize * sizeof(char *));
+ nenvp = reallocarray(env.envp, nsize, sizeof(char *));
if (nenvp == NULL) {
errno = ENOMEM;
return -1;
if (count >= max_paths) {
struct path_list **tmp;
max_paths <<= 1;
- tmp = realloc(paths, sizeof(*paths) * max_paths);
+ tmp = reallocarray(paths, max_paths, sizeof(*paths));
if (tmp == NULL) {
sudo_efree(path);
sudo_efree(pl);
debug_return_bool(false);
}
istacksize += SUDOERS_STACK_INCREMENT;
- new_istack = (struct include_stack *) realloc(istack,
- sizeof(*istack) * istacksize);
+ new_istack = reallocarray(istack, istacksize, sizeof(*istack));
if (new_istack == NULL) {
sudo_warn(NULL);
sudoerserror(NULL);
if (count >= max_paths) {
struct path_list **tmp;
max_paths <<= 1;
- tmp = realloc(paths, sizeof(*paths) * max_paths);
+ tmp = reallocarray(paths, max_paths, sizeof(*paths));
if (tmp == NULL) {
sudo_efree(path);
sudo_efree(pl);
debug_return_bool(false);
}
istacksize += SUDOERS_STACK_INCREMENT;
- new_istack = (struct include_stack *) realloc(istack,
- sizeof(*istack) * istacksize);
+ new_istack = reallocarray(istack, istacksize, sizeof(*istack));
if (new_istack == NULL) {
sudo_warn(NULL);
sudoerserror(NULL);