[PATCH v2 07/10] wildmatch: explicitly mark intentional use of the comma operator
- From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Mar 25, 2025, 23:32 UTC
- Message-ID
- <9a6de12b8076266fb0c88f6b658c20d37409ce13.1742945534.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.1889.v2.git.1742945534.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>
The comma operator is a somewhat obscure C feature that is often used by mistake and can even cause unintentional code flow. That is why the `-Wcomma` option of clang was introduced: To identify unintentional uses of the comma operator.
To mark such a usage as intentional, the value needs to be cast to `void`, which we do here.
In this instance, the usage is intentional because it allows storing the value of the current character as `prev_ch` before making the next character the current one, all of which happens in the loop condition that lets the loop stop at a closing bracket.
The alternative to using the comma operator would be to move those assignments from the condition into the loop body; In this particular case that would require the assignments to either be duplicated or to introduce and use a `goto` target before the assignments, though, because the loop body contains a `continue` for the case where a character class is found that starts with `[:` but does not end in `:]` (and the assignments should occur even when that code path is taken).
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> --- wildmatch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/wildmatch.c b/wildmatch.c index 8ea29141bd7..ce8108a6d57 100644 --- a/wildmatch.c +++ b/wildmatch.c @@ -268,7 +268,7 @@ static int dowild(const uchar *p, const uchar *text, unsigned int flags) p_ch = 0; /* This makes "prev_ch" get set to 0. */ } else if (t_ch == p_ch) matched = 1; - } while (prev_ch = p_ch, (p_ch = *++p) != ']'); + } while ((void)(prev_ch = p_ch), (p_ch = *++p) != ']'); if (matched == negated || ((flags & WM_PATHNAME) && t_ch == '/')) return WM_NOMATCH;
-- gitgitgadget