Skip to content

Commit d6e35a2

Browse files
committed
Merge branch 'jn/size-t-casted-to-off-t-fix'
Rewrite code that triggers undefined behaiour warning. * jn/size-t-casted-to-off-t-fix: xsize_t: avoid implementation defined behavior when len < 0
2 parents bb6a63a + aafa5df commit d6e35a2

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

git-compat-util.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -986,11 +986,9 @@ static inline char *xstrdup_or_null(const char *str)
986986

987987
static inline size_t xsize_t(off_t len)
988988
{
989-
size_t size = (size_t) len;
990-
991-
if (len != (off_t) size)
989+
if (len < 0 || (uintmax_t) len > SIZE_MAX)
992990
die("Cannot handle files this big");
993-
return size;
991+
return (size_t) len;
994992
}
995993

996994
__attribute__((format (printf, 3, 4)))

0 commit comments

Comments
 (0)