Skip to content

Commit b8405f3

Browse files
committed
compat/regex: explicitly mark intentional use 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 the `compat/regex/` code, the comma operator is used twice, once to avoid surrounding two conditional statements with curly brackets, the other one to increment two counters simultaneously in a `do ... while` condition. The first one is replaced with a proper conditional block, surrounded by curly brackets. The second one would be harder to replace because the loop contains two `continue`s. Therefore, the second one is marked as intentional by casting the value-to-discard to `void`. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 1d0ce59 commit b8405f3

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

compat/regex/regex_internal.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,10 @@ re_node_set_merge (re_node_set *dest, const re_node_set *src)
12321232
is = src->nelem - 1, id = dest->nelem - 1; is >= 0 && id >= 0; )
12331233
{
12341234
if (dest->elems[id] == src->elems[is])
1235-
is--, id--;
1235+
{
1236+
is--;
1237+
id--;
1238+
}
12361239
else if (dest->elems[id] < src->elems[is])
12371240
dest->elems[--sbase] = src->elems[is--];
12381241
else /* if (dest->elems[id] > src->elems[is]) */

compat/regex/regexec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2210,7 +2210,7 @@ sift_states_bkref (const re_match_context_t *mctx, re_sift_context_t *sctx,
22102210
/* mctx->bkref_ents may have changed, reload the pointer. */
22112211
entry = mctx->bkref_ents + enabled_idx;
22122212
}
2213-
while (enabled_idx++, entry++->more);
2213+
while ((void)enabled_idx++, entry++->more);
22142214
}
22152215
err = REG_NOERROR;
22162216
free_return:

0 commit comments

Comments
 (0)