diff options
| author | Junio C Hamano <gitster@pobox.com> | 2024-12-06 11:27:22 +0100 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2024-12-06 20:20:03 +0900 |
| commit | ba8f6018b5bed4fc58f8dfe2f9714d22398b06fe (patch) | |
| tree | 48cabeaead2941a34ff3ca022fa38e8d98a04504 /csum-file.c | |
| parent | 47d72a74a737f06791c282a75baf2c573cdf42f6 (diff) | |
| download | git-ba8f6018b5bed4fc58f8dfe2f9714d22398b06fe.tar.gz | |
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>
Diffstat (limited to 'csum-file.c')
| -rw-r--r-- | csum-file.c | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/csum-file.c b/csum-file.c index c14bacc7f9..5716016e12 100644 --- a/csum-file.c +++ b/csum-file.c @@ -9,7 +9,6 @@ */ #define USE_THE_REPOSITORY_VARIABLE -#define DISABLE_SIGN_COMPARE_WARNINGS #include "git-compat-util.h" #include "progress.h" @@ -24,7 +23,7 @@ static void verify_buffer_or_die(struct hashfile *f, if (ret < 0) die_errno("%s: sha1 file read error", f->name); - if (ret != count) + if ((size_t)ret != count) die("%s: sha1 file truncated", f->name); if (memcmp(buf, f->check_buffer, count)) die("sha1 file '%s' validation error", f->name); |
