projects
/
collectd.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
f96dc61
)
scanner.l: modernize code a bit
author
Ruben Kerkhof
<ruben@rubenkerkhof.com>
Thu, 31 May 2018 14:47:05 +0000
(16:47 +0200)
committer
Ruben Kerkhof
<ruben@rubenkerkhof.com>
Thu, 31 May 2018 14:47:05 +0000
(16:47 +0200)
src/liboconfig/scanner.l
patch
|
blob
|
history
diff --git
a/src/liboconfig/scanner.l
b/src/liboconfig/scanner.l
index
be6d678
..
cfd9a5c
100644
(file)
--- a/
src/liboconfig/scanner.l
+++ b/
src/liboconfig/scanner.l
@@
-40,9
+40,9
@@
/* multiline string buffer */
/* 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)
#define ml_free (ml_len - ml_pos)
@@
-115,7
+115,7
@@
IPV6_ADDR ({IPV6_BASE})|(\[{IPV6_BASE}\](:{PORT})?)
ml_pos = 0;
/* remove "\\<EOL>" */
ml_pos = 0;
/* remove "\\<EOL>" */
- if (
'\r' == yytext[len - 2]
)
+ if (
yytext[len - 2] == '\r'
)
len -= 3;
else
len -= 2;
len -= 3;
else
len -= 2;
@@
-129,7
+129,7
@@
IPV6_ADDR ({IPV6_BASE})|(\[{IPV6_BASE}\](:{PORT})?)
size_t len = strlen (yytext);
/* remove "\\<EOL>" */
size_t len = strlen (yytext);
/* remove "\\<EOL>" */
- if (
'\r' == yytext[len - 2]
)
+ if (
yytext[len - 2] == '\r'
)
len -= 3;
else
len -= 2;
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);
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 (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");
}
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;
YY_FATAL_ERROR ("failed to write to multiline buffer");
ml_pos += s;