Skip to content

Commit 1d0ce59

Browse files
committed
wildmatch: avoid using of the comma operator
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. 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. However, it is hard to read. The chosen alternative to using the comma operator is to move those assignments from the condition into the loop body; In this particular case that requires special care 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), which needs to be turned into a `goto`. Helped-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 045d695 commit 1d0ce59

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

wildmatch.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ static int dowild(const uchar *p, const uchar *text, unsigned int flags)
223223
p_ch = '[';
224224
if (t_ch == p_ch)
225225
matched = 1;
226-
continue;
226+
goto next;
227227
}
228228
if (CC_EQ(s,i, "alnum")) {
229229
if (ISALNUM(t_ch))
@@ -268,7 +268,10 @@ static int dowild(const uchar *p, const uchar *text, unsigned int flags)
268268
p_ch = 0; /* This makes "prev_ch" get set to 0. */
269269
} else if (t_ch == p_ch)
270270
matched = 1;
271-
} while (prev_ch = p_ch, (p_ch = *++p) != ']');
271+
next:
272+
prev_ch = p_ch;
273+
p_ch = *++p;
274+
} while (p_ch != ']');
272275
if (matched == negated ||
273276
((flags & WM_PATHNAME) && t_ch == '/'))
274277
return WM_NOMATCH;

0 commit comments

Comments
 (0)