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