Skip to content

Commit 131a8fa

Browse files
dschogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1a8a497 commit 131a8fa

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

builtin/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
10221022
for (i = 0; i < the_repository->index->cache_nr; i++)
10231023
if (ce_intent_to_add(the_repository->index->cache[i]))
10241024
ita_nr++;
1025-
committable = the_repository->index->cache_nr - ita_nr > 0;
1025+
committable = the_repository->index->cache_nr > ita_nr;
10261026
} else {
10271027
/*
10281028
* Unless the user did explicitly request a submodule

0 commit comments

Comments
 (0)