csum-file: fix -Wsign-compare warning on 32-bit platform
On 32-bit platforms, ssize_t may be "int" while size_t may be "unsigned int". At times we compare the number of bytes we read stored in a ssize_t variable with "unsigned int", but that is done after we check that we did not get an error return (which is negative---and that is the whole reason why we used ssize_t and not size_t), so these comparisons are safe. But compilers may not realize that. Cast these to size_t to work around the false positives. On platforms with size_t/ssize_t wider than a normal int, this won't be an issue. Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Dec 6, 2024 at 11:27 UTC
ba8f6018b5bed4fc58f8dfe2f9714d22398b06fe
1 file changed
+1
-2
csum-file.c
+1
-2
@@ -9,7 +9,6 @@
9
*/
10
11
#define USE_THE_REPOSITORY_VARIABLE
12
-#define DISABLE_SIGN_COMPARE_WARNINGS
12
13
#include "git-compat-util.h"
14
#include "progress.h"
@@ -24,7 +23,7 @@ static void verify_buffer_or_die(struct hashfile *f,
23
24
if (ret < 0)
25
die_errno("%s: sha1 file read error", f->name);
27
- if (ret != count)
26
+ if ((size_t)ret != count)
27
die("%s: sha1 file truncated", f->name);
28
if (memcmp(buf, f->check_buffer, count))
29
die("sha1 file '%s' validation error", f->name);