From b92c097b38f7cb6f222eefb6052951b6c42b969e Mon Sep 17 00:00:00 2001 From: Cas Cremers Date: Mon, 17 Dec 2012 20:51:42 +0100 Subject: [PATCH] BUGFIX: Windows version had a compilation problem. The use of 'strndup' in scanner.l caused problems for non-gnu modes of gcc, which was being invoked for the mingw32 compilation. Replaced now by the more portable strncpy + malloc version. --- src/scanner.l | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/scanner.l b/src/scanner.l index 5e77e3c..7fd1570 100644 --- a/src/scanner.l +++ b/src/scanner.l @@ -23,6 +23,7 @@ /* scanner for security protocols language */ #include +#include #include "pheading.h" #include "tac.h" #include "switches.h" @@ -180,19 +181,31 @@ knows { return KNOWS; } trusted { return TRUSTED; } option { return OPTION; } {text} { + int len; + char *dest; + char *src; + if (strlen(yytext) >= 2) { // Make a copy without the surrounding // double-quotes. // TODO: Allow to unescape quotes inside string if // needed later. - yylval.str = strndup(yytext+1,strlen(yytext)-2); + len = strlen(yytext)-2; + src = yytext+1; } else { // If only one character, then simply copy - yylval.str = strdup(yytext); + len = strlen(yytext); + src = yytext; } + // Copy + dest = (char *)malloc(len+1); + strncpy(dest,src,len); + dest[len] = EOS; + yylval.str = dest; + return TEXT; } {id} {