summaryrefslogtreecommitdiff
path: root/builtin/commit-graph.c
diff options
context:
space:
mode:
authorshejialuo <shejialuo@gmail.com>2025-06-29 12:28:06 +0800
committerJunio C Hamano <gitster@pobox.com>2025-07-07 08:07:46 -0700
commit67cfd2924d099b3316ddf579ba7c11fdc29ad2b6 (patch)
tree237214c74e41cadbafa72f3d58c1be9059ff73e2 /builtin/commit-graph.c
parent885becd9c4aec6c3764b4c701baf41853b49899e (diff)
string-list: enable sign compare warnings check
In "add_entry", we call "get_entry_index" function to get the inserted position. However, as the return type of "get_entry_index" function is `int`, there is a sign compare warning when comparing the `index` with the `list-nr` of unsigned type. "get_entry_index" would always return unsigned index. However, the current binary search algorithm initializes "left" to be "-1", which necessitates the use of signed `int` return type. The reason why we need to assign "left" to be "-1" is that in the `while` loop, we increment "left" by 1 to determine whether the loop should end. This design choice, while functional, forces us to use signed arithmetic throughout the function. To resolve this sign comparison issue, let's modify the binary search algorithm with the following approach: 1. Initialize "left" to 0 instead of -1 2. Use `left < right` as the loop termination condition instead of `left + 1 < right` 3. When searching the right part, set `left = middle + 1` instead of `middle` Then, we could delete "#define DISABLE_SIGN_COMPARE_WARNING" to enable sign warnings check for "string-list". Signed-off-by: shejialuo <shejialuo@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/commit-graph.c')
0 files changed, 0 insertions, 0 deletions