aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/xlint/lint1
diff options
context:
space:
mode:
authorDavid E. O'Brien <obrien@FreeBSD.org>2001-07-24 14:02:07 +0000
committerDavid E. O'Brien <obrien@FreeBSD.org>2001-07-24 14:02:07 +0000
commit3c5bf66cec6a7cfbb0ea06d38579337936e211b5 (patch)
tree1b10f19bc78c4d5f1bf3ae393629c8d392370b91 /usr.bin/xlint/lint1
parent0e9ea6e71e0e06787b134b1605d27344726c3ea6 (diff)
downloadsrc-3c5bf66cec6a7cfbb0ea06d38579337936e211b5.tar.gz
src-3c5bf66cec6a7cfbb0ea06d38579337936e211b5.zip
Expand x{malloc,calloc,realloc,strdup} in-place.
(even found some unchecked naked uses)
Notes
Notes: svn path=/head/; revision=80284
Diffstat (limited to 'usr.bin/xlint/lint1')
-rw-r--r--usr.bin/xlint/lint1/cgram.y6
-rw-r--r--usr.bin/xlint/lint1/decl.c9
-rw-r--r--usr.bin/xlint/lint1/func.c12
-rw-r--r--usr.bin/xlint/lint1/mem1.c16
-rw-r--r--usr.bin/xlint/lint1/scan.l38
-rw-r--r--usr.bin/xlint/lint1/tree.c26
6 files changed, 72 insertions, 35 deletions
diff --git a/usr.bin/xlint/lint1/cgram.y b/usr.bin/xlint/lint1/cgram.y
index 119a782badd3..fea9b0cec67a 100644
--- a/usr.bin/xlint/lint1/cgram.y
+++ b/usr.bin/xlint/lint1/cgram.y
@@ -920,7 +920,8 @@ pointer:
asterisk:
T_MULT {
- $$ = xcalloc(1, sizeof (pqinf_t));
+ if (($$ = calloc(1, sizeof (pqinf_t))) == NULL)
+ nomem();
$$->p_pcnt = 1;
}
;
@@ -936,7 +937,8 @@ type_qualifier_list:
type_qualifier:
T_QUAL {
- $$ = xcalloc(1, sizeof (pqinf_t));
+ if (($$ = calloc(1, sizeof (pqinf_t))) == NULL)
+ nomem();
if ($1 == CONST) {
$$->p_const = 1;
} else {
diff --git a/usr.bin/xlint/lint1/decl.c b/usr.bin/xlint/lint1/decl.c
index 639c12372a3a..143840b1707b 100644
--- a/usr.bin/xlint/lint1/decl.c
+++ b/usr.bin/xlint/lint1/decl.c
@@ -163,7 +163,8 @@ initdecl()
};
/* declaration stack */
- dcs = xcalloc(1, sizeof (dinfo_t));
+ if ((dcs = calloc(1, sizeof (dinfo_t))) == NULL)
+ nomem();
dcs->d_ctx = EXTERN;
dcs->d_ldlsym = &dcs->d_dlsyms;
@@ -176,7 +177,8 @@ initdecl()
}
/* shared type structures */
- typetab = xcalloc(NTSPEC, sizeof (type_t));
+ if ((typetab = calloc(NTSPEC, sizeof (type_t))) == NULL)
+ nomem();
for (i = 0; i < NTSPEC; i++)
typetab[i].t_tspec = NOTSPEC;
typetab[CHAR].t_tspec = CHAR;
@@ -557,7 +559,8 @@ pushdecl(sc)
(void)printf("pushdecl(%d)\n", (int)sc);
/* put a new element on the declaration stack */
- di = xcalloc(1, sizeof (dinfo_t));
+ if ((di = calloc(1, sizeof (dinfo_t))) == NULL)
+ nomem();
di->d_nxt = dcs;
dcs = di;
di->d_ctx = sc;
diff --git a/usr.bin/xlint/lint1/func.c b/usr.bin/xlint/lint1/func.c
index f4d0223840c2..3421e9b35c0e 100644
--- a/usr.bin/xlint/lint1/func.c
+++ b/usr.bin/xlint/lint1/func.c
@@ -144,7 +144,8 @@ pushctrl(env)
{
cstk_t *ci;
- ci = xcalloc(1, sizeof (cstk_t));
+ if ((ci = calloc(1, sizeof (cstk_t))) == NULL)
+ nomem();
ci->c_env = env;
ci->c_nxt = cstk;
cstk = ci;
@@ -463,7 +464,8 @@ label(typ, sym, tn)
* to the type of the switch expression
*/
v = constant(tn);
- nv = xcalloc(1, sizeof (val_t));
+ if ((nv = calloc(1, sizeof (val_t))) == NULL)
+ nomem();
cvtcon(CASE, 0, ci->c_swtype, nv, v);
free(v);
@@ -483,7 +485,8 @@ label(typ, sym, tn)
* append the value to the list of
* case values
*/
- cl = xcalloc(1, sizeof (clst_t));
+ if ((cl = calloc(1, sizeof (clst_t))) == NULL)
+ nomem();
STRUCT_ASSIGN(cl->cl_val, *nv);
cl->cl_nxt = ci->c_clst;
ci->c_clst = cl;
@@ -591,7 +594,8 @@ switch1(tn)
* duplicated. This is not too complicated because it is
* only an integer type.
*/
- tp = xcalloc(1, sizeof (type_t));
+ if ((tp = calloc(1, sizeof (type_t))) == NULL)
+ nomem();
if (tn != NULL) {
tp->t_tspec = tn->tn_type->t_tspec;
if ((tp->t_isenum = tn->tn_type->t_isenum) != 0)
diff --git a/usr.bin/xlint/lint1/mem1.c b/usr.bin/xlint/lint1/mem1.c
index 239d243ad7be..639e596f5603 100644
--- a/usr.bin/xlint/lint1/mem1.c
+++ b/usr.bin/xlint/lint1/mem1.c
@@ -100,9 +100,11 @@ fnnalloc(s, len)
return (NULL);
if ((fn = srchfn(s, len)) == NULL) {
- fn = xmalloc(sizeof (fn_t));
+ if ((fn = malloc(sizeof (fn_t))) == NULL)
+ nomem();
/* Do not used strdup() because string is not NUL-terminated.*/
- fn->fn_name = xmalloc(len + 1);
+ if ((fn->fn_name = malloc(len + 1)) == NULL)
+ nomem();
(void)memcpy(fn->fn_name, s, len);
fn->fn_name[len] = '\0';
fn->fn_len = len;
@@ -174,7 +176,8 @@ xnewblk()
mbl_t *mb;
int prot, flags;
- mb = xmalloc(sizeof (mbl_t));
+ if ((mb = malloc(sizeof (mbl_t))) == NULL)
+ nomem();
/* use mmap instead of malloc to avoid malloc's size overhead */
@@ -252,7 +255,8 @@ initmem()
pgsz = getpagesize();
mblklen = ((MBLKSIZ + pgsz - 1) / pgsz) * pgsz;
- mblks = xcalloc(nmblks = ML_INC, sizeof (mbl_t *));
+ if ((mblks = calloc(nmblks = ML_INC, sizeof (mbl_t *))) == NULL)
+ nomem();
}
@@ -265,7 +269,9 @@ getlblk(l, s)
size_t s;
{
while (l >= nmblks) {
- mblks = xrealloc(mblks, (nmblks + ML_INC) * sizeof (mbl_t *));
+ if ((mblks = realloc(mblks, (nmblks + ML_INC) *
+ sizeof (mbl_t *))) == NULL)
+ nomem();
(void)memset(&mblks[nmblks], 0, ML_INC * sizeof (mbl_t *));
nmblks += ML_INC;
}
diff --git a/usr.bin/xlint/lint1/scan.l b/usr.bin/xlint/lint1/scan.l
index 2de98d5a9ea7..5e06aad07c69 100644
--- a/usr.bin/xlint/lint1/scan.l
+++ b/usr.bin/xlint/lint1/scan.l
@@ -306,7 +306,8 @@ allocsb()
if ((sb = sbfrlst) != NULL) {
sbfrlst = sb->sb_nxt;
} else {
- sb = xmalloc(sizeof (sbuf_t));
+ if ((sb = malloc(sizeof (sbuf_t))) == NULL)
+ nomem();
}
(void)memset(sb, 0, sizeof (sb));
return (sb);
@@ -565,7 +566,9 @@ icon(base)
uq = (u_quad_t)xsign((quad_t)uq, typ, -1);
- (yylval.y_val = xcalloc(1, sizeof (val_t)))->v_tspec = typ;
+ if ((yylval.y_val = calloc(1, sizeof(val_t))) == NULL)
+ nomem();
+ yylval.y_val->v_tspec = typ;
yylval.y_val->v_ansiu = ansiu;
yylval.y_val->v_quad = (quad_t)uq;
@@ -672,7 +675,9 @@ fcon()
}
}
- (yylval.y_val = xcalloc(1, sizeof (val_t)))->v_tspec = typ;
+ if ((yylval.y_val = calloc(1, sizeof (val_t))) == NULL)
+ nomem();
+ yylval.y_val->v_tspec = typ;
if (typ == FLOAT) {
yylval.y_val->v_ldbl = f;
} else {
@@ -726,7 +731,8 @@ ccon()
val = cv;
}
- yylval.y_val = xcalloc(1, sizeof (val_t));
+ if ((yylval.y_val = calloc(1, sizeof (val_t))) == NULL)
+ nomem();
yylval.y_val->v_tspec = INT;
yylval.y_val->v_quad = val;
@@ -772,7 +778,8 @@ wccon()
}
}
- yylval.y_val = xcalloc(1, sizeof (val_t));
+ if ((yylval.y_val = calloc(1, sizeof (val_t))) == NULL)
+ nomem();
yylval.y_val->v_tspec = WCHAR;
yylval.y_val->v_quad = wc;
@@ -1125,13 +1132,15 @@ string()
size_t len, max;
strg_t *strg;
- s = xmalloc(max = 64);
+ if ((s = malloc(max = 64)) == NULL)
+ nomem();
len = 0;
while ((c = getescc('"')) >= 0) {
/* +1 to reserve space for a trailing NUL character */
if (len + 1 == max)
- s = xrealloc(s, max *= 2);
+ if ((s = realloc(s, max *= 2)) == NULL)
+ nomem();
s[len++] = (char)c;
}
s[len] = '\0';
@@ -1139,7 +1148,8 @@ string()
/* unterminated string constant */
error(258);
- strg = xcalloc(1, sizeof (strg_t));
+ if ((strg = calloc(1, sizeof (strg_t))) == NULL)
+ nomem();
strg->st_tspec = CHAR;
strg->st_len = len;
strg->st_cp = s;
@@ -1157,12 +1167,14 @@ wcstrg()
wchar_t *ws;
strg_t *strg;
- s = xmalloc(max = 64);
+ if ((s = malloc(max = 64)) == NULL)
+ nomem();
len = 0;
while ((c = getescc('"')) >= 0) {
/* +1 to save space for a trailing NUL character */
if (len + 1 >= max)
- s = xrealloc(s, max *= 2);
+ if ((s = realloc(s, max *= 2)) == NULL)
+ nomem();
s[len++] = (char)c;
}
s[len] = '\0';
@@ -1182,7 +1194,8 @@ wcstrg()
n = 1;
}
- ws = xmalloc((wlen + 1) * sizeof (wchar_t));
+ if ((ws = malloc((wlen + 1) * sizeof (wchar_t))) == NULL)
+ nomem();
/* convert from multibyte to wide char */
(void)mbtowc(NULL, NULL, 0);
@@ -1195,7 +1208,8 @@ wcstrg()
ws[wi] = 0;
free(s);
- strg = xcalloc(1, sizeof (strg_t));
+ if ((strg = calloc(1, sizeof (strg_t))) == NULL)
+ nomem();
strg->st_tspec = WCHAR;
strg->st_len = wlen;
strg->st_wcp = ws;
diff --git a/usr.bin/xlint/lint1/tree.c b/usr.bin/xlint/lint1/tree.c
index ca10e1f6519a..ab14a99c6995 100644
--- a/usr.bin/xlint/lint1/tree.c
+++ b/usr.bin/xlint/lint1/tree.c
@@ -2694,7 +2694,8 @@ fold(tn)
u_quad_t ul, ur;
tnode_t *cn;
- v = xcalloc(1, sizeof (val_t));
+ if ((v = calloc(1, sizeof (val_t))) == NULL)
+ nomem();
v->v_tspec = t = tn->tn_type->t_tspec;
utyp = t == PTR || isutyp(t);
@@ -2840,7 +2841,8 @@ foldtst(tn)
int l, r;
val_t *v;
- v = xcalloc(1, sizeof (val_t));
+ if ((v = calloc(1, sizeof (val_t))) == NULL)
+ nomem();
v->v_tspec = tn->tn_type->t_tspec;
if (tn->tn_type->t_tspec != INT)
lerror("foldtst() 1");
@@ -2898,7 +2900,8 @@ foldflt(tn)
tspec_t t;
ldbl_t l, r;
- v = xcalloc(1, sizeof (val_t));
+ if ((v = calloc(1, sizeof (val_t))) == NULL)
+ nomem();
v->v_tspec = t = tn->tn_type->t_tspec;
if (!isftyp(t))
@@ -3265,7 +3268,8 @@ parg(n, tp, tn)
tnode_t *ln;
int warn;
- ln = xcalloc(1, sizeof (tnode_t));
+ if ((ln = calloc(1, sizeof (tnode_t))) == NULL)
+ nomem();
ln->tn_type = tduptyp(tp);
ln->tn_type->t_const = 0;
ln->tn_lvalue = 1;
@@ -3293,7 +3297,8 @@ constant(tn)
if (tn != NULL)
tn = promote(NOOP, 0, tn);
- v = xcalloc(1, sizeof (val_t));
+ if ((v = calloc(1, sizeof (val_t))) == NULL)
+ nomem();
if (tn == NULL) {
if (nerr == 0)
@@ -3458,7 +3463,8 @@ displexpr(tn, offs)
char *s;
size_t n;
n = MB_CUR_MAX * (tn->tn_strg->st_len + 1);
- s = xmalloc(n);
+ if ((s = malloc(n)) == NULL)
+ nomem();
(void)wcstombs(s, tn->tn_strg->st_wcp, n);
(void)printf("L\"%s\"", s);
free(s);
@@ -3829,12 +3835,14 @@ catstrg(strg1, strg2)
len = (len1 = strg1->st_len) + (len2 = strg2->st_len);
if (strg1->st_tspec == CHAR) {
- strg1->st_cp = xrealloc(strg1->st_cp, len + 1);
+ if ((strg1->st_cp = realloc(strg1->st_cp, len + 1)) == NULL)
+ nomem();
(void)memcpy(strg1->st_cp + len1, strg2->st_cp, len2 + 1);
free(strg2->st_cp);
} else {
- strg1->st_wcp = xrealloc(strg1->st_wcp,
- (len + 1) * sizeof (wchar_t));
+ if ((strg1->st_wcp = realloc(strg1->st_wcp, (len + 1) *
+ sizeof (wchar_t))) == NULL)
+ nomem();
(void)memcpy(strg1->st_wcp + len1, strg2->st_wcp,
(len2 + 1) * sizeof (wchar_t));
free(strg2->st_wcp);