mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
examples: don't promote unchecked function calls
* etc/bench.pl.in, examples/c/bistromathic/parse.y, * examples/c/calc/calc.y, examples/c/pushcalc/calc.y: Check scanf's return value. * doc/bison.texi: Likewise, but only for the second example, to avoid cluttering the very simple case.
This commit is contained in:
@@ -268,7 +268,8 @@ yylex (const char **line, YYSTYPE *yylval, YYLTYPE *yylloc)
|
||||
case '5': case '6': case '7': case '8': case '9':
|
||||
{
|
||||
int nchars = 0;
|
||||
sscanf (*line - 1, "%lf%n", &yylval->TOK_NUM, &nchars);
|
||||
int n = sscanf (*line - 1, "%lf%n", &yylval->TOK_NUM, &nchars);
|
||||
assert (n == 1);
|
||||
*line += nchars - 1;
|
||||
yylloc->last_column += nchars - 1;
|
||||
return TOK_NUM;
|
||||
@@ -284,7 +285,8 @@ yylex (const char **line, YYSTYPE *yylval, YYLTYPE *yylloc)
|
||||
{
|
||||
int nchars = 0;
|
||||
char buf[100];
|
||||
sscanf (*line - 1, "%99[a-z]%n", buf, &nchars);
|
||||
int n = sscanf (*line - 1, "%99[a-z]%n", buf, &nchars);
|
||||
assert (n == 1);
|
||||
*line += nchars - 1;
|
||||
yylloc->last_column += nchars - 1;
|
||||
if (strcmp (buf, "exit") == 0)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
%code top {
|
||||
#include <assert.h>
|
||||
#include <ctype.h> /* isdigit. */
|
||||
#include <stdio.h> /* For printf, etc. */
|
||||
#include <string.h> /* strcmp. */
|
||||
@@ -73,7 +74,8 @@ yylex (void)
|
||||
if (c == '.' || isdigit (c))
|
||||
{
|
||||
ungetc (c, stdin);
|
||||
scanf ("%lf", &yylval.NUM);
|
||||
int n = scanf ("%lf", &yylval.NUM);
|
||||
assert (n == 1);
|
||||
return NUM;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
%code top {
|
||||
#include <assert.h>
|
||||
#include <ctype.h> /* isdigit. */
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h> /* For printf, etc. */
|
||||
#include <string.h> /* strcmp. */
|
||||
}
|
||||
@@ -81,7 +81,8 @@ yylex (YYSTYPE *yylval)
|
||||
if (c == '.' || isdigit (c))
|
||||
{
|
||||
ungetc (c, stdin);
|
||||
scanf ("%lf", &yylval->NUM);
|
||||
int n = scanf ("%lf", &yylval->NUM);
|
||||
assert (n == 1);
|
||||
return NUM;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user