From 7af68d4bf02a2ed7116bb0b25ce733e914acbef7 Mon Sep 17 00:00:00 2001 From: Kate F Date: Fri, 31 May 2024 07:34:21 -0700 Subject: [PATCH 1/4] Allow xrealloc() to free() on a size of 0. This matches the standard behaviour. I'd disallowed it to avoid confusion, but in rx I do actually want to realloc down to nothing and return NULL when size is 0. And that's what free() does, but it seems cumbersome to have a conditional around that in the caller. --- include/adt/xalloc.h | 1 + src/adt/xalloc.c | 5 +---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/include/adt/xalloc.h b/include/adt/xalloc.h index 373e72d46..d36132687 100644 --- a/include/adt/xalloc.h +++ b/include/adt/xalloc.h @@ -23,6 +23,7 @@ xmalloc(size_t sz); void * xcalloc(size_t count, size_t sz); +/* equivalent to free(p) when sz is 0, returns NULL */ void * xrealloc(void *p, size_t sz); diff --git a/src/adt/xalloc.c b/src/adt/xalloc.c index b80723ffd..86a83ead4 100644 --- a/src/adt/xalloc.c +++ b/src/adt/xalloc.c @@ -57,11 +57,8 @@ xrealloc(void *p, size_t sz) { void *q; - /* This is legal and frees p, but confusing; use free() instead */ - assert(sz != 0); - q = realloc(p, sz); - if (q == NULL) { + if (sz > 0 && q == NULL) { perror("realloc"); abort(); } From 88877cd858b5665d2752342dff8a85b5eadc506c Mon Sep 17 00:00:00 2001 From: Kate F Date: Fri, 31 May 2024 07:35:14 -0700 Subject: [PATCH 2/4] xstrndup() --- include/adt/xalloc.h | 3 +++ src/adt/xalloc.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/adt/xalloc.h b/include/adt/xalloc.h index d36132687..e398b3925 100644 --- a/include/adt/xalloc.h +++ b/include/adt/xalloc.h @@ -17,6 +17,9 @@ xstrdup(const char *s); * The following functions are for CLI use only; they exit on error */ +char * +xstrndup(const char *s, size_t n); + void * xmalloc(size_t sz); diff --git a/src/adt/xalloc.c b/src/adt/xalloc.c index 86a83ead4..b077c3b8f 100644 --- a/src/adt/xalloc.c +++ b/src/adt/xalloc.c @@ -4,6 +4,8 @@ * See LICENCE for the full copyright terms. */ +#define _POSIX_C_SOURCE 200809L + #include #include #include @@ -24,6 +26,18 @@ xstrdup(const char *s) return strcpy(new, s); } +char * +xstrndup(const char *s, size_t n) +{ + char *new = strndup(s, n); + if (new == NULL) { + perror("strndup"); + abort(); + } + + return new; +} + void * xmalloc(size_t sz) { From 4ec219a73b1a79186f5d3705cb0fbe60f7f5739d Mon Sep 17 00:00:00 2001 From: Kate F Date: Fri, 31 May 2024 07:53:29 -0700 Subject: [PATCH 3/4] Normalization; all x*() xalloc.h interfaces exit on error. There's no need to have xstrdup() behave differently here, it's just confusing. --- include/adt/xalloc.h | 9 +- src/adt/xalloc.c | 2 +- src/libfsm/parser.act | 10 +- src/libfsm/parser.c | 173 +++++++++----------- src/libfsm/parser.h | 4 +- src/lx/parser.act | 8 - src/lx/parser.c | 360 ++++++++++++++++++++---------------------- src/lx/parser.h | 4 +- src/retest/cvtpcre.c | 4 - 9 files changed, 253 insertions(+), 321 deletions(-) diff --git a/include/adt/xalloc.h b/include/adt/xalloc.h index e398b3925..cf7fd7b11 100644 --- a/include/adt/xalloc.h +++ b/include/adt/xalloc.h @@ -1,5 +1,5 @@ /* - * Copyright 2008-2017 Katherine Flavel + * Copyright 2008-2024 Katherine Flavel * * See LICENCE for the full copyright terms. */ @@ -8,15 +8,12 @@ #define XALLOC_H /* - * Duplicate a string. Returns NULL on error. + * These functions are for CLI use only; they exit on error */ + char * xstrdup(const char *s); -/* - * The following functions are for CLI use only; they exit on error - */ - char * xstrndup(const char *s, size_t n); diff --git a/src/adt/xalloc.c b/src/adt/xalloc.c index b077c3b8f..bdce10a49 100644 --- a/src/adt/xalloc.c +++ b/src/adt/xalloc.c @@ -1,5 +1,5 @@ /* - * Copyright 2008-2017 Katherine Flavel + * Copyright 2008-2024 Katherine Flavel * * See LICENCE for the full copyright terms. */ diff --git a/src/libfsm/parser.act b/src/libfsm/parser.act index 14ad7f169..80ace7fdf 100644 --- a/src/libfsm/parser.act +++ b/src/libfsm/parser.act @@ -241,11 +241,8 @@ @}; IDENT: () -> (s :string) = @{ + /* XXX: don't exit in library code */ @s = xstrdup(lex_state->buf.a); - if (@s == NULL) { - perror("xstrdup"); - exit(EXIT_FAILURE); - } @}; %actions% @@ -288,11 +285,8 @@ exit(EXIT_FAILURE); } + /* XXX: don't exit in library code */ new->id = xstrdup(@n); - if (new->id == NULL) { - perror("xstrdup"); - exit(EXIT_FAILURE); - } if (!fsm_addstate(fsm, &@s)) { perror("fsm_addstate"); diff --git a/src/libfsm/parser.c b/src/libfsm/parser.c index 81f1cc030..19d5664f3 100644 --- a/src/libfsm/parser.c +++ b/src/libfsm/parser.c @@ -9,7 +9,7 @@ /* BEGINNING OF HEADER */ -#line 150 "src/libfsm/parser.act" +#line 151 "src/libfsm/parser.act" #include @@ -135,7 +135,7 @@ htab->longest_chain_length = max_chain_length; } -#line 138 "src/libfsm/parser.c" +#line 139 "src/libfsm/parser.c" #ifndef ERROR_TERMINAL @@ -175,14 +175,14 @@ p_label(fsm fsm, lex_state lex_state, act_state act_state, char *ZOc) { /* BEGINNING OF EXTRACT: CHAR */ { -#line 239 "src/libfsm/parser.act" +#line 240 "src/libfsm/parser.act" assert(lex_state->buf.a[0] != '\0'); assert(lex_state->buf.a[1] == '\0'); ZIc = lex_state->buf.a[0]; -#line 185 "src/libfsm/parser.c" +#line 186 "src/libfsm/parser.c" } /* END OF EXTRACT: CHAR */ ADVANCE_LEXER; @@ -192,7 +192,7 @@ p_label(fsm fsm, lex_state lex_state, act_state act_state, char *ZOc) { /* BEGINNING OF EXTRACT: ESC */ { -#line 167 "src/libfsm/parser.act" +#line 168 "src/libfsm/parser.act" assert(0 == strncmp(lex_state->buf.a, "\\", 1)); assert(2 == strlen(lex_state->buf.a)); @@ -210,7 +210,7 @@ p_label(fsm fsm, lex_state lex_state, act_state act_state, char *ZOc) default: break; } -#line 213 "src/libfsm/parser.c" +#line 214 "src/libfsm/parser.c" } /* END OF EXTRACT: ESC */ ADVANCE_LEXER; @@ -220,7 +220,7 @@ p_label(fsm fsm, lex_state lex_state, act_state act_state, char *ZOc) { /* BEGINNING OF EXTRACT: HEX */ { -#line 232 "src/libfsm/parser.act" +#line 233 "src/libfsm/parser.act" unsigned long u; char *e; @@ -247,7 +247,7 @@ p_label(fsm fsm, lex_state lex_state, act_state act_state, char *ZOc) ZIc = (char) (unsigned char) u; -#line 250 "src/libfsm/parser.c" +#line 251 "src/libfsm/parser.c" } /* END OF EXTRACT: HEX */ ADVANCE_LEXER; @@ -257,7 +257,7 @@ p_label(fsm fsm, lex_state lex_state, act_state act_state, char *ZOc) { /* BEGINNING OF EXTRACT: OCT */ { -#line 205 "src/libfsm/parser.act" +#line 206 "src/libfsm/parser.act" unsigned long u; char *e; @@ -284,7 +284,7 @@ p_label(fsm fsm, lex_state lex_state, act_state act_state, char *ZOc) ZIc = (char) (unsigned char) u; -#line 287 "src/libfsm/parser.c" +#line 288 "src/libfsm/parser.c" } /* END OF EXTRACT: OCT */ ADVANCE_LEXER; @@ -330,15 +330,12 @@ ZL2_items:; case (TOK_IDENT): /* BEGINNING OF EXTRACT: IDENT */ { -#line 243 "src/libfsm/parser.act" +#line 245 "src/libfsm/parser.act" + /* XXX: don't exit in library code */ ZIa = xstrdup(lex_state->buf.a); - if (ZIa == NULL) { - perror("xstrdup"); - exit(EXIT_FAILURE); - } -#line 341 "src/libfsm/parser.c" +#line 339 "src/libfsm/parser.c" } /* END OF EXTRACT: IDENT */ break; @@ -398,11 +395,11 @@ p_xstart(fsm fsm, lex_state lex_state, act_state act_state) { /* BEGINNING OF ACTION: err-expected-start */ { -#line 371 "src/libfsm/parser.act" +#line 366 "src/libfsm/parser.act" err_expected(lex_state, "'start:'"); -#line 405 "src/libfsm/parser.c" +#line 403 "src/libfsm/parser.c" } /* END OF ACTION: err-expected-start */ } @@ -416,15 +413,12 @@ p_xstart(fsm fsm, lex_state lex_state, act_state act_state) case (TOK_IDENT): /* BEGINNING OF EXTRACT: IDENT */ { -#line 243 "src/libfsm/parser.act" +#line 245 "src/libfsm/parser.act" + /* XXX: don't exit in library code */ ZIn = xstrdup(lex_state->buf.a); - if (ZIn == NULL) { - perror("xstrdup"); - exit(EXIT_FAILURE); - } -#line 427 "src/libfsm/parser.c" +#line 422 "src/libfsm/parser.c" } /* END OF EXTRACT: IDENT */ break; @@ -442,7 +436,7 @@ p_xstart(fsm fsm, lex_state lex_state, act_state act_state) } /* BEGINNING OF ACTION: add-state */ { -#line 254 "src/libfsm/parser.act" +#line 252 "src/libfsm/parser.act" struct act_statelist *p; const unsigned hash = hash_of_id((ZIn)); @@ -481,11 +475,8 @@ p_xstart(fsm fsm, lex_state lex_state, act_state act_state) exit(EXIT_FAILURE); } + /* XXX: don't exit in library code */ new->id = xstrdup((ZIn)); - if (new->id == NULL) { - perror("xstrdup"); - exit(EXIT_FAILURE); - } if (!fsm_addstate(fsm, &(ZIs))) { perror("fsm_addstate"); @@ -498,25 +489,25 @@ p_xstart(fsm fsm, lex_state lex_state, act_state act_state) act_state->states.buckets[bucket_id] = new; } -#line 501 "src/libfsm/parser.c" +#line 493 "src/libfsm/parser.c" } /* END OF ACTION: add-state */ /* BEGINNING OF ACTION: mark-start */ { -#line 309 "src/libfsm/parser.act" +#line 304 "src/libfsm/parser.act" fsm_setstart(fsm, (ZIs)); -#line 510 "src/libfsm/parser.c" +#line 502 "src/libfsm/parser.c" } /* END OF ACTION: mark-start */ /* BEGINNING OF ACTION: free */ { -#line 317 "src/libfsm/parser.act" +#line 312 "src/libfsm/parser.act" free((ZIn)); -#line 519 "src/libfsm/parser.c" +#line 511 "src/libfsm/parser.c" } /* END OF ACTION: free */ } @@ -554,11 +545,11 @@ p_xend(fsm fsm, lex_state lex_state, act_state act_state) { /* BEGINNING OF ACTION: err-expected-end */ { -#line 375 "src/libfsm/parser.act" +#line 370 "src/libfsm/parser.act" err_expected(lex_state, "'end:'"); -#line 561 "src/libfsm/parser.c" +#line 553 "src/libfsm/parser.c" } /* END OF ACTION: err-expected-end */ } @@ -604,11 +595,11 @@ ZL1:; { /* BEGINNING OF ACTION: err-expected-sep */ { -#line 359 "src/libfsm/parser.act" +#line 354 "src/libfsm/parser.act" err_expected(lex_state, "';'"); -#line 611 "src/libfsm/parser.c" +#line 603 "src/libfsm/parser.c" } /* END OF ACTION: err-expected-sep */ } @@ -632,15 +623,12 @@ p_63(fsm fsm, lex_state lex_state, act_state act_state, string *ZIa) case (TOK_IDENT): /* BEGINNING OF EXTRACT: IDENT */ { -#line 243 "src/libfsm/parser.act" +#line 245 "src/libfsm/parser.act" + /* XXX: don't exit in library code */ ZIb = xstrdup(lex_state->buf.a); - if (ZIb == NULL) { - perror("xstrdup"); - exit(EXIT_FAILURE); - } -#line 643 "src/libfsm/parser.c" +#line 632 "src/libfsm/parser.c" } /* END OF EXTRACT: IDENT */ break; @@ -653,7 +641,7 @@ p_63(fsm fsm, lex_state lex_state, act_state act_state, string *ZIa) /* END OF INLINE: id */ /* BEGINNING OF ACTION: add-state */ { -#line 254 "src/libfsm/parser.act" +#line 252 "src/libfsm/parser.act" struct act_statelist *p; const unsigned hash = hash_of_id((*ZIa)); @@ -692,11 +680,8 @@ p_63(fsm fsm, lex_state lex_state, act_state act_state, string *ZIa) exit(EXIT_FAILURE); } + /* XXX: don't exit in library code */ new->id = xstrdup((*ZIa)); - if (new->id == NULL) { - perror("xstrdup"); - exit(EXIT_FAILURE); - } if (!fsm_addstate(fsm, &(ZIx))) { perror("fsm_addstate"); @@ -709,12 +694,12 @@ p_63(fsm fsm, lex_state lex_state, act_state act_state, string *ZIa) act_state->states.buckets[bucket_id] = new; } -#line 712 "src/libfsm/parser.c" +#line 698 "src/libfsm/parser.c" } /* END OF ACTION: add-state */ /* BEGINNING OF ACTION: add-state */ { -#line 254 "src/libfsm/parser.act" +#line 252 "src/libfsm/parser.act" struct act_statelist *p; const unsigned hash = hash_of_id((ZIb)); @@ -753,11 +738,8 @@ p_63(fsm fsm, lex_state lex_state, act_state act_state, string *ZIa) exit(EXIT_FAILURE); } + /* XXX: don't exit in library code */ new->id = xstrdup((ZIb)); - if (new->id == NULL) { - perror("xstrdup"); - exit(EXIT_FAILURE); - } if (!fsm_addstate(fsm, &(ZIy))) { perror("fsm_addstate"); @@ -770,25 +752,25 @@ p_63(fsm fsm, lex_state lex_state, act_state act_state, string *ZIa) act_state->states.buckets[bucket_id] = new; } -#line 773 "src/libfsm/parser.c" +#line 756 "src/libfsm/parser.c" } /* END OF ACTION: add-state */ /* BEGINNING OF ACTION: free */ { -#line 317 "src/libfsm/parser.act" +#line 312 "src/libfsm/parser.act" free((*ZIa)); -#line 782 "src/libfsm/parser.c" +#line 765 "src/libfsm/parser.c" } /* END OF ACTION: free */ /* BEGINNING OF ACTION: free */ { -#line 317 "src/libfsm/parser.act" +#line 312 "src/libfsm/parser.act" free((ZIb)); -#line 791 "src/libfsm/parser.c" +#line 774 "src/libfsm/parser.c" } /* END OF ACTION: free */ /* BEGINNING OF INLINE: 42 */ @@ -799,14 +781,14 @@ p_63(fsm fsm, lex_state lex_state, act_state act_state, string *ZIa) ADVANCE_LEXER; /* BEGINNING OF ACTION: add-edge-any */ { -#line 343 "src/libfsm/parser.act" +#line 338 "src/libfsm/parser.act" if (!fsm_addedge_any(fsm, (ZIx), (ZIy))) { perror("fsm_addedge_any"); exit(EXIT_FAILURE); } -#line 809 "src/libfsm/parser.c" +#line 792 "src/libfsm/parser.c" } /* END OF ACTION: add-edge-any */ } @@ -822,14 +804,14 @@ p_63(fsm fsm, lex_state lex_state, act_state act_state, string *ZIa) } /* BEGINNING OF ACTION: add-edge-literal */ { -#line 336 "src/libfsm/parser.act" +#line 331 "src/libfsm/parser.act" if (!fsm_addedge_literal(fsm, (ZIx), (ZIy), (ZIc))) { perror("fsm_addedge_literal"); exit(EXIT_FAILURE); } -#line 832 "src/libfsm/parser.c" +#line 815 "src/libfsm/parser.c" } /* END OF ACTION: add-edge-literal */ } @@ -838,14 +820,14 @@ p_63(fsm fsm, lex_state lex_state, act_state act_state, string *ZIa) { /* BEGINNING OF ACTION: add-edge-epsilon */ { -#line 350 "src/libfsm/parser.act" +#line 345 "src/libfsm/parser.act" if (!fsm_addedge_epsilon(fsm, (ZIx), (ZIy))) { perror("fsm_addedge_epsilon"); exit(EXIT_FAILURE); } -#line 848 "src/libfsm/parser.c" +#line 831 "src/libfsm/parser.c" } /* END OF ACTION: add-edge-epsilon */ } @@ -856,11 +838,11 @@ p_63(fsm fsm, lex_state lex_state, act_state act_state, string *ZIa) { /* BEGINNING OF ACTION: err-expected-trans */ { -#line 363 "src/libfsm/parser.act" +#line 358 "src/libfsm/parser.act" err_expected(lex_state, "transition"); -#line 863 "src/libfsm/parser.c" +#line 846 "src/libfsm/parser.c" } /* END OF ACTION: err-expected-trans */ } @@ -880,7 +862,7 @@ p_63(fsm fsm, lex_state lex_state, act_state act_state, string *ZIa) /* BEGINNING OF ACTION: add-state */ { -#line 254 "src/libfsm/parser.act" +#line 252 "src/libfsm/parser.act" struct act_statelist *p; const unsigned hash = hash_of_id((*ZIa)); @@ -919,11 +901,8 @@ p_63(fsm fsm, lex_state lex_state, act_state act_state, string *ZIa) exit(EXIT_FAILURE); } + /* XXX: don't exit in library code */ new->id = xstrdup((*ZIa)); - if (new->id == NULL) { - perror("xstrdup"); - exit(EXIT_FAILURE); - } if (!fsm_addstate(fsm, &(ZI45))) { perror("fsm_addstate"); @@ -936,16 +915,16 @@ p_63(fsm fsm, lex_state lex_state, act_state act_state, string *ZIa) act_state->states.buckets[bucket_id] = new; } -#line 939 "src/libfsm/parser.c" +#line 919 "src/libfsm/parser.c" } /* END OF ACTION: add-state */ /* BEGINNING OF ACTION: free */ { -#line 317 "src/libfsm/parser.act" +#line 312 "src/libfsm/parser.act" free((*ZIa)); -#line 948 "src/libfsm/parser.c" +#line 928 "src/libfsm/parser.c" } /* END OF ACTION: free */ p_61 (fsm, lex_state, act_state); @@ -988,7 +967,7 @@ p_fsm(fsm fsm, lex_state lex_state, act_state act_state) ADVANCE_LEXER; /* BEGINNING OF ACTION: free-statelist */ { -#line 333 "src/libfsm/parser.act" +#line 328 "src/libfsm/parser.act" struct act_statelist *p; struct act_statelist *next; @@ -1003,7 +982,7 @@ p_fsm(fsm fsm, lex_state lex_state, act_state act_state) } } -#line 1006 "src/libfsm/parser.c" +#line 986 "src/libfsm/parser.c" } /* END OF ACTION: free-statelist */ } @@ -1012,12 +991,12 @@ ZL1:; { /* BEGINNING OF ACTION: err-syntax */ { -#line 380 "src/libfsm/parser.act" +#line 375 "src/libfsm/parser.act" err(lex_state, "Syntax error"); exit(EXIT_FAILURE); -#line 1020 "src/libfsm/parser.c" +#line 1000 "src/libfsm/parser.c" } /* END OF ACTION: err-syntax */ } @@ -1053,11 +1032,11 @@ ZL2_xend_C_Cend_Hids:; { /* BEGINNING OF ACTION: err-expected-comma */ { -#line 367 "src/libfsm/parser.act" +#line 362 "src/libfsm/parser.act" err_expected(lex_state, "','"); -#line 1060 "src/libfsm/parser.c" +#line 1040 "src/libfsm/parser.c" } /* END OF ACTION: err-expected-comma */ } @@ -1101,15 +1080,12 @@ p_xend_C_Cend_Hid(fsm fsm, lex_state lex_state, act_state act_state) case (TOK_IDENT): /* BEGINNING OF EXTRACT: IDENT */ { -#line 243 "src/libfsm/parser.act" +#line 245 "src/libfsm/parser.act" + /* XXX: don't exit in library code */ ZIn = xstrdup(lex_state->buf.a); - if (ZIn == NULL) { - perror("xstrdup"); - exit(EXIT_FAILURE); - } -#line 1112 "src/libfsm/parser.c" +#line 1089 "src/libfsm/parser.c" } /* END OF EXTRACT: IDENT */ break; @@ -1122,7 +1098,7 @@ p_xend_C_Cend_Hid(fsm fsm, lex_state lex_state, act_state act_state) /* END OF INLINE: id */ /* BEGINNING OF ACTION: add-state */ { -#line 254 "src/libfsm/parser.act" +#line 252 "src/libfsm/parser.act" struct act_statelist *p; const unsigned hash = hash_of_id((ZIn)); @@ -1161,11 +1137,8 @@ p_xend_C_Cend_Hid(fsm fsm, lex_state lex_state, act_state act_state) exit(EXIT_FAILURE); } + /* XXX: don't exit in library code */ new->id = xstrdup((ZIn)); - if (new->id == NULL) { - perror("xstrdup"); - exit(EXIT_FAILURE); - } if (!fsm_addstate(fsm, &(ZIs))) { perror("fsm_addstate"); @@ -1178,25 +1151,25 @@ p_xend_C_Cend_Hid(fsm fsm, lex_state lex_state, act_state act_state) act_state->states.buckets[bucket_id] = new; } -#line 1181 "src/libfsm/parser.c" +#line 1155 "src/libfsm/parser.c" } /* END OF ACTION: add-state */ /* BEGINNING OF ACTION: mark-end */ { -#line 313 "src/libfsm/parser.act" +#line 308 "src/libfsm/parser.act" fsm_setend(fsm, (ZIs), 1); -#line 1190 "src/libfsm/parser.c" +#line 1164 "src/libfsm/parser.c" } /* END OF ACTION: mark-end */ /* BEGINNING OF ACTION: free */ { -#line 317 "src/libfsm/parser.act" +#line 312 "src/libfsm/parser.act" free((ZIn)); -#line 1199 "src/libfsm/parser.c" +#line 1173 "src/libfsm/parser.c" } /* END OF ACTION: free */ } @@ -1208,7 +1181,7 @@ ZL1:; /* BEGINNING OF TRAILER */ -#line 436 "src/libfsm/parser.act" +#line 431 "src/libfsm/parser.act" struct fsm *fsm_parse(FILE *f, const struct fsm_options *opt) { @@ -1263,6 +1236,6 @@ ZL1:; return new; } -#line 1266 "src/libfsm/parser.c" +#line 1240 "src/libfsm/parser.c" /* END OF FILE */ diff --git a/src/libfsm/parser.h b/src/libfsm/parser.h index 181f13d44..70155c504 100644 --- a/src/libfsm/parser.h +++ b/src/libfsm/parser.h @@ -9,7 +9,7 @@ /* BEGINNING OF HEADER */ -#line 159 "src/libfsm/parser.act" +#line 160 "src/libfsm/parser.act" typedef struct lex_state * lex_state; @@ -26,7 +26,7 @@ extern void p_fsm(fsm, lex_state, act_state); /* BEGINNING OF TRAILER */ -#line 437 "src/libfsm/parser.act" +#line 432 "src/libfsm/parser.act" #line 32 "src/libfsm/parser.h" diff --git a/src/lx/parser.act b/src/lx/parser.act index f9b0b32f9..27975d9d5 100644 --- a/src/lx/parser.act +++ b/src/lx/parser.act @@ -223,18 +223,10 @@ TOKEN: () -> (s :string) = @{ /* TODO: submatch addressing */ @s = xstrdup(lex_state->buf.a + 1); /* +1 for '$' prefix */ - if (@s == NULL) { - perror("xstrdup"); - exit(EXIT_FAILURE); - } @}; IDENT: () -> (s :string) = @{ @s = xstrdup(lex_state->buf.a); - if (@s == NULL) { - perror("xstrdup"); - exit(EXIT_FAILURE); - } @}; RE: () -> (f :flags) = @{ diff --git a/src/lx/parser.c b/src/lx/parser.c index dfcf36b8f..0933c386f 100644 --- a/src/lx/parser.c +++ b/src/lx/parser.c @@ -9,7 +9,7 @@ /* BEGINNING OF HEADER */ -#line 27 "src/lx/parser.act" +#line 128 "src/lx/parser.act" #include @@ -183,7 +183,7 @@ ZL1:; { /* BEGINNING OF ACTION: err-expected-list */ { -#line 823 "src/lx/parser.act" +#line 817 "src/lx/parser.act" err_expected(lex_state, "list of mappings, bindings or zones"); @@ -205,21 +205,17 @@ p_pattern(lex_state lex_state, act_state act_state, zone ZIz, fsm *ZOr) /* BEGINNING OF EXTRACT: IDENT */ { -#line 232 "src/lx/parser.act" +#line 229 "src/lx/parser.act" ZIn = xstrdup(lex_state->buf.a); - if (ZIn == NULL) { - perror("xstrdup"); - exit(EXIT_FAILURE); - } -#line 217 "src/lx/parser.c" +#line 213 "src/lx/parser.c" } /* END OF EXTRACT: IDENT */ ADVANCE_LEXER; /* BEGINNING OF ACTION: deref-var */ { -#line 286 "src/lx/parser.act" +#line 281 "src/lx/parser.act" struct ast_zone *z; @@ -246,7 +242,7 @@ p_pattern(lex_state lex_state, act_state act_state, zone ZIz, fsm *ZOr) goto ZL1; } -#line 250 "src/lx/parser.c" +#line 246 "src/lx/parser.c" } /* END OF ACTION: deref-var */ } @@ -257,22 +253,18 @@ p_pattern(lex_state lex_state, act_state act_state, zone ZIz, fsm *ZOr) /* BEGINNING OF EXTRACT: TOKEN */ { -#line 223 "src/lx/parser.act" +#line 225 "src/lx/parser.act" /* TODO: submatch addressing */ ZIt = xstrdup(lex_state->buf.a + 1); /* +1 for '$' prefix */ - if (ZIt == NULL) { - perror("xstrdup"); - exit(EXIT_FAILURE); - } -#line 270 "src/lx/parser.c" +#line 262 "src/lx/parser.c" } /* END OF EXTRACT: TOKEN */ ADVANCE_LEXER; /* BEGINNING OF ACTION: deref-token */ { -#line 313 "src/lx/parser.act" +#line 309 "src/lx/parser.act" const struct ast_mapping *m; fsm_state_t start; @@ -329,7 +321,7 @@ p_pattern(lex_state lex_state, act_state act_state, zone ZIz, fsm *ZOr) fsm_setstart((ZIr), start); -#line 333 "src/lx/parser.c" +#line 325 "src/lx/parser.c" } /* END OF ACTION: deref-token */ } @@ -383,7 +375,7 @@ p_list_Hof_Hthings_C_Cthing(lex_state lex_state, act_state act_state, ast ZIa, z } /* BEGINNING OF ACTION: op-reverse */ { -#line 685 "src/lx/parser.act" +#line 678 "src/lx/parser.act" assert((ZI210) != NULL); @@ -392,7 +384,7 @@ p_list_Hof_Hthings_C_Cthing(lex_state lex_state, act_state act_state, ast ZIa, z goto ZL1; } -#line 396 "src/lx/parser.c" +#line 388 "src/lx/parser.c" } /* END OF ACTION: op-reverse */ p_212 (lex_state, act_state, &ZIz, &ZI210, &ZI206); @@ -407,7 +399,7 @@ p_list_Hof_Hthings_C_Cthing(lex_state lex_state, act_state act_state, ast ZIa, z } /* BEGINNING OF ACTION: subtract-exit */ { -#line 744 "src/lx/parser.act" +#line 737 "src/lx/parser.act" assert((ZI231) != NULL); @@ -427,7 +419,7 @@ p_list_Hof_Hthings_C_Cthing(lex_state lex_state, act_state act_state, ast ZIa, z } } -#line 431 "src/lx/parser.c" +#line 423 "src/lx/parser.c" } /* END OF ACTION: subtract-exit */ p_251 (lex_state, act_state, &ZIa, &ZIz, &ZIexit, &ZI232, &ZI233); @@ -458,7 +450,7 @@ p_list_Hof_Hthings_C_Cthing(lex_state lex_state, act_state act_state, ast ZIa, z } /* BEGINNING OF ACTION: op-complete */ { -#line 676 "src/lx/parser.act" +#line 669 "src/lx/parser.act" assert((ZI210) != NULL); @@ -467,7 +459,7 @@ p_list_Hof_Hthings_C_Cthing(lex_state lex_state, act_state act_state, ast ZIa, z goto ZL1; } -#line 471 "src/lx/parser.c" +#line 463 "src/lx/parser.c" } /* END OF ACTION: op-complete */ p_212 (lex_state, act_state, &ZIz, &ZI210, &ZI206); @@ -482,7 +474,7 @@ p_list_Hof_Hthings_C_Cthing(lex_state lex_state, act_state act_state, ast ZIa, z } /* BEGINNING OF ACTION: subtract-exit */ { -#line 744 "src/lx/parser.act" +#line 737 "src/lx/parser.act" assert((ZI239) != NULL); @@ -502,7 +494,7 @@ p_list_Hof_Hthings_C_Cthing(lex_state lex_state, act_state act_state, ast ZIa, z } } -#line 506 "src/lx/parser.c" +#line 498 "src/lx/parser.c" } /* END OF ACTION: subtract-exit */ p_251 (lex_state, act_state, &ZIa, &ZIz, &ZIexit, &ZI240, &ZI241); @@ -518,15 +510,11 @@ p_list_Hof_Hthings_C_Cthing(lex_state lex_state, act_state act_state, ast ZIa, z /* BEGINNING OF EXTRACT: IDENT */ { -#line 232 "src/lx/parser.act" +#line 229 "src/lx/parser.act" ZIn = xstrdup(lex_state->buf.a); - if (ZIn == NULL) { - perror("xstrdup"); - exit(EXIT_FAILURE); - } -#line 530 "src/lx/parser.c" +#line 518 "src/lx/parser.c" } /* END OF EXTRACT: IDENT */ ADVANCE_LEXER; @@ -576,7 +564,7 @@ p_list_Hof_Hthings_C_Cthing(lex_state lex_state, act_state act_state, ast ZIa, z } /* BEGINNING OF ACTION: subtract-exit */ { -#line 744 "src/lx/parser.act" +#line 737 "src/lx/parser.act" assert((ZI248) != NULL); @@ -596,7 +584,7 @@ p_list_Hof_Hthings_C_Cthing(lex_state lex_state, act_state act_state, ast ZIa, z } } -#line 600 "src/lx/parser.c" +#line 588 "src/lx/parser.c" } /* END OF ACTION: subtract-exit */ p_251 (lex_state, act_state, &ZIa, &ZIz, &ZIexit, &ZI249, &ZI250); @@ -627,7 +615,7 @@ p_list_Hof_Hthings_C_Cthing(lex_state lex_state, act_state act_state, ast ZIa, z } /* BEGINNING OF ACTION: op-complement */ { -#line 667 "src/lx/parser.act" +#line 660 "src/lx/parser.act" assert((ZI210) != NULL); @@ -636,7 +624,7 @@ p_list_Hof_Hthings_C_Cthing(lex_state lex_state, act_state act_state, ast ZIa, z goto ZL1; } -#line 640 "src/lx/parser.c" +#line 628 "src/lx/parser.c" } /* END OF ACTION: op-complement */ p_212 (lex_state, act_state, &ZIz, &ZI210, &ZI206); @@ -651,7 +639,7 @@ p_list_Hof_Hthings_C_Cthing(lex_state lex_state, act_state act_state, ast ZIa, z } /* BEGINNING OF ACTION: subtract-exit */ { -#line 744 "src/lx/parser.act" +#line 737 "src/lx/parser.act" assert((ZI223) != NULL); @@ -671,7 +659,7 @@ p_list_Hof_Hthings_C_Cthing(lex_state lex_state, act_state act_state, ast ZIa, z } } -#line 675 "src/lx/parser.c" +#line 663 "src/lx/parser.c" } /* END OF ACTION: subtract-exit */ p_251 (lex_state, act_state, &ZIa, &ZIz, &ZIexit, &ZI224, &ZI225); @@ -698,22 +686,18 @@ p_list_Hof_Hthings_C_Cthing(lex_state lex_state, act_state act_state, ast ZIa, z /* BEGINNING OF EXTRACT: TOKEN */ { -#line 223 "src/lx/parser.act" +#line 225 "src/lx/parser.act" /* TODO: submatch addressing */ ZI253 = xstrdup(lex_state->buf.a + 1); /* +1 for '$' prefix */ - if (ZI253 == NULL) { - perror("xstrdup"); - exit(EXIT_FAILURE); - } -#line 711 "src/lx/parser.c" +#line 695 "src/lx/parser.c" } /* END OF EXTRACT: TOKEN */ ADVANCE_LEXER; /* BEGINNING OF ACTION: deref-token */ { -#line 313 "src/lx/parser.act" +#line 309 "src/lx/parser.act" const struct ast_mapping *m; fsm_state_t start; @@ -770,7 +754,7 @@ p_list_Hof_Hthings_C_Cthing(lex_state lex_state, act_state act_state, ast ZIa, z fsm_setstart((ZI254), start); -#line 774 "src/lx/parser.c" +#line 758 "src/lx/parser.c" } /* END OF ACTION: deref-token */ p_197 (lex_state, act_state, ZI254, &ZI210); @@ -786,7 +770,7 @@ p_list_Hof_Hthings_C_Cthing(lex_state lex_state, act_state act_state, ast ZIa, z } /* BEGINNING OF ACTION: subtract-exit */ { -#line 744 "src/lx/parser.act" +#line 737 "src/lx/parser.act" assert((ZI259) != NULL); @@ -806,7 +790,7 @@ p_list_Hof_Hthings_C_Cthing(lex_state lex_state, act_state act_state, ast ZIa, z } } -#line 810 "src/lx/parser.c" +#line 794 "src/lx/parser.c" } /* END OF ACTION: subtract-exit */ p_251 (lex_state, act_state, &ZIa, &ZIz, &ZIexit, &ZI260, &ZI261); @@ -846,7 +830,7 @@ p_list_Hof_Hthings_C_Cthing(lex_state lex_state, act_state act_state, ast ZIa, z } /* BEGINNING OF ACTION: subtract-exit */ { -#line 744 "src/lx/parser.act" +#line 737 "src/lx/parser.act" assert((ZI268) != NULL); @@ -866,7 +850,7 @@ p_list_Hof_Hthings_C_Cthing(lex_state lex_state, act_state act_state, ast ZIa, z } } -#line 870 "src/lx/parser.c" +#line 854 "src/lx/parser.c" } /* END OF ACTION: subtract-exit */ p_251 (lex_state, act_state, &ZIa, &ZIz, &ZIexit, &ZI269, &ZI270); @@ -886,11 +870,11 @@ ZL1:; { /* BEGINNING OF ACTION: err-expected-thing */ { -#line 819 "src/lx/parser.act" +#line 813 "src/lx/parser.act" err_expected(lex_state, "mapping, binding or zone"); -#line 894 "src/lx/parser.c" +#line 878 "src/lx/parser.c" } /* END OF ACTION: err-expected-thing */ } @@ -916,11 +900,11 @@ ZL1:; { /* BEGINNING OF ACTION: err-expected-open */ { -#line 807 "src/lx/parser.act" +#line 801 "src/lx/parser.act" err_expected(lex_state, "'{'"); -#line 924 "src/lx/parser.c" +#line 908 "src/lx/parser.c" } /* END OF ACTION: err-expected-open */ } @@ -946,11 +930,11 @@ ZL1:; { /* BEGINNING OF ACTION: err-expected-close */ { -#line 811 "src/lx/parser.act" +#line 805 "src/lx/parser.act" err_expected(lex_state, "'}'"); -#line 954 "src/lx/parser.c" +#line 938 "src/lx/parser.c" } /* END OF ACTION: err-expected-close */ } @@ -972,14 +956,14 @@ ZL2_pattern_C_Cbody:; { /* BEGINNING OF EXTRACT: CHAR */ { -#line 216 "src/lx/parser.act" +#line 220 "src/lx/parser.act" assert(lex_state->buf.a[0] != '\0'); assert(lex_state->buf.a[1] == '\0'); ZIc = lex_state->buf.a[0]; -#line 983 "src/lx/parser.c" +#line 967 "src/lx/parser.c" } /* END OF EXTRACT: CHAR */ ADVANCE_LEXER; @@ -989,7 +973,7 @@ ZL2_pattern_C_Cbody:; { /* BEGINNING OF EXTRACT: ESC */ { -#line 144 "src/lx/parser.act" +#line 150 "src/lx/parser.act" assert(lex_state->buf.a[0] == '\\'); assert(lex_state->buf.a[1] != '\0'); @@ -1007,7 +991,7 @@ ZL2_pattern_C_Cbody:; default: ZIc = '\0'; break; /* TODO: handle error */ } -#line 1011 "src/lx/parser.c" +#line 995 "src/lx/parser.c" } /* END OF EXTRACT: ESC */ ADVANCE_LEXER; @@ -1017,7 +1001,7 @@ ZL2_pattern_C_Cbody:; { /* BEGINNING OF EXTRACT: HEX */ { -#line 189 "src/lx/parser.act" +#line 213 "src/lx/parser.act" unsigned long u; char *e; @@ -1044,7 +1028,7 @@ ZL2_pattern_C_Cbody:; ZIc = (char) (unsigned char) u; -#line 1048 "src/lx/parser.c" +#line 1032 "src/lx/parser.c" } /* END OF EXTRACT: HEX */ ADVANCE_LEXER; @@ -1054,7 +1038,7 @@ ZL2_pattern_C_Cbody:; { /* BEGINNING OF EXTRACT: OCT */ { -#line 162 "src/lx/parser.act" +#line 186 "src/lx/parser.act" unsigned long u; char *e; @@ -1081,7 +1065,7 @@ ZL2_pattern_C_Cbody:; ZIc = (char) (unsigned char) u; -#line 1085 "src/lx/parser.c" +#line 1069 "src/lx/parser.c" } /* END OF EXTRACT: OCT */ ADVANCE_LEXER; @@ -1094,19 +1078,19 @@ ZL2_pattern_C_Cbody:; /* END OF INLINE: 84 */ /* BEGINNING OF ACTION: pattern-char */ { -#line 256 "src/lx/parser.act" +#line 250 "src/lx/parser.act" /* TODO */ *lex_state->p++ = (ZIc); -#line 1103 "src/lx/parser.c" +#line 1087 "src/lx/parser.c" } /* END OF ACTION: pattern-char */ /* BEGINNING OF INLINE: pattern::body */ goto ZL2_pattern_C_Cbody; /* END OF INLINE: pattern::body */ } - /* UNREACHED */ + /*UNREACHED*/ case (ERROR_TERMINAL): return; default: @@ -1141,7 +1125,7 @@ ZL2_174:; } /* END OF INLINE: 174 */ } - /* UNREACHED */ + /*UNREACHED*/ default: { ZI171 = ZI168; @@ -1228,7 +1212,7 @@ ZL2_180:; } /* BEGINNING OF ACTION: op-alt */ { -#line 733 "src/lx/parser.act" +#line 726 "src/lx/parser.act" assert((ZI177) != NULL); assert((ZIb) != NULL); @@ -1239,7 +1223,7 @@ ZL2_180:; goto ZL1; } -#line 1243 "src/lx/parser.c" +#line 1227 "src/lx/parser.c" } /* END OF ACTION: op-alt */ /* BEGINNING OF INLINE: 180 */ @@ -1247,7 +1231,7 @@ ZL2_180:; goto ZL2_180; /* END OF INLINE: 180 */ } - /* UNREACHED */ + /*UNREACHED*/ default: { ZI178 = ZI176; @@ -1308,7 +1292,7 @@ p_expr_C_Cprefix_Hexpr(lex_state lex_state, act_state act_state, zone ZIz, fsm * } /* BEGINNING OF ACTION: op-reverse */ { -#line 685 "src/lx/parser.act" +#line 678 "src/lx/parser.act" assert((ZIq) != NULL); @@ -1317,7 +1301,7 @@ p_expr_C_Cprefix_Hexpr(lex_state lex_state, act_state act_state, zone ZIz, fsm * goto ZL1; } -#line 1321 "src/lx/parser.c" +#line 1305 "src/lx/parser.c" } /* END OF ACTION: op-reverse */ } @@ -1332,7 +1316,7 @@ p_expr_C_Cprefix_Hexpr(lex_state lex_state, act_state act_state, zone ZIz, fsm * } /* BEGINNING OF ACTION: op-complete */ { -#line 676 "src/lx/parser.act" +#line 669 "src/lx/parser.act" assert((ZIq) != NULL); @@ -1341,7 +1325,7 @@ p_expr_C_Cprefix_Hexpr(lex_state lex_state, act_state act_state, zone ZIz, fsm * goto ZL1; } -#line 1345 "src/lx/parser.c" +#line 1329 "src/lx/parser.c" } /* END OF ACTION: op-complete */ } @@ -1356,7 +1340,7 @@ p_expr_C_Cprefix_Hexpr(lex_state lex_state, act_state act_state, zone ZIz, fsm * } /* BEGINNING OF ACTION: op-complement */ { -#line 667 "src/lx/parser.act" +#line 660 "src/lx/parser.act" assert((ZIq) != NULL); @@ -1365,7 +1349,7 @@ p_expr_C_Cprefix_Hexpr(lex_state lex_state, act_state act_state, zone ZIz, fsm * goto ZL1; } -#line 1369 "src/lx/parser.c" +#line 1353 "src/lx/parser.c" } /* END OF ACTION: op-complement */ } @@ -1415,7 +1399,7 @@ ZL2_186:; } /* BEGINNING OF ACTION: op-intersect */ { -#line 722 "src/lx/parser.act" +#line 715 "src/lx/parser.act" assert((ZI183) != NULL); assert((ZIb) != NULL); @@ -1426,7 +1410,7 @@ ZL2_186:; goto ZL1; } -#line 1430 "src/lx/parser.c" +#line 1414 "src/lx/parser.c" } /* END OF ACTION: op-intersect */ /* BEGINNING OF INLINE: 186 */ @@ -1434,7 +1418,7 @@ ZL2_186:; goto ZL2_186; /* END OF INLINE: 186 */ } - /* UNREACHED */ + /*UNREACHED*/ default: { ZI184 = ZI182; @@ -1472,7 +1456,7 @@ ZL2_list_Hof_Hthings_C_Czone_Hthing_C_Clist_Hof_Hzone_Hto_Hmappings_C_Clist_Hof_ } /* BEGINNING OF ACTION: op-alt */ { -#line 733 "src/lx/parser.act" +#line 726 "src/lx/parser.act" assert((ZIold_Hexit) != NULL); assert((ZInew_Hexit) != NULL); @@ -1483,14 +1467,14 @@ ZL2_list_Hof_Hthings_C_Czone_Hthing_C_Clist_Hof_Hzone_Hto_Hmappings_C_Clist_Hof_ goto ZL1; } -#line 1487 "src/lx/parser.c" +#line 1471 "src/lx/parser.c" } /* END OF ACTION: op-alt */ /* BEGINNING OF INLINE: list-of-things::zone-thing::list-of-zone-to-mappings::list-of-zone-to-mappings-x */ goto ZL2_list_Hof_Hthings_C_Czone_Hthing_C_Clist_Hof_Hzone_Hto_Hmappings_C_Clist_Hof_Hzone_Hto_Hmappings_Hx; /* END OF INLINE: list-of-things::zone-thing::list-of-zone-to-mappings::list-of-zone-to-mappings-x */ } - /* UNREACHED */ + /*UNREACHED*/ case (ERROR_TERMINAL): return; default: @@ -1571,7 +1555,7 @@ ZL2_197:; ADVANCE_LEXER; /* BEGINNING OF ACTION: op-cross */ { -#line 577 "src/lx/parser.act" +#line 576 "src/lx/parser.act" fsm_state_t start, end; fsm_state_t old; @@ -1616,7 +1600,7 @@ ZL2_197:; fsm_setstart((ZIq), start); -#line 1620 "src/lx/parser.c" +#line 1604 "src/lx/parser.c" } /* END OF ACTION: op-cross */ /* BEGINNING OF INLINE: 197 */ @@ -1624,13 +1608,13 @@ ZL2_197:; goto ZL2_197; /* END OF INLINE: 197 */ } - /* UNREACHED */ + /*UNREACHED*/ case (TOK_QMARK): { ADVANCE_LEXER; /* BEGINNING OF ACTION: op-qmark */ { -#line 622 "src/lx/parser.act" +#line 621 "src/lx/parser.act" fsm_state_t start, end; fsm_state_t old; @@ -1675,7 +1659,7 @@ ZL2_197:; fsm_setstart((ZIq), start); -#line 1679 "src/lx/parser.c" +#line 1663 "src/lx/parser.c" } /* END OF ACTION: op-qmark */ /* BEGINNING OF INLINE: 197 */ @@ -1683,13 +1667,13 @@ ZL2_197:; goto ZL2_197; /* END OF INLINE: 197 */ } - /* UNREACHED */ + /*UNREACHED*/ case (TOK_STAR): { ADVANCE_LEXER; /* BEGINNING OF ACTION: op-star */ { -#line 527 "src/lx/parser.act" +#line 526 "src/lx/parser.act" fsm_state_t start, end; fsm_state_t old; @@ -1739,7 +1723,7 @@ ZL2_197:; fsm_setstart((ZIq), start); -#line 1743 "src/lx/parser.c" +#line 1727 "src/lx/parser.c" } /* END OF ACTION: op-star */ /* BEGINNING OF INLINE: 197 */ @@ -1747,14 +1731,14 @@ ZL2_197:; goto ZL2_197; /* END OF INLINE: 197 */ } - /* UNREACHED */ + /*UNREACHED*/ default: goto ZL1; } } /* END OF INLINE: 272 */ } - /* UNREACHED */ + /*UNREACHED*/ default: { ZI196 = ZI191; @@ -1812,7 +1796,7 @@ p_204(lex_state lex_state, act_state act_state, zone *ZIz, fsm *ZI202, fsm *ZOq) } /* BEGINNING OF ACTION: op-subtract */ { -#line 711 "src/lx/parser.act" +#line 704 "src/lx/parser.act" assert((*ZI202) != NULL); assert((ZIb) != NULL); @@ -1823,7 +1807,7 @@ p_204(lex_state lex_state, act_state act_state, zone *ZIz, fsm *ZI202, fsm *ZOq) goto ZL1; } -#line 1827 "src/lx/parser.c" +#line 1811 "src/lx/parser.c" } /* END OF ACTION: op-subtract */ } @@ -1887,7 +1871,7 @@ p_208(lex_state lex_state, act_state act_state, zone *ZIz, fsm *ZI206, fsm *ZOq) } /* BEGINNING OF ACTION: op-concat */ { -#line 694 "src/lx/parser.act" +#line 687 "src/lx/parser.act" assert((*ZI206) != NULL); assert((ZIb) != NULL); @@ -1898,7 +1882,7 @@ p_208(lex_state lex_state, act_state act_state, zone *ZIz, fsm *ZI206, fsm *ZOq) goto ZL1; } -#line 1902 "src/lx/parser.c" +#line 1886 "src/lx/parser.c" } /* END OF ACTION: op-concat */ } @@ -1937,13 +1921,13 @@ p_212(lex_state lex_state, act_state act_state, zone *ZIz, fsm *ZI210, fsm *ZOq) } /* BEGINNING OF ACTION: op-product */ { -#line 705 "src/lx/parser.act" +#line 699 "src/lx/parser.act" fprintf(stderr, "unimplemented\n"); (ZIq) = NULL; goto ZL1; -#line 1947 "src/lx/parser.c" +#line 1931 "src/lx/parser.c" } /* END OF ACTION: op-product */ } @@ -1977,7 +1961,7 @@ p_215(lex_state lex_state, act_state act_state, fsm *ZOr) /* BEGINNING OF EXTRACT: RE */ { -#line 240 "src/lx/parser.act" +#line 237 "src/lx/parser.act" assert(lex_state->buf.a[0] == '/'); @@ -1991,13 +1975,13 @@ p_215(lex_state lex_state, act_state act_state, fsm *ZOr) ZIf |= RE_ANCHORED; /* regexps in lx are implicitly anchored */ ZIf |= RE_SINGLE; /* we can't assume we're lexing text */ -#line 1995 "src/lx/parser.c" +#line 1979 "src/lx/parser.c" } /* END OF EXTRACT: RE */ ADVANCE_LEXER; /* BEGINNING OF ACTION: pattern-buffer */ { -#line 261 "src/lx/parser.act" +#line 264 "src/lx/parser.act" size_t len; @@ -2022,12 +2006,12 @@ p_215(lex_state lex_state, act_state act_state, fsm *ZOr) lex_state->p = lex_state->a; -#line 2026 "src/lx/parser.c" +#line 2010 "src/lx/parser.c" } /* END OF ACTION: pattern-buffer */ /* BEGINNING OF ACTION: compile-regex */ { -#line 385 "src/lx/parser.act" +#line 380 "src/lx/parser.act" struct re_err err; @@ -2042,16 +2026,16 @@ p_215(lex_state lex_state, act_state act_state, fsm *ZOr) exit(EXIT_FAILURE); } -#line 2046 "src/lx/parser.c" +#line 2030 "src/lx/parser.c" } /* END OF ACTION: compile-regex */ /* BEGINNING OF ACTION: free-arr */ { -#line 774 "src/lx/parser.act" +#line 767 "src/lx/parser.act" free((ZIa)); -#line 2055 "src/lx/parser.c" +#line 2039 "src/lx/parser.c" } /* END OF ACTION: free-arr */ } @@ -2063,7 +2047,7 @@ p_215(lex_state lex_state, act_state act_state, fsm *ZOr) ADVANCE_LEXER; /* BEGINNING OF ACTION: pattern-buffer */ { -#line 261 "src/lx/parser.act" +#line 264 "src/lx/parser.act" size_t len; @@ -2088,12 +2072,12 @@ p_215(lex_state lex_state, act_state act_state, fsm *ZOr) lex_state->p = lex_state->a; -#line 2092 "src/lx/parser.c" +#line 2076 "src/lx/parser.c" } /* END OF ACTION: pattern-buffer */ /* BEGINNING OF ACTION: compile-literal */ { -#line 370 "src/lx/parser.act" +#line 365 "src/lx/parser.act" struct re_err err; @@ -2108,16 +2092,16 @@ p_215(lex_state lex_state, act_state act_state, fsm *ZOr) exit(EXIT_FAILURE); } -#line 2112 "src/lx/parser.c" +#line 2096 "src/lx/parser.c" } /* END OF ACTION: compile-literal */ /* BEGINNING OF ACTION: free-arr */ { -#line 774 "src/lx/parser.act" +#line 767 "src/lx/parser.act" free((ZIa)); -#line 2121 "src/lx/parser.c" +#line 2105 "src/lx/parser.c" } /* END OF ACTION: free-arr */ } @@ -2181,7 +2165,7 @@ ZL2_list_Hof_Hthings_C_Czone_Hthing_C_Clist_Hof_Hzone_Hfrom_Hmappings_C_Clist_Ho } /* BEGINNING OF ACTION: subtract-exit */ { -#line 744 "src/lx/parser.act" +#line 737 "src/lx/parser.act" assert((ZIr) != NULL); @@ -2201,12 +2185,12 @@ ZL2_list_Hof_Hthings_C_Czone_Hthing_C_Clist_Hof_Hzone_Hfrom_Hmappings_C_Clist_Ho } } -#line 2205 "src/lx/parser.c" +#line 2189 "src/lx/parser.c" } /* END OF ACTION: subtract-exit */ /* BEGINNING OF ACTION: add-mapping */ { -#line 458 "src/lx/parser.act" +#line 454 "src/lx/parser.act" struct ast_token *t; struct ast_mapping *m; @@ -2239,14 +2223,14 @@ ZL2_list_Hof_Hthings_C_Czone_Hthing_C_Clist_Hof_Hzone_Hfrom_Hmappings_C_Clist_Ho nmappings++; } -#line 2243 "src/lx/parser.c" +#line 2227 "src/lx/parser.c" } /* END OF ACTION: add-mapping */ /* BEGINNING OF INLINE: list-of-things::zone-thing::list-of-zone-from-mappings::list-of-zone-from-mappings-x */ goto ZL2_list_Hof_Hthings_C_Czone_Hthing_C_Clist_Hof_Hzone_Hfrom_Hmappings_C_Clist_Hof_Hzone_Hfrom_Hmappings_Hx; /* END OF INLINE: list-of-things::zone-thing::list-of-zone-from-mappings::list-of-zone-from-mappings-x */ } - /* UNREACHED */ + /*UNREACHED*/ case (ERROR_TERMINAL): return; default: @@ -2273,16 +2257,16 @@ p_lx(lex_state lex_state, act_state act_state, ast *ZOa) /* BEGINNING OF ACTION: no-zone */ { -#line 523 "src/lx/parser.act" +#line 516 "src/lx/parser.act" (ZIparent) = NULL; -#line 2281 "src/lx/parser.c" +#line 2265 "src/lx/parser.c" } /* END OF ACTION: no-zone */ /* BEGINNING OF ACTION: make-ast */ { -#line 432 "src/lx/parser.act" +#line 425 "src/lx/parser.act" (ZIa) = ast_new(); if ((ZIa) == NULL) { @@ -2290,12 +2274,12 @@ p_lx(lex_state lex_state, act_state act_state, ast *ZOa) goto ZL1; } -#line 2294 "src/lx/parser.c" +#line 2278 "src/lx/parser.c" } /* END OF ACTION: make-ast */ /* BEGINNING OF ACTION: make-zone */ { -#line 440 "src/lx/parser.act" +#line 433 "src/lx/parser.act" assert((ZIa) != NULL); @@ -2313,28 +2297,28 @@ p_lx(lex_state lex_state, act_state act_state, ast *ZOa) goto ZL1; } -#line 2317 "src/lx/parser.c" +#line 2301 "src/lx/parser.c" } /* END OF ACTION: make-zone */ /* BEGINNING OF ACTION: no-exit */ { -#line 519 "src/lx/parser.act" +#line 512 "src/lx/parser.act" (ZIexit) = NULL; -#line 2326 "src/lx/parser.c" +#line 2310 "src/lx/parser.c" } /* END OF ACTION: no-exit */ /* BEGINNING OF ACTION: set-globalzone */ { -#line 508 "src/lx/parser.act" +#line 501 "src/lx/parser.act" assert((ZIa) != NULL); assert((ZIz) != NULL); (ZIa)->global = (ZIz); -#line 2338 "src/lx/parser.c" +#line 2322 "src/lx/parser.c" } /* END OF ACTION: set-globalzone */ p_list_Hof_Hthings (lex_state, act_state, ZIa, ZIz, ZIexit); @@ -2358,11 +2342,11 @@ p_lx(lex_state lex_state, act_state act_state, ast *ZOa) { /* BEGINNING OF ACTION: err-expected-eof */ { -#line 815 "src/lx/parser.act" +#line 809 "src/lx/parser.act" err_expected(lex_state, "EOF"); -#line 2366 "src/lx/parser.c" +#line 2350 "src/lx/parser.c" } /* END OF ACTION: err-expected-eof */ } @@ -2375,7 +2359,7 @@ ZL1:; { /* BEGINNING OF ACTION: make-ast */ { -#line 432 "src/lx/parser.act" +#line 425 "src/lx/parser.act" (ZIa) = ast_new(); if ((ZIa) == NULL) { @@ -2383,17 +2367,17 @@ ZL1:; goto ZL4; } -#line 2387 "src/lx/parser.c" +#line 2371 "src/lx/parser.c" } /* END OF ACTION: make-ast */ /* BEGINNING OF ACTION: err-syntax */ { -#line 782 "src/lx/parser.act" +#line 777 "src/lx/parser.act" err(lex_state, "Syntax error"); exit(EXIT_FAILURE); -#line 2397 "src/lx/parser.c" +#line 2381 "src/lx/parser.c" } /* END OF ACTION: err-syntax */ } @@ -2450,7 +2434,7 @@ p_list_Hof_Hthings_C_Czone_Hthing_C_Czone_Hto_Hmapping(lex_state lex_state, act_ } /* BEGINNING OF ACTION: add-mapping */ { -#line 458 "src/lx/parser.act" +#line 454 "src/lx/parser.act" struct ast_token *t; struct ast_mapping *m; @@ -2483,12 +2467,12 @@ p_list_Hof_Hthings_C_Czone_Hthing_C_Czone_Hto_Hmapping(lex_state lex_state, act_ nmappings++; } -#line 2487 "src/lx/parser.c" +#line 2471 "src/lx/parser.c" } /* END OF ACTION: add-mapping */ /* BEGINNING OF ACTION: clone */ { -#line 764 "src/lx/parser.act" +#line 757 "src/lx/parser.act" assert((ZIr) != NULL); @@ -2498,7 +2482,7 @@ p_list_Hof_Hthings_C_Czone_Hthing_C_Czone_Hto_Hmapping(lex_state lex_state, act_ goto ZL1; } -#line 2502 "src/lx/parser.c" +#line 2486 "src/lx/parser.c" } /* END OF ACTION: clone */ } @@ -2534,11 +2518,11 @@ p_112(lex_state lex_state, act_state act_state, string *ZOt) { /* BEGINNING OF ACTION: err-expected-map */ { -#line 791 "src/lx/parser.act" +#line 785 "src/lx/parser.act" err_expected(lex_state, "'->'"); -#line 2542 "src/lx/parser.c" +#line 2526 "src/lx/parser.c" } /* END OF ACTION: err-expected-map */ } @@ -2549,16 +2533,12 @@ p_112(lex_state lex_state, act_state act_state, string *ZOt) case (TOK_TOKEN): /* BEGINNING OF EXTRACT: TOKEN */ { -#line 223 "src/lx/parser.act" +#line 225 "src/lx/parser.act" /* TODO: submatch addressing */ ZIt = xstrdup(lex_state->buf.a + 1); /* +1 for '$' prefix */ - if (ZIt == NULL) { - perror("xstrdup"); - exit(EXIT_FAILURE); - } -#line 2562 "src/lx/parser.c" +#line 2542 "src/lx/parser.c" } /* END OF EXTRACT: TOKEN */ break; @@ -2572,11 +2552,11 @@ p_112(lex_state lex_state, act_state act_state, string *ZOt) { /* BEGINNING OF ACTION: no-token */ { -#line 515 "src/lx/parser.act" +#line 508 "src/lx/parser.act" (ZIt) = NULL; -#line 2580 "src/lx/parser.c" +#line 2560 "src/lx/parser.c" } /* END OF ACTION: no-token */ } @@ -2665,11 +2645,11 @@ ZL1:; { /* BEGINNING OF ACTION: err-expected-semi */ { -#line 799 "src/lx/parser.act" +#line 793 "src/lx/parser.act" err_expected(lex_state, "';'"); -#line 2673 "src/lx/parser.c" +#line 2653 "src/lx/parser.c" } /* END OF ACTION: err-expected-semi */ } @@ -2716,16 +2696,16 @@ p_251(lex_state lex_state, act_state act_state, ast *ZIa, zone *ZIz, fsm *ZIexit } /* BEGINNING OF ACTION: no-zone */ { -#line 523 "src/lx/parser.act" +#line 516 "src/lx/parser.act" (ZIto) = NULL; -#line 2724 "src/lx/parser.c" +#line 2704 "src/lx/parser.c" } /* END OF ACTION: no-zone */ /* BEGINNING OF ACTION: add-mapping */ { -#line 458 "src/lx/parser.act" +#line 454 "src/lx/parser.act" struct ast_token *t; struct ast_mapping *m; @@ -2758,7 +2738,7 @@ p_251(lex_state lex_state, act_state act_state, ast *ZIa, zone *ZIz, fsm *ZIexit nmappings++; } -#line 2762 "src/lx/parser.c" +#line 2742 "src/lx/parser.c" } /* END OF ACTION: add-mapping */ } @@ -2770,7 +2750,7 @@ p_251(lex_state lex_state, act_state act_state, ast *ZIa, zone *ZIz, fsm *ZIexit /* BEGINNING OF ACTION: make-zone */ { -#line 440 "src/lx/parser.act" +#line 433 "src/lx/parser.act" assert((*ZIa) != NULL); @@ -2788,12 +2768,12 @@ p_251(lex_state lex_state, act_state act_state, ast *ZIa, zone *ZIz, fsm *ZIexit goto ZL1; } -#line 2792 "src/lx/parser.c" +#line 2772 "src/lx/parser.c" } /* END OF ACTION: make-zone */ /* BEGINNING OF ACTION: add-mapping */ { -#line 458 "src/lx/parser.act" +#line 454 "src/lx/parser.act" struct ast_token *t; struct ast_mapping *m; @@ -2826,7 +2806,7 @@ p_251(lex_state lex_state, act_state act_state, ast *ZIa, zone *ZIz, fsm *ZIexit nmappings++; } -#line 2830 "src/lx/parser.c" +#line 2810 "src/lx/parser.c" } /* END OF ACTION: add-mapping */ p_list_Hof_Hthings_C_Czone_Hthing_C_Clist_Hof_Hzone_Hfrom_Hmappings_C_Clist_Hof_Hzone_Hfrom_Hmappings_Hx (lex_state, act_state, *ZIa, *ZIz, ZIchild, *ZIexit); @@ -2850,11 +2830,11 @@ p_251(lex_state lex_state, act_state act_state, ast *ZIa, zone *ZIz, fsm *ZIexit { /* BEGINNING OF ACTION: err-expected-to */ { -#line 803 "src/lx/parser.act" +#line 797 "src/lx/parser.act" err_expected(lex_state, "'..'"); -#line 2858 "src/lx/parser.c" +#line 2838 "src/lx/parser.c" } /* END OF ACTION: err-expected-to */ } @@ -2879,25 +2859,25 @@ p_251(lex_state lex_state, act_state act_state, ast *ZIa, zone *ZIz, fsm *ZIexit } /* BEGINNING OF ACTION: no-zone */ { -#line 523 "src/lx/parser.act" +#line 516 "src/lx/parser.act" (ZIx) = NULL; -#line 2887 "src/lx/parser.c" +#line 2867 "src/lx/parser.c" } /* END OF ACTION: no-zone */ /* BEGINNING OF ACTION: no-token */ { -#line 515 "src/lx/parser.act" +#line 508 "src/lx/parser.act" (ZIy) = NULL; -#line 2896 "src/lx/parser.c" +#line 2876 "src/lx/parser.c" } /* END OF ACTION: no-token */ /* BEGINNING OF ACTION: regex-any */ { -#line 401 "src/lx/parser.act" +#line 396 "src/lx/parser.act" fsm_state_t start, end; @@ -2928,12 +2908,12 @@ p_251(lex_state lex_state, act_state act_state, ast *ZIa, zone *ZIz, fsm *ZIexit fsm_setstart((ZIw), start); fsm_setend((ZIw), end, 1); -#line 2932 "src/lx/parser.c" +#line 2912 "src/lx/parser.c" } /* END OF ACTION: regex-any */ /* BEGINNING OF ACTION: subtract-exit */ { -#line 744 "src/lx/parser.act" +#line 737 "src/lx/parser.act" assert((ZIw) != NULL); @@ -2953,12 +2933,12 @@ p_251(lex_state lex_state, act_state act_state, ast *ZIa, zone *ZIz, fsm *ZIexit } } -#line 2957 "src/lx/parser.c" +#line 2937 "src/lx/parser.c" } /* END OF ACTION: subtract-exit */ /* BEGINNING OF ACTION: add-mapping */ { -#line 458 "src/lx/parser.act" +#line 454 "src/lx/parser.act" struct ast_token *t; struct ast_mapping *m; @@ -2991,7 +2971,7 @@ p_251(lex_state lex_state, act_state act_state, ast *ZIa, zone *ZIz, fsm *ZIexit nmappings++; } -#line 2995 "src/lx/parser.c" +#line 2975 "src/lx/parser.c" } /* END OF ACTION: add-mapping */ } @@ -3018,11 +2998,11 @@ p_251(lex_state lex_state, act_state act_state, ast *ZIa, zone *ZIz, fsm *ZIexit { /* BEGINNING OF ACTION: err-expected-list */ { -#line 823 "src/lx/parser.act" +#line 817 "src/lx/parser.act" err_expected(lex_state, "list of mappings, bindings or zones"); -#line 3026 "src/lx/parser.c" +#line 3006 "src/lx/parser.c" } /* END OF ACTION: err-expected-list */ } @@ -3038,16 +3018,16 @@ p_251(lex_state lex_state, act_state act_state, ast *ZIa, zone *ZIz, fsm *ZIexit /* BEGINNING OF ACTION: no-exit */ { -#line 519 "src/lx/parser.act" +#line 512 "src/lx/parser.act" (ZIr2) = NULL; -#line 3046 "src/lx/parser.c" +#line 3026 "src/lx/parser.c" } /* END OF ACTION: no-exit */ /* BEGINNING OF ACTION: make-zone */ { -#line 440 "src/lx/parser.act" +#line 433 "src/lx/parser.act" assert((*ZIa) != NULL); @@ -3065,12 +3045,12 @@ p_251(lex_state lex_state, act_state act_state, ast *ZIa, zone *ZIz, fsm *ZIexit goto ZL1; } -#line 3069 "src/lx/parser.c" +#line 3049 "src/lx/parser.c" } /* END OF ACTION: make-zone */ /* BEGINNING OF ACTION: add-mapping */ { -#line 458 "src/lx/parser.act" +#line 454 "src/lx/parser.act" struct ast_token *t; struct ast_mapping *m; @@ -3103,7 +3083,7 @@ p_251(lex_state lex_state, act_state act_state, ast *ZIa, zone *ZIz, fsm *ZIexit nmappings++; } -#line 3107 "src/lx/parser.c" +#line 3087 "src/lx/parser.c" } /* END OF ACTION: add-mapping */ /* BEGINNING OF INLINE: 131 */ @@ -3122,11 +3102,11 @@ p_251(lex_state lex_state, act_state act_state, ast *ZIa, zone *ZIz, fsm *ZIexit { /* BEGINNING OF ACTION: err-expected-list */ { -#line 823 "src/lx/parser.act" +#line 817 "src/lx/parser.act" err_expected(lex_state, "list of mappings, bindings or zones"); -#line 3130 "src/lx/parser.c" +#line 3110 "src/lx/parser.c" } /* END OF ACTION: err-expected-list */ } @@ -3170,11 +3150,11 @@ p_252(lex_state lex_state, act_state act_state, ast *ZIa, zone *ZIz, fsm *ZIexit { /* BEGINNING OF ACTION: err-expected-bind */ { -#line 795 "src/lx/parser.act" +#line 789 "src/lx/parser.act" err_expected(lex_state, "'='"); -#line 3178 "src/lx/parser.c" +#line 3158 "src/lx/parser.c" } /* END OF ACTION: err-expected-bind */ } @@ -3189,7 +3169,7 @@ p_252(lex_state lex_state, act_state act_state, ast *ZIa, zone *ZIz, fsm *ZIexit } /* BEGINNING OF ACTION: add-binding */ { -#line 491 "src/lx/parser.act" +#line 486 "src/lx/parser.act" struct var *v; @@ -3206,7 +3186,7 @@ p_252(lex_state lex_state, act_state act_state, ast *ZIa, zone *ZIz, fsm *ZIexit goto ZL1; } -#line 3210 "src/lx/parser.c" +#line 3190 "src/lx/parser.c" } /* END OF ACTION: add-binding */ } @@ -3232,7 +3212,7 @@ p_252(lex_state lex_state, act_state act_state, ast *ZIa, zone *ZIz, fsm *ZIexit /* BEGINNING OF ACTION: deref-var */ { -#line 286 "src/lx/parser.act" +#line 281 "src/lx/parser.act" struct ast_zone *z; @@ -3259,7 +3239,7 @@ p_252(lex_state lex_state, act_state act_state, ast *ZIa, zone *ZIz, fsm *ZIexit goto ZL1; } -#line 3263 "src/lx/parser.c" +#line 3243 "src/lx/parser.c" } /* END OF ACTION: deref-var */ p_197 (lex_state, act_state, ZI273, &ZI210); @@ -3275,7 +3255,7 @@ p_252(lex_state lex_state, act_state act_state, ast *ZIa, zone *ZIz, fsm *ZIexit } /* BEGINNING OF ACTION: subtract-exit */ { -#line 744 "src/lx/parser.act" +#line 737 "src/lx/parser.act" assert((ZI278) != NULL); @@ -3295,7 +3275,7 @@ p_252(lex_state lex_state, act_state act_state, ast *ZIa, zone *ZIz, fsm *ZIexit } } -#line 3299 "src/lx/parser.c" +#line 3279 "src/lx/parser.c" } /* END OF ACTION: subtract-exit */ p_251 (lex_state, act_state, ZIa, ZIz, ZIexit, &ZI279, &ZI280); @@ -3318,7 +3298,7 @@ ZL1:; /* BEGINNING OF TRAILER */ -#line 827 "src/lx/parser.act" +#line 881 "src/lx/parser.act" struct ast *lx_parse(FILE *f, const struct fsm_options *opt) { @@ -3381,6 +3361,6 @@ ZL1:; return ast; } -#line 3385 "src/lx/parser.c" +#line 3365 "src/lx/parser.c" /* END OF FILE */ diff --git a/src/lx/parser.h b/src/lx/parser.h index bde7c36ab..970fe2b0e 100644 --- a/src/lx/parser.h +++ b/src/lx/parser.h @@ -9,7 +9,7 @@ /* BEGINNING OF HEADER */ -#line 128 "src/lx/parser.act" +#line 140 "src/lx/parser.act" #include @@ -29,7 +29,7 @@ extern void p_lx(lex_state, act_state, ast *); /* BEGINNING OF TRAILER */ -#line 889 "src/lx/parser.act" +#line 883 "src/lx/parser.act" #line 36 "src/lx/parser.h" diff --git a/src/retest/cvtpcre.c b/src/retest/cvtpcre.c index 4bcd6e63a..633431f7d 100644 --- a/src/retest/cvtpcre.c +++ b/src/retest/cvtpcre.c @@ -263,10 +263,6 @@ parse_modifiers(size_t linenum, const char *s, enum re_flags *mods_p) assert(s != NULL); buf = xstrdup(s); - if (buf == NULL) { - return 0; - } - pos = tok = buf; first = true; From 825a6218314c1afcf7aa63267ca070a37e80bf4b Mon Sep 17 00:00:00 2001 From: Kate F Date: Fri, 31 May 2024 08:09:21 -0700 Subject: [PATCH 4/4] No need to depend on POSIX here. --- src/adt/xalloc.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/adt/xalloc.c b/src/adt/xalloc.c index bdce10a49..91ee82431 100644 --- a/src/adt/xalloc.c +++ b/src/adt/xalloc.c @@ -4,8 +4,6 @@ * See LICENCE for the full copyright terms. */ -#define _POSIX_C_SOURCE 200809L - #include #include #include @@ -29,13 +27,14 @@ xstrdup(const char *s) char * xstrndup(const char *s, size_t n) { - char *new = strndup(s, n); + char *new; + + new = malloc(n); if (new == NULL) { - perror("strndup"); - abort(); + return NULL; } - return new; + return memcpy(new, s, n); } void *