mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-14 23:03:04 +00:00
Simplify mfcalc error handling
* 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.
This commit is contained in:
@@ -2662,19 +2662,21 @@ found, a pointer to that symbol is returned; otherwise zero is returned.
|
|||||||
|
|
||||||
@comment file: mfcalc.y: 3
|
@comment file: mfcalc.y: 3
|
||||||
@example
|
@example
|
||||||
#include <stdlib.h> /* 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 <stdlib.h> /* malloc, realloc. */
|
||||||
#include <string.h> /* strlen. */
|
#include <string.h> /* strlen. */
|
||||||
|
@end group
|
||||||
|
|
||||||
@group
|
@group
|
||||||
symrec *
|
symrec *
|
||||||
putsym (char const *name, int sym_type)
|
putsym (char const *name, int sym_type)
|
||||||
@{
|
@{
|
||||||
symrec *res = (symrec *) malloc (sizeof (symrec));
|
symrec *res = (symrec *) malloc (sizeof (symrec));
|
||||||
if (!res)
|
|
||||||
abort ();
|
|
||||||
res->name = strdup (name);
|
res->name = strdup (name);
|
||||||
if (!res->name)
|
|
||||||
abort ();
|
|
||||||
res->type = sym_type;
|
res->type = sym_type;
|
||||||
res->value.var = 0; /* Set value to 0 even if fun. */
|
res->value.var = 0; /* Set value to 0 even if fun. */
|
||||||
res->next = sym_table;
|
res->next = sym_table;
|
||||||
@@ -2717,7 +2719,6 @@ operators in @code{yylex}.
|
|||||||
@example
|
@example
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
@group
|
@group
|
||||||
int
|
int
|
||||||
@@ -2764,15 +2765,8 @@ Bison generated a definition of @code{YYSTYPE} with a member named
|
|||||||
/* If buffer is full, make it bigger. */
|
/* If buffer is full, make it bigger. */
|
||||||
if (bufsize <= i)
|
if (bufsize <= i)
|
||||||
@{
|
@{
|
||||||
ptrdiff_t maxsize
|
|
||||||
= (PTRDIFF_MAX < SIZE_MAX
|
|
||||||
? PTRDIFF_MAX : SIZE_MAX);
|
|
||||||
if ((maxsize - 40) / 2 < bufsize)
|
|
||||||
abort ();
|
|
||||||
bufsize = 2 * bufsize + 40;
|
bufsize = 2 * bufsize + 40;
|
||||||
symbuf = realloc (symbuf, bufsize);
|
symbuf = realloc (symbuf, bufsize);
|
||||||
if (!symbuf)
|
|
||||||
abort ();
|
|
||||||
@}
|
@}
|
||||||
/* Add this character to the buffer. */
|
/* Add this character to the buffer. */
|
||||||
symbuf[i++] = c;
|
symbuf[i++] = c;
|
||||||
|
|||||||
Reference in New Issue
Block a user