X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fliboconfig%2Fscanner.l;h=7efa78a3fd85dff042cba40824d095d7fcf5bd0a;hb=c4439c9cb3e2348ad7013644731de27a55eca478;hp=08524fd84a4a775dd778c9eb1d873f7935739d11;hpb=77243847767b4bc2ea6600a5f88ef45f2a8ec713;p=collectd.git diff --git a/src/liboconfig/scanner.l b/src/liboconfig/scanner.l index 08524fd8..7efa78a3 100644 --- a/src/liboconfig/scanner.l +++ b/src/liboconfig/scanner.l @@ -27,21 +27,27 @@ */ %{ -/* lex and yacc do some weird stuff, so turn off some warnings. */ -#if defined(__clang__) -# pragma clang diagnostic ignored "-Wunused-function" -# pragma clang diagnostic ignored "-Wunneeded-internal-declaration" +#ifdef WIN32 +#include "gnulib_config.h" +#include "config.h" #endif #include +#include #include "oconfig.h" #include "aux_types.h" #include "parser.h" +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wmissing-noreturn" +#endif + + /* multiline string buffer */ -static char *ml_buffer = NULL; -static int ml_pos = 0; -static int ml_len = 0; +static char *ml_buffer; +static size_t ml_pos; +static size_t ml_len; #define ml_free (ml_len - ml_pos) @@ -56,6 +62,8 @@ static void ml_append (char *); %} %option yylineno %option noyywrap +%option noinput +%option nounput %x ML WHITE_SPACE [\ \t\b] NON_WHITE_SPACE [^\ \t\b] @@ -107,12 +115,12 @@ IPV6_ADDR ({IPV6_BASE})|(\[{IPV6_BASE}\](:{PORT})?) {UNQUOTED_STRING} {yylval.string = yytext; return (UNQUOTED_STRING);} \"{QUOTED_STRING}\\{EOL} { - int len = strlen (yytext); + size_t len = strlen (yytext); ml_pos = 0; /* remove "\\" */ - if ('\r' == yytext[len - 2]) + if (yytext[len - 2] == '\r') len -= 3; else len -= 2; @@ -123,10 +131,10 @@ IPV6_ADDR ({IPV6_BASE})|(\[{IPV6_BASE}\](:{PORT})?) } ^{WHITE_SPACE}+ {/* remove leading white-space */} {NON_WHITE_SPACE}{QUOTED_STRING}\\{EOL} { - int len = strlen (yytext); + size_t len = strlen (yytext); /* remove "\\" */ - if ('\r' == yytext[len - 2]) + if (yytext[len - 2] == '\r') len -= 3; else len -= 2; @@ -144,21 +152,23 @@ IPV6_ADDR ({IPV6_BASE})|(\[{IPV6_BASE}\](:{PORT})?) %% static void ml_append (char *string) { - int len = strlen (string); - int s; + size_t len = strlen (string); if (ml_free <= len) { ml_len += len - ml_free + 1; - ml_buffer = (char *)realloc (ml_buffer, ml_len); - if (NULL == ml_buffer) + ml_buffer = realloc (ml_buffer, ml_len); + if (ml_buffer == NULL) YY_FATAL_ERROR ("out of dynamic memory in ml_append"); } - s = snprintf (ml_buffer + ml_pos, ml_free, "%s", string); - if ((0 > s) || (ml_free <= s)) + int s = snprintf(ml_buffer + ml_pos, ml_free, "%s", string); + if (s < 0 || (size_t)s >= ml_free) YY_FATAL_ERROR ("failed to write to multiline buffer"); ml_pos += s; return; } /* ml_append */ +#ifdef __clang__ +#pragma clang diagnostic pop +#endif