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.
This commit is contained in:
Cas Cremers 2012-12-17 20:51:42 +01:00
parent 49097852d9
commit b92c097b38

View File

@ -23,6 +23,7 @@
/* scanner for security protocols language */ /* scanner for security protocols language */
#include <strings.h> #include <strings.h>
#include <string.h>
#include "pheading.h" #include "pheading.h"
#include "tac.h" #include "tac.h"
#include "switches.h" #include "switches.h"
@ -180,19 +181,31 @@ knows { return KNOWS; }
trusted { return TRUSTED; } trusted { return TRUSTED; }
option { return OPTION; } option { return OPTION; }
{text} { {text} {
int len;
char *dest;
char *src;
if (strlen(yytext) >= 2) if (strlen(yytext) >= 2)
{ {
// Make a copy without the surrounding // Make a copy without the surrounding
// double-quotes. // double-quotes.
// TODO: Allow to unescape quotes inside string if // TODO: Allow to unescape quotes inside string if
// needed later. // needed later.
yylval.str = strndup(yytext+1,strlen(yytext)-2); len = strlen(yytext)-2;
src = yytext+1;
} }
else else
{ {
// If only one character, then simply copy // 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; return TEXT;
} }
{id} { {id} {