Page MenuHomeFreeBSD

D9915.id27614.diff
No OneTemporary

D9915.id27614.diff

Index: sbin/fsck_ffs/fsck.h
===================================================================
--- sbin/fsck_ffs/fsck.h
+++ sbin/fsck_ffs/fsck.h
@@ -282,7 +282,8 @@
u_int i_numblks; /* size of block array in bytes */
ufs2_daddr_t i_blks[1]; /* actually longer */
} **inphead, **inpsort;
-extern long numdirs, dirhash, listmax, inplast;
+extern long dirhash, inplast;
+extern unsigned long numdirs, listmax;
extern long countdirs; /* number of directories we actually found */
#define MIBSIZE 3 /* size of fsck sysctl MIBs */
Index: sbin/fsck_ffs/globs.c
===================================================================
--- sbin/fsck_ffs/globs.c
+++ sbin/fsck_ffs/globs.c
@@ -56,7 +56,8 @@
struct bufarea *pdirbp; /* current directory contents */
struct bufarea *pbp; /* current inode block */
ino_t cursnapshot;
-long numdirs, dirhash, listmax, inplast;
+long dirhash, inplast;
+unsigned long numdirs, listmax;
long countdirs; /* number of directories we actually found */
int adjrefcnt[MIBSIZE]; /* MIB command to adjust inode reference cnt */
int adjblkcnt[MIBSIZE]; /* MIB command to adjust inode block count */
@@ -123,7 +124,7 @@
pdirbp = NULL;
pbp = NULL;
cursnapshot = 0;
- numdirs = dirhash = listmax = inplast = 0;
+ numdirs = listmax = dirhash = inplast = 0;
countdirs = 0;
bzero(adjrefcnt, sizeof(int) * MIBSIZE);
bzero(adjblkcnt, sizeof(int) * MIBSIZE);
Index: sbin/fsck_ffs/inode.c
===================================================================
--- sbin/fsck_ffs/inode.c
+++ sbin/fsck_ffs/inode.c
@@ -472,8 +472,8 @@
inp->i_blks[UFS_NDADDR + i] = DIP(dp, di_ib[i]);
if (inplast == listmax) {
listmax += 100;
- inpsort = (struct inoinfo **)realloc((char *)inpsort,
- (unsigned)listmax * sizeof(struct inoinfo *));
+ inpsort = (struct inoinfo **)reallocarray((char *)inpsort,
+ listmax, sizeof(struct inoinfo *));
if (inpsort == NULL)
errx(EEXIT, "cannot increase directory list");
}
Index: sbin/fsck_ffs/setup.c
===================================================================
--- sbin/fsck_ffs/setup.c
+++ sbin/fsck_ffs/setup.c
@@ -268,8 +268,7 @@
(unsigned)bmapsize);
goto badsb;
}
- inostathead = Calloc((unsigned)(sblock.fs_ncg),
- sizeof(struct inostatlist));
+ inostathead = Calloc(sblock.fs_ncg, sizeof(struct inostatlist));
if (inostathead == NULL) {
printf("cannot alloc %u bytes for inostathead\n",
(unsigned)(sizeof(struct inostatlist) * (sblock.fs_ncg)));
@@ -279,10 +278,8 @@
dirhash = numdirs;
inplast = 0;
listmax = numdirs + 10;
- inpsort = (struct inoinfo **)Calloc((unsigned)listmax,
- sizeof(struct inoinfo *));
- inphead = (struct inoinfo **)Calloc((unsigned)numdirs,
- sizeof(struct inoinfo *));
+ inpsort = (struct inoinfo **)Calloc(listmax, sizeof(struct inoinfo *));
+ inphead = (struct inoinfo **)Calloc(numdirs, sizeof(struct inoinfo *));
if (inpsort == NULL || inphead == NULL) {
printf("cannot alloc %ju bytes for inphead\n",
(uintmax_t)numdirs * sizeof(struct inoinfo *));
Index: sbin/ipfw/ipfw2.c
===================================================================
--- sbin/ipfw/ipfw2.c
+++ sbin/ipfw/ipfw2.c
@@ -2903,7 +2903,7 @@
if (tstate->count + 1 > tstate->size) {
tstate->size += 4;
- tstate->idx = realloc(tstate->idx, tstate->size *
+ tstate->idx = reallocarray(tstate->idx, tstate->size,
sizeof(ipfw_obj_ntlv));
if (tstate->idx == NULL)
return (0);
Index: sbin/newfs_nandfs/newfs_nandfs.c
===================================================================
--- sbin/newfs_nandfs/newfs_nandfs.c
+++ sbin/newfs_nandfs/newfs_nandfs.c
@@ -1041,8 +1041,8 @@
printf("cannot delete segment %jx (offset %jd)\n",
i, offset);
bad_segments_count++;
- bad_segments = realloc(bad_segments,
- bad_segments_count * sizeof(uint32_t));
+ bad_segments = reallocarray(bad_segments,
+ bad_segments_count, sizeof(uint32_t));
bad_segments[bad_segments_count - 1] = i;
}
}
Index: usr.bin/c99/c99.c
===================================================================
--- usr.bin/c99/c99.c
+++ usr.bin/c99/c99.c
@@ -96,8 +96,8 @@
{
if (nargs + 1 >= cargs) {
cargs += 16;
- if ((args = realloc(args, sizeof(*args) * cargs)) == NULL)
- err(1, "malloc");
+ if ((args = reallocarray(args, cargs, sizeof(*args))) == NULL)
+ err(1, "realloc");
}
if ((args[nargs++] = strdup(item)) == NULL)
err(1, "strdup");
Index: usr.bin/col/col.c
===================================================================
--- usr.bin/col/col.c
+++ usr.bin/col/col.c
@@ -91,8 +91,8 @@
CHAR *l_line; /* characters on the line */
LINE *l_prev; /* previous line */
LINE *l_next; /* next line */
- int l_lsize; /* allocated sizeof l_line */
- int l_line_len; /* strlen(l_line) */
+ unsigned l_lsize; /* allocated sizeof l_line */
+ unsigned l_line_len; /* strlen(l_line) */
int l_needs_sort; /* set if chars went in out of order */
int l_max_col; /* max column in the line */
};
@@ -312,11 +312,11 @@
}
/* grow line's buffer? */
if (l->l_line_len + 1 >= l->l_lsize) {
- int need;
+ unsigned need;
need = l->l_lsize ? l->l_lsize * 2 : 90;
- if ((l->l_line = realloc(l->l_line,
- (unsigned)need * sizeof(CHAR))) == NULL)
+ if ((l->l_line = reallocarray(l->l_line, need,
+ sizeof(CHAR))) == NULL)
err(1, NULL);
l->l_lsize = need;
}
@@ -426,7 +426,8 @@
if (l->l_needs_sort) {
static CHAR *sorted;
- static int count_size, *count, sorted_size;
+ static int count_size, *count;
+ static unsigned sorted_size;
/*
* Do an O(n) sort on l->l_line by column being careful to
@@ -434,14 +435,14 @@
*/
if (l->l_lsize > sorted_size) {
sorted_size = l->l_lsize;
- if ((sorted = realloc(sorted,
- (unsigned)sizeof(CHAR) * sorted_size)) == NULL)
+ if ((sorted = reallocarray(sorted, sorted_size,
+ sizeof(CHAR))) == NULL)
err(1, NULL);
}
if (l->l_max_col >= count_size) {
count_size = l->l_max_col + 1;
- if ((count = realloc(count,
- (unsigned)sizeof(int) * count_size)) == NULL)
+ if ((count = reallocarray(count, count_size,
+ sizeof(int))) == NULL)
err(1, NULL);
}
memset(count, 0, sizeof(int) * l->l_max_col + 1);
@@ -552,7 +553,7 @@
int i;
if (!line_freelist) {
- if ((l = realloc(NULL, sizeof(LINE) * NALLOC)) == NULL)
+ if ((l = reallocarray(NULL, NALLOC, sizeof(LINE))) == NULL)
err(1, NULL);
line_freelist = l;
for (i = 1; i < NALLOC; i++, l++)
Index: usr.bin/column/column.c
===================================================================
--- usr.bin/column/column.c
+++ usr.bin/column/column.c
@@ -243,10 +243,10 @@
(cols[coloff] = wcstok(p, separator, &last));
p = NULL)
if (++coloff == maxcols) {
- if (!(cols = realloc(cols, ((u_int)maxcols +
- DEFCOLS) * sizeof(wchar_t *))) ||
- !(lens = realloc(lens,
- ((u_int)maxcols + DEFCOLS) * sizeof(int))))
+ if (!(cols = reallocarray(cols, (u_int)maxcols +
+ DEFCOLS, sizeof(wchar_t *))) ||
+ !(lens = reallocarray(lens,
+ (u_int)maxcols + DEFCOLS, sizeof(int))))
err(1, NULL);
memset((char *)lens + maxcols * sizeof(int),
0, DEFCOLS * sizeof(int));
@@ -300,8 +300,8 @@
maxlength = len;
if (entries == maxentry) {
maxentry += DEFNUM;
- if (!(list = realloc(list,
- (u_int)maxentry * sizeof(*list))))
+ if (!(list = reallocarray(list,
+ (u_int)maxentry, sizeof(*list))))
err(1, NULL);
}
list[entries] = malloc((wcslen(buf) + 1) * sizeof(wchar_t));
Index: usr.bin/join/join.c
===================================================================
--- usr.bin/join/join.c
+++ usr.bin/join/join.c
@@ -292,8 +292,8 @@
if (F->setcnt == F->setalloc) {
cnt = F->setalloc;
F->setalloc += 50;
- if ((F->set = realloc(F->set,
- F->setalloc * sizeof(LINE))) == NULL)
+ if ((F->set = reallocarray(F->set,
+ F->setalloc, sizeof(LINE))) == NULL)
err(1, NULL);
memset(F->set + cnt, 0, 50 * sizeof(LINE));
@@ -343,8 +343,8 @@
continue;
if (lp->fieldcnt == lp->fieldalloc) {
lp->fieldalloc += 50;
- if ((lp->fields = realloc(lp->fields,
- lp->fieldalloc * sizeof(char *))) == NULL)
+ if ((lp->fields = reallocarray(lp->fields,
+ lp->fieldalloc, sizeof(char *))) == NULL)
err(1, NULL);
}
lp->fields[lp->fieldcnt++] = fieldp;
@@ -559,8 +559,8 @@
errx(1, "malformed -o option field");
if (olistcnt == olistalloc) {
olistalloc += 50;
- if ((olist = realloc(olist,
- olistalloc * sizeof(OLIST))) == NULL)
+ if ((olist = reallocarray(olist,
+ olistalloc, sizeof(OLIST))) == NULL)
err(1, NULL);
}
olist[olistcnt].filenum = filenum;
Index: usr.bin/last/last.c
===================================================================
--- usr.bin/last/last.c
+++ usr.bin/last/last.c
@@ -230,7 +230,7 @@
/* Load the last entries from the file. */
while ((ut = getutxent()) != NULL) {
if (amount % 128 == 0) {
- buf = realloc(buf, (amount + 128) * sizeof *ut);
+ buf = reallocarray(buf, amount + 128, sizeof(*ut));
if (buf == NULL)
err(1, "realloc");
}
Index: usr.bin/locate/locate/util.c
===================================================================
--- usr.bin/locate/locate/util.c
+++ usr.bin/locate/locate/util.c
@@ -85,7 +85,8 @@
char **
colon(char **dbv, char *path, char *dot)
{
- int vlen, slen;
+ int slen;
+ u_int vlen;
char *c, *ch, *p;
char **pv;
@@ -120,8 +121,8 @@
*(p + slen) = '\0';
}
/* increase dbv with element p */
- if ((dbv = realloc(dbv, sizeof(char *) * (vlen + 2)))
- == NULL)
+ if ((dbv = reallocarray(dbv, vlen + 2,
+ sizeof(char *))) == NULL)
err(1, "realloc");
*(dbv + vlen) = p;
*(dbv + ++vlen) = NULL;
Index: usr.bin/mklocale/yacc.y
===================================================================
--- usr.bin/mklocale/yacc.y
+++ usr.bin/mklocale/yacc.y
@@ -295,8 +295,7 @@
static uint32_t *
xrelalloc(uint32_t *old, unsigned int sz)
{
- uint32_t *r = (uint32_t *)realloc((char *)old,
- sz * sizeof(uint32_t));
+ uint32_t *r = (uint32_t *)reallocarray((char *)old, sz, sizeof(uint32_t));
if (!r)
errx(1, "xrelalloc");
return(r);
Index: usr.bin/rs/rs.c
===================================================================
--- usr.bin/rs/rs.c
+++ usr.bin/rs/rs.c
@@ -80,7 +80,7 @@
static char **elem;
static char **endelem;
static char *curline;
-static int allocsize = BUFSIZ;
+static unsigned allocsize = BUFSIZ;
static int curlen;
static int irows, icols;
static int orows = 0, ocols = 0;
@@ -378,7 +378,7 @@
char **p;
allocsize += allocsize;
- p = (char **)realloc(elem, allocsize * sizeof(char *));
+ p = reallocarray(elem, allocsize, sizeof(char *));
if (p == NULL)
err(1, "no memory");
Index: usr.bin/ruptime/ruptime.c
===================================================================
--- usr.bin/ruptime/ruptime.c
+++ usr.bin/ruptime/ruptime.c
@@ -213,8 +213,8 @@
}
if (nhosts == hspace) {
- if ((hs =
- realloc(hs, (hspace += 40) * sizeof(*hs))) == NULL)
+ if ((hs = reallocarray(hs, hspace += 40,
+ sizeof(*hs))) == NULL)
err(1, NULL);
hsp = hs + nhosts;
}
Index: usr.sbin/mailwrapper/mailwrapper.c
===================================================================
--- usr.sbin/mailwrapper/mailwrapper.c
+++ usr.sbin/mailwrapper/mailwrapper.c
@@ -73,7 +73,7 @@
if (al->argc == al->maxc) {
al->maxc <<= 1;
- al->argv = realloc(al->argv, al->maxc * sizeof(char *));
+ al->argv = reallocarray(al->argv, al->maxc, sizeof(char *));
if (al->argv == NULL)
err(EX_TEMPFAIL, "realloc");
}
Index: usr.sbin/newsyslog/newsyslog.c
===================================================================
--- usr.sbin/newsyslog/newsyslog.c
+++ usr.sbin/newsyslog/newsyslog.c
@@ -1577,8 +1577,8 @@
/* Detect integer overflow */
if (max_logcnt < logcnt)
errx(1, "Too many old logfiles found");
- oldlogs = realloc(oldlogs,
- max_logcnt * sizeof(struct oldlog_entry));
+ oldlogs = reallocarray(oldlogs, max_logcnt,
+ sizeof(struct oldlog_entry));
if (oldlogs == NULL)
err(1, "realloc()");
}
@@ -1586,7 +1586,7 @@
/* Second, if needed we delete oldest archived logfiles */
if (logcnt > 0 && logcnt >= ent->numlogs && ent->numlogs > 1) {
- oldlogs = realloc(oldlogs, logcnt *
+ oldlogs = reallocarray(oldlogs, logcnt,
sizeof(struct oldlog_entry));
if (oldlogs == NULL)
err(1, "realloc()");
Index: usr.sbin/pmcstat/pmcpl_calltree.c
===================================================================
--- usr.sbin/pmcstat/pmcpl_calltree.c
+++ usr.sbin/pmcstat/pmcpl_calltree.c
@@ -185,7 +185,7 @@
static void
pmcpl_ct_samples_grow(struct pmcpl_ct_sample *samples)
{
- int npmcs;
+ unsigned int npmcs;
/* Enough storage. */
if (pmcstat_npmcs <= samples->npmcs)
@@ -193,7 +193,7 @@
npmcs = samples->npmcs +
max(pmcstat_npmcs - samples->npmcs, PMCPL_CT_GROWSIZE);
- samples->sb = realloc(samples->sb, npmcs * sizeof(unsigned));
+ samples->sb = reallocarray(samples->sb, npmcs, sizeof(unsigned));
if (samples->sb == NULL)
errx(EX_SOFTWARE, "ERROR: out of memory");
bzero((char *)samples->sb + samples->npmcs * sizeof(unsigned),
@@ -226,13 +226,13 @@
static void
pmcpl_ct_arc_grow(int cursize, int *maxsize, struct pmcpl_ct_arc **items)
{
- int nmaxsize;
+ unsigned int nmaxsize;
if (cursize < *maxsize)
return;
nmaxsize = *maxsize + max(cursize + 1 - *maxsize, PMCPL_CT_GROWSIZE);
- *items = realloc(*items, nmaxsize * sizeof(struct pmcpl_ct_arc));
+ *items = reallocarray(*items, nmaxsize, sizeof(struct pmcpl_ct_arc));
if (*items == NULL)
errx(EX_SOFTWARE, "ERROR: out of memory");
bzero((char *)*items + *maxsize * sizeof(struct pmcpl_ct_arc),
@@ -247,13 +247,13 @@
static void
pmcpl_ct_instr_grow(int cursize, int *maxsize, struct pmcpl_ct_instr **items)
{
- int nmaxsize;
+ unsigned int nmaxsize;
if (cursize < *maxsize)
return;
nmaxsize = *maxsize + max(cursize + 1 - *maxsize, PMCPL_CT_GROWSIZE);
- *items = realloc(*items, nmaxsize * sizeof(struct pmcpl_ct_instr));
+ *items = reallocarray(*items, nmaxsize, sizeof(struct pmcpl_ct_instr));
if (*items == NULL)
errx(EX_SOFTWARE, "ERROR: out of memory");
bzero((char *)*items + *maxsize * sizeof(struct pmcpl_ct_instr),
Index: usr.sbin/pmcstat/pmcstat_log.c
===================================================================
--- usr.sbin/pmcstat/pmcstat_log.c
+++ usr.sbin/pmcstat/pmcstat_log.c
@@ -535,8 +535,8 @@
* Allocate space for the new entries.
*/
firsttime = image->pi_symbols == NULL;
- symptr = realloc(image->pi_symbols,
- sizeof(*symptr) * (image->pi_symcount + nfuncsyms));
+ symptr = reallocarray(image->pi_symbols,
+ image->pi_symcount + nfuncsyms, sizeof(*symptr));
if (symptr == image->pi_symbols) /* realloc() failed. */
return;
image->pi_symbols = symptr;
@@ -587,8 +587,8 @@
* Return space to the system if there were duplicates.
*/
if (newsyms < nfuncsyms)
- image->pi_symbols = realloc(image->pi_symbols,
- sizeof(*symptr) * image->pi_symcount);
+ image->pi_symbols = reallocarray(image->pi_symbols,
+ image->pi_symcount, sizeof(*symptr));
/*
* Keep the list of symbols sorted.
Index: usr.sbin/portsnap/make_index/make_index.c
===================================================================
--- usr.sbin/portsnap/make_index/make_index.c
+++ usr.sbin/portsnap/make_index/make_index.c
@@ -288,7 +288,7 @@
N++;
if (N >= *nd) {
*nd += *nd;
- d = realloc(d, *nd * sizeof(DEP));
+ d = reallocarray(d, *nd, sizeof(DEP));
if (d == NULL)
err(1, "realloc(d)");
}
@@ -452,7 +452,8 @@
/* Enlarge array if needed */
if (i >= pplen) {
pplen *= 2;
- if ((pp = realloc(pp, pplen * sizeof(PORT *))) == NULL)
+ if ((pp = reallocarray(pp, pplen,
+ sizeof(PORT *))) == NULL)
err(1, "realloc(pp)");
}
Index: usr.sbin/ppp/iface.c
===================================================================
--- usr.sbin/ppp/iface.c
+++ usr.sbin/ppp/iface.c
@@ -173,8 +173,8 @@
)) {
/* Record the address */
- addr = (struct iface_addr *)
- realloc(iface->addr, (iface->addrs + 1) * sizeof iface->addr[0]);
+ addr = reallocarray(iface->addr, iface->addrs + 1,
+ sizeof iface->addr[0]);
if (addr == NULL)
break;
iface->addr = addr;
@@ -575,8 +575,7 @@
}
}
- addr = (struct iface_addr *)realloc
- (iface->addr, (iface->addrs + 1) * sizeof iface->addr[0]);
+ addr = reallocarray(iface->addr, (iface->addrs + 1), sizeof iface->addr[0]);
if (addr == NULL) {
log_Printf(LogERROR, "iface_inAdd: realloc: %s\n", strerror(errno));
close(s);
Index: usr.sbin/ppp/ncp.c
===================================================================
--- usr.sbin/ppp/ncp.c
+++ usr.sbin/ppp/ncp.c
@@ -387,8 +387,7 @@
if (range->nports == range->maxports) {
range->maxports += 10;
- newport = (u_short *)realloc(range->port,
- range->maxports * sizeof(u_short));
+ newport = reallocarray(range->port, range->maxports, sizeof(u_short));
if (newport == NULL) {
log_Printf(LogERROR, "ncp_AddUrgentPort: realloc: %s\n",
strerror(errno));
Index: usr.sbin/route6d/route6d.c
===================================================================
--- usr.sbin/route6d/route6d.c
+++ usr.sbin/route6d/route6d.c
@@ -3554,24 +3554,24 @@
if (!index2ifc) {
nindex2ifc = 5; /*initial guess*/
index2ifc = (struct ifc **)
- malloc(sizeof(*index2ifc) * nindex2ifc);
+ malloc(nindex2ifc * sizeof(*index2ifc));
if (index2ifc == NULL) {
fatal("malloc");
/*NOTREACHED*/
}
- memset(index2ifc, 0, sizeof(*index2ifc) * nindex2ifc);
+ memset(index2ifc, 0, nindex2ifc * sizeof(*index2ifc));
}
n = nindex2ifc;
for (nsize = nindex2ifc; nsize <= idx; nsize *= 2)
;
if (n != nsize) {
- p = (struct ifc **)realloc(index2ifc,
- sizeof(*index2ifc) * nsize);
+ p = (struct ifc **)reallocarray(index2ifc, nsize,
+ sizeof(*index2ifc));
if (p == NULL) {
fatal("realloc");
/*NOTREACHED*/
}
- memset(p + n, 0, sizeof(*index2ifc) * (nindex2ifc - n));
+ memset(p + n, 0, (nindex2ifc - n) * sizeof(*index2ifc));
index2ifc = p;
nindex2ifc = nsize;
}

File Metadata

Mime Type
text/plain
Expires
Sat, Jun 27, 11:24 AM (10 h, 46 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
34398445
Default Alt Text
D9915.id27614.diff (18 KB)

Event Timeline