1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
ONLY(!) if you want to check bound overflows with EMX/GCC 2.7.2.1 you
have to change some lines within yaccsrc.c. (or the skeleton file bison.simple
if you really know what you are doing).
If you are using checker (together with gcc -fcheck-memory-usage) look at
the end of this file.
Reason: The skeleton file will produce a bounds checking error. This is NOT
a real error. The code uses initially a pointer to the first element BEFORE
an array; the pointer will be incremented before the first use. This is a
problem for the bounds checker. It detects an illegal pointer al the
initialization and sets the value of the pointer to invalid (-1) the first
assignment crashes the program.
You will see here the patches in the function yyparse. First, look at the
code near the beginning of the function and apply the following changes:
Original:
> yystate = 0;
> yyerrstatus = 0;
> yynerrs = 0;
> yychar = YYEMPTY; /* Cause a token to be read. */
>
> /* Initialize stack pointers.
> Waste one element of value and location stack
> so that they stay on the same level as the state stack.
> The wasted elements are never initialized. */
>
> yyssp = yyss - 1;
> yyvsp = yyvs;
>#ifdef YYLSP_NEEDED
> yylsp = yyls;
>#endif
>
>/* Push a new state, which is found in yystate . */
>/* In all cases, when you get here, the value and location stacks
> have just been pushed. so pushing a state here evens the stacks. */
>yynewstate:
>
> *++yyssp = yystate;
>
> if (yyssp >= yyss + yystacksize - 1)
New:
> yystate = 0;
> yyerrstatus = 0;
> yynerrs = 0;
> yychar = YYEMPTY; /* Cause a token to be read. */
>
> /* Initialize stack pointers.
> Waste one element of value and location stack
> so that they stay on the same level as the state stack.
> The wasted elements are never initialized. */
>
> yyssp = yyss; /* FGC: allow -fbounds-checking */
> yyvsp = yyvs;
>#ifdef YYLSP_NEEDED
> yylsp = yyls;
>#endif
>
> goto yyfirststart;
>
>/* Push a new state, which is found in yystate . */
>/* In all cases, when you get here, the value and location stacks
> have just been pushed. so pushing a state here evens the stacks. */
>yynewstate:
>
> ++yyssp; /* FGC */
>yyfirststart: /* FGC */
> *yyssp = (short) yystate; /* FGC */
>
> if (yyssp >= yyss + yystacksize - 1)
Now, look at the end of yyparse.
Original:
>#if YYDEBUG != 0
> if (yydebug)
> {
> short *ssp1 = yyss - 1;
> fprintf (stderr, "state stack now");
> while (ssp1 != yyssp)
> fprintf (stderr, " %d", *++ssp1);
> fprintf (stderr, "\n");
> }
>#endif
New:
>#if YYDEBUG != 0
> if (yydebug)
> {
> short *ssp1 = yyss; /* FGC */
> fprintf (stderr, "state stack now");
> while (ssp1 != yyssp)
> fprintf (stderr, " %d", *++ssp1);
> fprintf (stderr, "\n");
> }
>#endif
NEVER use this code in a delevopement environment. There may be some
problems with it, I never checked the changes in all conditions. Let's wait
for the bison gurus to fix these problems by themselves.
------------ THE FOLLOW CHANGES SHOULD BE APPLIED FOR CHECKER ONLY -------------
Look at the beginning of yyparse and replace
> YYSTYPE yyval; /* the variable used to return */
with
> YYSTYPE yyval = 0; /* the variable used to return */
Furthermore, initialize yyvsa[0], e.g. add the line
> yyvsa[0] = 0;
after the line
> yychar = YYEMPTY;
That's OK in all circumstances and may be applied without any risk.
|