daandemeyer / rpms / systemd

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