commit: simplify code

The difference of two unsigned integers is defined to be unsigned, and therefore it is misleading to check whether it is greater than zero (instead, the more natural way would be to check whether the difference is zero or not). Let's instead avoid the subtraction altogether, and compare the two operands directly, which makes the code more obvious as a side effect. Pointed out by CodeQL's rule with the ID `cpp/unsigned-difference-expression-compared-zero`. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed May 15, 2025 at 13:11 UTC 131a8fa8151c95f309241ead33018f30f57ff57c
1 file changed +1 -1
builtin/commit.c
+1 -1
@@ -1022,7 +1022,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
1022 for (i = 0; i < the_repository->index->cache_nr; i++)
1023 if (ce_intent_to_add(the_repository->index->cache[i]))
1024 ita_nr++;
1025 - committable = the_repository->index->cache_nr - ita_nr > 0;
1025 + committable = the_repository->index->cache_nr > ita_nr;
1026 } else {
1027 /*
1028 * Unless the user did explicitly request a submodule