]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
extract-word: don't rely on C's downgrade-to-bool feature for chars
authorLennart Poettering <lennart@poettering.net>
Tue, 12 Jan 2021 20:36:54 +0000 (21:36 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 12 Jan 2021 21:00:35 +0000 (22:00 +0100)
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

index 76b3fe12e3b8c4437a6893d29ddbaf84fc9e54be..4104dac9a74eba854c2c06abe9c3be3855157c11 100644 (file)
 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)