diff options
author | Johannes Schindelin <johannes.schindelin@gmx.de> | 2025-05-15 13:11:39 +0000 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2025-05-15 13:46:44 -0700 |
commit | 131a8fa8151c95f309241ead33018f30f57ff57c (patch) | |
tree | 38787c8e0b0ec935fab7275eabb44bdd542e2d68 | |
parent | 1a8a4971cc6c179c4dd711f4a7f5d7178f4b3ab7 (diff) |
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>
-rw-r--r-- | builtin/commit.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/builtin/commit.c b/builtin/commit.c index 66bd91fd52..fba0dded64 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1022,7 +1022,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix, for (i = 0; i < the_repository->index->cache_nr; i++) if (ce_intent_to_add(the_repository->index->cache[i])) ita_nr++; - committable = the_repository->index->cache_nr - ita_nr > 0; + committable = the_repository->index->cache_nr > ita_nr; } else { /* * Unless the user did explicitly request a submodule |