else
fb->len = FILEWBUF_INIT_LEN;
- wp = realloc(fb->wbuf, fb->len * sizeof(wchar_t));
+ wp = reallocarray(fb->wbuf, fb->len, sizeof(wchar_t));
if (wp == NULL) {
wused = 0;
break;
if (n < THRESHOLD)
simplesort(a, n, 0, tr, endch);
else {
- if ((ta = malloc(n * sizeof(a))) == NULL)
+ ta = reallocarray(NULL, n, sizeof(a));
+ if (ta == NULL)
return (-1);
r_sort_b(a, ta, n, 0, tr, endch);
free(ta);
if (set >= endset) { \
BITCMD *newset; \
setlen += SET_LEN_INCR; \
- newset = realloc(saveset, sizeof(BITCMD) * setlen); \
+ newset = reallocarray(saveset, setlen, sizeof(BITCMD)); \
if (newset == NULL) \
goto out; \
set = newset + (set - saveset); \
setlen = SET_LEN + 2;
- if ((set = malloc((u_int)(sizeof(BITCMD) * setlen))) == NULL)
+ set = reallocarray(NULL, setlen, sizeof(BITCMD));
+ if (set == NULL)
return (NULL);
saveset = set;
endset = set + (setlen - 2);
sl->sl_cur = 0;
sl->sl_max = _SL_CHUNKSIZE;
- sl->sl_str = malloc(sl->sl_max * sizeof(char *));
+ sl->sl_str = reallocarray(NULL, sl->sl_max, sizeof(char *));
if (sl->sl_str == NULL) {
free(sl);
sl = NULL;
if (sl->sl_cur == sl->sl_max - 1) {
char **new;
- new = realloc(sl->sl_str,
- (sl->sl_max + _SL_CHUNKSIZE) * sizeof(char *));
+ new = reallocarray(sl->sl_str,
+ (sl->sl_max + _SL_CHUNKSIZE), sizeof(char *));
if (new == NULL)
return -1;
sl->sl_max += _SL_CHUNKSIZE;
str = strdup("A\n");
str[0] += i;
- files[i].lines = malloc(sizeof(char *) * LINE_COUNT);
+ files[i].lines = reallocarray(NULL, LINE_COUNT, sizeof(char *));
files[i].lines[0] = str;
files[i].lines[1] = str;
files[i].fp = pipe_feed("%s", files[i].lines, LINE_COUNT);
wstr = wcsdup(L"A\n");
wstr[0] += i;
- files[i].lines = malloc(sizeof(char *) * LINE_COUNT);
+ files[i].lines = reallocarray(NULL, LINE_COUNT, sizeof(char *));
files[i].lines[0] = wstr;
files[i].lines[1] = wstr;
files[i].fp = pipe_feed("%ls", files[i].lines, LINE_COUNT);