[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Dereferencing null ptr yylloc in pure push parser

From: Egor Pugin
Subject: Dereferencing null ptr yylloc in pure push parser
Date: Sun, 15 Nov 2015 14:36:12 +0300


I'm using pure+push parser, bison v3.0.4.
%define api.pure full
%define api.push-pull push

The parse function signature is:
yypush_parse (yypstate *yyps, int yypushed_char, YYSTYPE const
*yypushed_val, YYLTYPE *yypushed_loc)

When I call it like (I don't need yylloc in this case):
ret = yypush_parse(ps, t->token, &yylval, nullptr);
(C++11 nullptr), it tries to dereference null pointer in line:

YYDPRINTF ((stderr, "Starting parse\n"));

  yystate = 0;
  yyerrstatus = 0;
  yynerrs = 0;
  yychar = YYEMPTY; /* Cause a token to be read.  */
  yylsp[0] = *yypushed_loc;   // <- DEREFERENCE NULL POINTER
  goto yysetstate;

Before this line there is declaration of default yylloc:
YYLTYPE yylloc = yyloc_default;

After null dereferencing there is such code:
YYDPRINTF ((stderr, "Reading a token: "));
      yychar = yypushed_char;
      if (yypushed_val)
        yylval = *yypushed_val;
      if (yypushed_loc)
        yylloc = *yypushed_loc;

It seems in my case assignment should be checked as when reading a token.

In the bison sources I found line (yacc.c):
b4_locations_if([[  yylsp[0] =
]b4_push_if([b4_pure_if([*])yypushed_loc], [yylloc])[;
[  goto yysetstate;

Probably the issue is here.

Is this a bug or it is intended?
For workaround I'll use dummy not null yylloc.

Egor Pugin

reply via email to

[Prev in Thread] Current Thread [Next in Thread]