From fa67d9c0d652dc41574b546f542909e9c8157237 Mon Sep 17 00:00:00 2001
From: Lennart Poettering <lennart@poettering.net>
Date: Tue, 12 Jan 2021 21:36:54 +0100
Subject: [PATCH] extract-word: don't rely on C's downgrade-to-bool feature for
chars
The `quote` char variable ectually contains a character, not a pointer
or boolean. hence do an explicit comparison rather than rely on C's
downgrade to bool feature, as per our coding style.
---
src/basic/extract-word.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/src/basic/extract-word.c b/src/basic/extract-word.c
index 76b3fe12e3b..4104dac9a74 100644
--- a/src/basic/extract-word.c
+++ b/src/basic/extract-word.c
@@ -20,11 +20,10 @@
int extract_first_word(const char **p, char **ret, const char *separators, ExtractFlags flags) {
_cleanup_free_ char *s = NULL;
size_t allocated = 0, sz = 0;
- char c;
- int r;
-
char quote = 0; /* 0 or ' or " */
bool backslash = false; /* whether we've just seen a backslash */
+ char c;
+ int r;
assert(p);
assert(ret);
@@ -71,7 +70,7 @@ int extract_first_word(const char **p, char **ret, const char *separators, Extra
if (c == 0) {
if ((flags & EXTRACT_CUNESCAPE_RELAX) &&
- (!quote || flags & EXTRACT_RELAX)) {
+ (quote == 0 || flags & EXTRACT_RELAX)) {
/* If we find an unquoted trailing backslash and we're in
* EXTRACT_CUNESCAPE_RELAX mode, keep it verbatim in the
* output.
@@ -116,7 +115,7 @@ int extract_first_word(const char **p, char **ret, const char *separators, Extra
backslash = false;
- } else if (quote) { /* inside either single or double quotes */
+ } else if (quote != 0) { /* inside either single or double quotes */
for (;; (*p)++, c = **p) {
if (c == 0) {
if (flags & EXTRACT_RELAX)