>From e356c1ca5759e5f4336842483b550cbd6a566b5d Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 3 Oct 2019 11:15:02 -0700 Subject: [PATCH 1/2] Simplify mfcalc error handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * doc/bison.texi (Mfcalc Symbol Table, Mfcalc Lexer): Don’t abort on memory allocation failure or integer overflow. Instead, comment that these things aren’t checked for. --- doc/bison.texi | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/doc/bison.texi b/doc/bison.texi index 5545313d..a89142df 100644 --- a/doc/bison.texi +++ b/doc/bison.texi @@ -2662,19 +2662,21 @@ found, a pointer to that symbol is returned; otherwise zero is returned. @comment file: mfcalc.y: 3 @example -#include /* malloc, abort. */ +@group +/* The mfcalc code assumes that malloc and realloc + always succeed, and that integer calculations + never overflow. Production-quality code should + not make these assumptions. */ +#include /* malloc, realloc. */ #include /* strlen. */ +@end group @group symrec * putsym (char const *name, int sym_type) @{ symrec *res = (symrec *) malloc (sizeof (symrec)); - if (!res) - abort (); res->name = strdup (name); - if (!res->name) - abort (); res->type = sym_type; res->value.var = 0; /* Set value to 0 even if fun. */ res->next = sym_table; @@ -2717,7 +2719,6 @@ operators in @code{yylex}. @example #include #include -#include @group int @@ -2764,15 +2765,8 @@ Bison generated a definition of @code{YYSTYPE} with a member named /* If buffer is full, make it bigger. */ if (bufsize <= i) @{ - ptrdiff_t maxsize - = (PTRDIFF_MAX < SIZE_MAX - ? PTRDIFF_MAX : SIZE_MAX); - if ((maxsize - 40) / 2 < bufsize) - abort (); bufsize = 2 * bufsize + 40; symbuf = realloc (symbuf, bufsize); - if (!symbuf) - abort (); @} /* Add this character to the buffer. */ symbuf[i++] = c; -- 2.21.0