summaryrefslogtreecommitdiff
path: root/usr.bin/lex/gen.c
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2015-11-19 23:28:04 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2015-11-19 23:28:04 +0000
commitb28f441103fbcc39cc45760802a62c2e8035edba (patch)
treece280d3c8a8ecc4fc30fae34c0617531c7189991 /usr.bin/lex/gen.c
parentc5173a2b4670bf712f6cf5ae35baf6f749393eb6 (diff)
it is not necessary to cast the result of malloc/calloc.
also replace some 0s with the modern concept of NULL
Diffstat (limited to 'usr.bin/lex/gen.c')
-rw-r--r--usr.bin/lex/gen.c95
1 files changed, 39 insertions, 56 deletions
diff --git a/usr.bin/lex/gen.c b/usr.bin/lex/gen.c
index 59b4235c8fa..0a3f29fa308 100644
--- a/usr.bin/lex/gen.c
+++ b/usr.bin/lex/gen.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gen.c,v 1.14 2015/11/19 23:20:34 tedu Exp $ */
+/* $OpenBSD: gen.c,v 1.15 2015/11/19 23:28:03 tedu Exp $ */
/* gen - actual generation (writing) of flex scanners */
@@ -108,15 +108,15 @@ static struct yytbl_data *
mkeoltbl(void)
{
int i;
- flex_int8_t *tdata = 0;
+ flex_int8_t *tdata = NULL;
struct yytbl_data *tbl;
- tbl = (struct yytbl_data *) calloc(1, sizeof(struct yytbl_data));
+ tbl = calloc(1, sizeof(struct yytbl_data));
yytbl_data_init(tbl, YYTD_ID_RULE_CAN_MATCH_EOL);
tbl->td_flags = YYTD_DATA8;
tbl->td_lolen = num_rules + 1;
tbl->td_data = tdata =
- (flex_int8_t *) calloc(tbl->td_lolen, sizeof(flex_int8_t));
+ calloc(tbl->td_lolen, sizeof(flex_int8_t));
for (i = 1; i <= num_rules; i++)
tdata[i] = rule_has_nl[i] ? 1 : 0;
@@ -214,8 +214,8 @@ static struct yytbl_data *
mkctbl(void)
{
int i;
- struct yytbl_data *tbl = 0;
- flex_int32_t *tdata = 0, curr = 0;
+ struct yytbl_data *tbl = NULL;
+ flex_int32_t *tdata = NULL, curr = 0;
int end_of_buffer_action = num_rules + 1;
buf_prints(&yydmap_buf,
@@ -223,14 +223,14 @@ mkctbl(void)
((tblend + numecs + 1) >= INT16_MAX
|| long_align) ? "flex_int32_t" : "flex_int16_t");
- tbl = (struct yytbl_data *) calloc(1, sizeof(struct yytbl_data));
+ tbl = calloc(1, sizeof(struct yytbl_data));
yytbl_data_init(tbl, YYTD_ID_TRANSITION);
tbl->td_flags = YYTD_DATA32 | YYTD_STRUCT;
tbl->td_hilen = 0;
tbl->td_lolen = tblend + numecs + 1; /* number of structs */
tbl->td_data = tdata =
- (flex_int32_t *) calloc(tbl->td_lolen * 2, sizeof(flex_int32_t));
+ calloc(tbl->td_lolen * 2, sizeof(flex_int32_t));
/*
* We want the transition to be represented as the offset to the next
@@ -314,18 +314,18 @@ mkctbl(void)
static struct yytbl_data *
mkssltbl(void)
{
- struct yytbl_data *tbl = 0;
- flex_int32_t *tdata = 0;
+ struct yytbl_data *tbl = NULL;
+ flex_int32_t *tdata = NULL;
flex_int32_t i;
- tbl = (struct yytbl_data *) calloc(1, sizeof(struct yytbl_data));
+ tbl = calloc(1, sizeof(struct yytbl_data));
yytbl_data_init(tbl, YYTD_ID_START_STATE_LIST);
tbl->td_flags = YYTD_DATA32 | YYTD_PTRANS;
tbl->td_hilen = 0;
tbl->td_lolen = lastsc * 2 + 1;
tbl->td_data = tdata =
- (flex_int32_t *) calloc(tbl->td_lolen, sizeof(flex_int32_t));
+ calloc(tbl->td_lolen, sizeof(flex_int32_t));
for (i = 0; i <= lastsc * 2; ++i)
tdata[i] = base[i];
@@ -449,17 +449,17 @@ struct yytbl_data *
mkecstbl(void)
{
int i;
- struct yytbl_data *tbl = 0;
- flex_int32_t *tdata = 0;
+ struct yytbl_data *tbl = NULL;
+ flex_int32_t *tdata = NULL;
- tbl = (struct yytbl_data *) calloc(1, sizeof(struct yytbl_data));
+ tbl = calloc(1, sizeof(struct yytbl_data));
yytbl_data_init(tbl, YYTD_ID_EC);
tbl->td_flags |= YYTD_DATA32;
tbl->td_hilen = 0;
tbl->td_lolen = csize;
tbl->td_data = tdata =
- (flex_int32_t *) calloc(tbl->td_lolen, sizeof(flex_int32_t));
+ calloc(tbl->td_lolen, sizeof(flex_int32_t));
for (i = 1; i < csize; ++i) {
ecgroup[i] = ABS(ecgroup[i]);
@@ -657,16 +657,16 @@ mkftbl(void)
int i;
int end_of_buffer_action = num_rules + 1;
struct yytbl_data *tbl;
- flex_int32_t *tdata = 0;
+ flex_int32_t *tdata = NULL;
- tbl = (struct yytbl_data *) calloc(1, sizeof(struct yytbl_data));
+ tbl = calloc(1, sizeof(struct yytbl_data));
yytbl_data_init(tbl, YYTD_ID_ACCEPT);
tbl->td_flags |= YYTD_DATA32;
tbl->td_hilen = 0; /* it's a one-dimensional array */
tbl->td_lolen = lastdfa + 1;
tbl->td_data = tdata =
- (flex_int32_t *) calloc(tbl->td_lolen, sizeof(flex_int32_t));
+ calloc(tbl->td_lolen, sizeof(flex_int32_t));
dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action;
@@ -1102,11 +1102,11 @@ gentabs()
"\t{YYTD_ID_ACCLIST, (void**)&yy_acclist, sizeof(%s)},\n",
long_align ? "flex_int32_t" : "flex_int16_t");
- yyacclist_tbl = (struct yytbl_data *) calloc(1, sizeof(struct yytbl_data));
+ yyacclist_tbl = calloc(1, sizeof(struct yytbl_data));
yytbl_data_init(yyacclist_tbl, YYTD_ID_ACCLIST);
yyacclist_tbl->td_lolen = MAX(numas, 1) + 1;
yyacclist_tbl->td_data = yyacclist_data =
- (flex_int32_t *) calloc(yyacclist_tbl->td_lolen, sizeof(flex_int32_t));
+ calloc(yyacclist_tbl->td_lolen, sizeof(flex_int32_t));
yyacclist_curr = 1;
j = 1; /* index into "yy_acclist" array */
@@ -1212,13 +1212,11 @@ gentabs()
"\t{YYTD_ID_ACCEPT, (void**)&yy_accept, sizeof(%s)},\n",
long_align ? "flex_int32_t" : "flex_int16_t");
- yyacc_tbl =
- (struct yytbl_data *) calloc(1,
- sizeof(struct yytbl_data));
+ yyacc_tbl = calloc(1, sizeof(struct yytbl_data));
yytbl_data_init(yyacc_tbl, YYTD_ID_ACCEPT);
yyacc_tbl->td_lolen = k;
yyacc_tbl->td_data = yyacc_data =
- (flex_int32_t *) calloc(yyacc_tbl->td_lolen, sizeof(flex_int32_t));
+ calloc(yyacc_tbl->td_lolen, sizeof(flex_int32_t));
yyacc_curr = 1;
for (i = 1; i <= lastdfa; ++i) {
@@ -1269,15 +1267,12 @@ gentabs()
* Write out meta-equivalence classes (used to index
* templates with).
*/
- flex_int32_t *yymecs_data = 0;
- yymeta_tbl =
- (struct yytbl_data *) calloc(1,
- sizeof(struct
- yytbl_data));
+ flex_int32_t *yymecs_data = NULL;
+ yymeta_tbl = calloc(1, sizeof(struct yytbl_data));
yytbl_data_init(yymeta_tbl, YYTD_ID_META);
yymeta_tbl->td_lolen = numecs + 1;
yymeta_tbl->td_data = yymecs_data =
- (flex_int32_t *) calloc(yymeta_tbl->td_lolen,
+ calloc(yymeta_tbl->td_lolen,
sizeof(flex_int32_t));
if (trace)
@@ -1320,13 +1315,11 @@ gentabs()
"\t{YYTD_ID_BASE, (void**)&yy_base, sizeof(%s)},\n",
(tblend >= INT16_MAX
|| long_align) ? "flex_int32_t" : "flex_int16_t");
- yybase_tbl =
- (struct yytbl_data *) calloc(1,
- sizeof(struct yytbl_data));
+ yybase_tbl = calloc(1, sizeof(struct yytbl_data));
yytbl_data_init(yybase_tbl, YYTD_ID_BASE);
yybase_tbl->td_lolen = total_states + 1;
yybase_tbl->td_data = yybase_data =
- (flex_int32_t *) calloc(yybase_tbl->td_lolen,
+ calloc(yybase_tbl->td_lolen,
sizeof(flex_int32_t));
yybase_curr = 1;
@@ -1379,13 +1372,11 @@ gentabs()
(total_states >= INT16_MAX
|| long_align) ? "flex_int32_t" : "flex_int16_t");
- yydef_tbl =
- (struct yytbl_data *) calloc(1,
- sizeof(struct yytbl_data));
+ yydef_tbl = calloc(1, sizeof(struct yytbl_data));
yytbl_data_init(yydef_tbl, YYTD_ID_DEF);
yydef_tbl->td_lolen = total_states + 1;
yydef_tbl->td_data = yydef_data =
- (flex_int32_t *) calloc(yydef_tbl->td_lolen, sizeof(flex_int32_t));
+ calloc(yydef_tbl->td_lolen, sizeof(flex_int32_t));
for (i = 1; i <= total_states; ++i) {
mkdata(def[i]);
@@ -1413,13 +1404,11 @@ gentabs()
(total_states >= INT16_MAX
|| long_align) ? "flex_int32_t" : "flex_int16_t");
- yynxt_tbl =
- (struct yytbl_data *) calloc(1,
- sizeof(struct yytbl_data));
+ yynxt_tbl = calloc(1, sizeof(struct yytbl_data));
yytbl_data_init(yynxt_tbl, YYTD_ID_NXT);
yynxt_tbl->td_lolen = tblend + 1;
yynxt_tbl->td_data = yynxt_data =
- (flex_int32_t *) calloc(yynxt_tbl->td_lolen, sizeof(flex_int32_t));
+ calloc(yynxt_tbl->td_lolen, sizeof(flex_int32_t));
for (i = 1; i <= tblend; ++i) {
/*
@@ -1453,13 +1442,11 @@ gentabs()
(total_states >= INT16_MAX
|| long_align) ? "flex_int32_t" : "flex_int16_t");
- yychk_tbl =
- (struct yytbl_data *) calloc(1,
- sizeof(struct yytbl_data));
+ yychk_tbl = calloc(1, sizeof(struct yytbl_data));
yytbl_data_init(yychk_tbl, YYTD_ID_CHK);
yychk_tbl->td_lolen = tblend + 1;
yychk_tbl->td_data = yychk_data =
- (flex_int32_t *) calloc(yychk_tbl->td_lolen, sizeof(flex_int32_t));
+ calloc(yychk_tbl->td_lolen, sizeof(flex_int32_t));
for (i = 1; i <= tblend; ++i) {
if (chk[i] == 0)
@@ -1479,7 +1466,7 @@ gentabs()
}
/* End generating yy_chk */
- free((void *) acc_array);
+ free(acc_array);
}
@@ -1706,7 +1693,7 @@ make_tables()
}
}
if (nultrans) {
- flex_int32_t *yynultrans_data = 0;
+ flex_int32_t *yynultrans_data = NULL;
/* Begin generating yy_NUL_trans */
out_str_dec(get_state_decl(), "yy_NUL_trans",
@@ -1716,16 +1703,13 @@ make_tables()
(fullspd) ? "struct yy_trans_info*" :
"flex_int32_t");
- yynultrans_tbl =
- (struct yytbl_data *) calloc(1,
- sizeof(struct
- yytbl_data));
+ yynultrans_tbl = calloc(1, sizeof(struct yytbl_data));
yytbl_data_init(yynultrans_tbl, YYTD_ID_NUL_TRANS);
if (fullspd)
yynultrans_tbl->td_flags |= YYTD_PTRANS;
yynultrans_tbl->td_lolen = lastdfa + 1;
yynultrans_tbl->td_data = yynultrans_data =
- (flex_int32_t *) calloc(yynultrans_tbl->td_lolen,
+ calloc(yynultrans_tbl->td_lolen,
sizeof(flex_int32_t));
for (i = 1; i <= lastdfa; ++i) {
@@ -1742,8 +1726,7 @@ make_tables()
dataend();
if (tablesext) {
yytbl_data_compress(yynultrans_tbl);
- if (yytbl_data_fwrite(&tableswr, yynultrans_tbl) <
- 0)
+ if (yytbl_data_fwrite(&tableswr, yynultrans_tbl) < 0)
flexerror(_
("Could not write yynultrans_tbl"));
yytbl_data_destroy(yynultrans_tbl);