Skip to content

Commit ba8f601

Browse files
committed
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 <[email protected]> Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 47d72a7 commit ba8f601

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

csum-file.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
*/
1010

1111
#define USE_THE_REPOSITORY_VARIABLE
12-
#define DISABLE_SIGN_COMPARE_WARNINGS
1312

1413
#include "git-compat-util.h"
1514
#include "progress.h"
@@ -24,7 +23,7 @@ static void verify_buffer_or_die(struct hashfile *f,
2423

2524
if (ret < 0)
2625
die_errno("%s: sha1 file read error", f->name);
27-
if (ret != count)
26+
if ((size_t)ret != count)
2827
die("%s: sha1 file truncated", f->name);
2928
if (memcmp(buf, f->check_buffer, count))
3029
die("sha1 file '%s' validation error", f->name);

0 commit comments

Comments
 (0)