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
This commit is contained in:
commit
d6e35a2644
@ -986,11 +986,9 @@ static inline char *xstrdup_or_null(const char *str)
|
||||
|
||||
static inline size_t xsize_t(off_t len)
|
||||
{
|
||||
size_t size = (size_t) len;
|
||||
|
||||
if (len != (off_t) size)
|
||||
if (len < 0 || (uintmax_t) len > SIZE_MAX)
|
||||
die("Cannot handle files this big");
|
||||
return size;
|
||||
return (size_t) len;
|
||||
}
|
||||
|
||||
__attribute__((format (printf, 3, 4)))
|
||||
|
Loading…
Reference in New Issue
Block a user