]> git.ipfire.org Git - thirdparty/git.git/commitdiff
compat/regex: explicitly mark intentional use of the comma operator
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Thu, 27 Mar 2025 11:53:01 +0000 (11:53 +0000)
committerJunio C Hamano <gitster@pobox.com>
Sat, 29 Mar 2025 00:38:11 +0000 (17:38 -0700)
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>
Acked-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
compat/regex/regex_internal.c
compat/regex/regexec.c

index ec5cc5d2dd10f81557007706f13a93f922ba3183..4a4f849629a26ea41dd251e7b3831b2920552d5a 100644 (file)
@@ -1232,7 +1232,10 @@ re_node_set_merge (re_node_set *dest, const re_node_set *src)
        is = src->nelem - 1, id = dest->nelem - 1; is >= 0 && id >= 0; )
     {
       if (dest->elems[id] == src->elems[is])
-       is--, id--;
+       {
+         is--;
+         id--;
+       }
       else if (dest->elems[id] < src->elems[is])
        dest->elems[--sbase] = src->elems[is--];
       else /* if (dest->elems[id] > src->elems[is]) */
index 2eeec82f4077b7a4cb07a6c00cf634f845e2c258..c08f1bbe1f5ecfbc22642ef58d38483edf7e910e 100644 (file)
@@ -2210,7 +2210,7 @@ sift_states_bkref (const re_match_context_t *mctx, re_sift_context_t *sctx,
          /* mctx->bkref_ents may have changed, reload the pointer.  */
          entry = mctx->bkref_ents + enabled_idx;
        }
-      while (enabled_idx++, entry++->more);
+      while ((void)enabled_idx++, entry++->more);
     }
   err = REG_NOERROR;
  free_return: