From 4bde5d0d933efc21f63e4783b631c41ca3de1495 Mon Sep 17 00:00:00 2001 From: Clemens Paumgarten <clemenspaumgarten@gmail.com> Date: Thu, 6 Jun 2019 18:00:00 +0200 Subject: [PATCH] test --- src/scanner.l | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/scanner.l b/src/scanner.l index c7941d5..4a55e16 100644 --- a/src/scanner.l +++ b/src/scanner.l @@ -122,12 +122,13 @@ identifier [a-zA-Z_][a-zA-Z0-9_]* {float_literal} { yylval->TK_FLOAT_LITERAL = atof(yytext); return TK_FLOAT_LITERAL; } {string_literal} { /* https://stackoverflow.com/questions/14185172/lex-how-to-eliminate-double-quotes-from-a-string-literal */ - char* str = (char*)malloc(strlen(yytext)); - strcpy(str, "\\"); - strncpy(str, yytext, yyleng-1); - str[yyleng+2] = '\0'; - yylval->TK_STRING_LITERAL = str; - return TK_STRING_LITERAL; } + char* str = malloc(sizeof(char) * yyleng+3); + strcpy(str, "\\"); + strncpy(str+1, yytext, yyleng-1); + strcpy(str+yyleng, "\\\""); + str[yyleng+2] = '\0'; + yylval->TK_STRING_LITERAL = str; + return TK_STRING_LITERAL; } -- GitLab