use yyfree/yyalloc during bytevector lex

This commit is contained in:
Yuichi Nishiwaki 2014-03-01 13:24:43 +09:00
parent 491fd81c97
commit 95dc14bac2
1 changed files with 4 additions and 2 deletions

View File

@ -151,15 +151,17 @@ infnan "+inf.0"|"-inf.0"|"+nan.0"|"-nan.0"
BEGIN(BYTEVECTOR); BEGIN(BYTEVECTOR);
yylval.blob.len = 0; yylval.blob.len = 0;
yylval.blob.capa = 10; yylval.blob.capa = 10;
yylval.blob.dat = calloc(10, 1); yylval.blob.dat = yyalloc(10, yyscanner);
} }
<BYTEVECTOR>[ \r\n\t] { <BYTEVECTOR>[ \r\n\t] {
/* skip whitespace */ /* skip whitespace */
} }
<BYTEVECTOR>{uinteger} { <BYTEVECTOR>{uinteger} {
int i = atoi(yytext); int i = atoi(yytext);
if (0 > i || i > 255) if (0 > i || i > 255) {
yyfree(yylval.blob.dat, yyscanner);
REJECT; REJECT;
}
yylval.blob.dat[yylval.blob.len++] = (char)i; yylval.blob.dat[yylval.blob.len++] = (char)i;
if (yylval.blob.len > yylval.blob.capa) { if (yylval.blob.len > yylval.blob.capa) {
yylval.blob.capa *= 2; yylval.blob.capa *= 2;