summaryrefslogtreecommitdiffstats
path: root/usr.sbin/pmcstat/pmcpl_calltree.c
diff options
context:
space:
mode:
authorpfg <pfg@FreeBSD.org>2017-05-06 02:43:26 +0000
committerpfg <pfg@FreeBSD.org>2017-05-06 02:43:26 +0000
commitcab775df1a1541c50fce19e4c67bfde02af8b97d (patch)
treed7dff8f431e9fc58d52d9db809f77607d3090e0c /usr.sbin/pmcstat/pmcpl_calltree.c
parent5d76adac38d9c07945c337413ccb2d812df59b4a (diff)
downloadFreeBSD-src-cab775df1a1541c50fce19e4c67bfde02af8b97d.zip
FreeBSD-src-cab775df1a1541c50fce19e4c67bfde02af8b97d.tar.gz
MFC r317284:
pmcstat(8); unsign some allocation variables and use reallocarray(3). Use unsigned values in some internal variables that will be used during allocation. The variables are used in reduced scope and have no chance of becoming negative. Provide bounds checking through reallocarray(3).
Diffstat (limited to 'usr.sbin/pmcstat/pmcpl_calltree.c')
-rw-r--r--usr.sbin/pmcstat/pmcpl_calltree.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/usr.sbin/pmcstat/pmcpl_calltree.c b/usr.sbin/pmcstat/pmcpl_calltree.c
index edfe85a..0f95ac1 100644
--- a/usr.sbin/pmcstat/pmcpl_calltree.c
+++ b/usr.sbin/pmcstat/pmcpl_calltree.c
@@ -185,7 +185,7 @@ pmcpl_ct_samples_free(struct pmcpl_ct_sample *samples)
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 @@ pmcpl_ct_samples_grow(struct pmcpl_ct_sample *samples)
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 @@ pmcpl_ct_samples_root(struct pmcpl_ct_sample *samples)
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 @@ pmcpl_ct_arc_grow(int cursize, int *maxsize, struct pmcpl_ct_arc **items)
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),
OpenPOWER on IntegriCloud