From df349a2e12e6170f86818c6f2c6ee7a560a8467a Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Thu, 31 May 2018 16:47:05 +0200 Subject: [PATCH] scanner.l: modernize code a bit --- src/liboconfig/scanner.l | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/liboconfig/scanner.l b/src/liboconfig/scanner.l index be6d6782..cfd9a5c9 100644 --- a/src/liboconfig/scanner.l +++ b/src/liboconfig/scanner.l @@ -40,9 +40,9 @@ /* multiline string buffer */ -static char *ml_buffer = NULL; -static size_t ml_pos = 0; -static size_t ml_len = 0; +static char *ml_buffer; +static size_t ml_pos; +static size_t ml_len; #define ml_free (ml_len - ml_pos) @@ -115,7 +115,7 @@ IPV6_ADDR ({IPV6_BASE})|(\[{IPV6_BASE}\](:{PORT})?) ml_pos = 0; /* remove "\\" */ - if ('\r' == yytext[len - 2]) + if (yytext[len - 2] == '\r') len -= 3; else len -= 2; @@ -129,7 +129,7 @@ IPV6_ADDR ({IPV6_BASE})|(\[{IPV6_BASE}\](:{PORT})?) size_t len = strlen (yytext); /* remove "\\" */ - if ('\r' == yytext[len - 2]) + if (yytext[len - 2] == '\r') len -= 3; else len -= 2; @@ -148,17 +148,16 @@ IPV6_ADDR ({IPV6_BASE})|(\[{IPV6_BASE}\](:{PORT})?) static void ml_append (char *string) { size_t len = strlen (string); - int s; if (ml_free <= len) { ml_len += len - ml_free + 1; ml_buffer = realloc (ml_buffer, ml_len); - if (NULL == ml_buffer) + 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; -- 2.11.0