diff options
author | Junio C Hamano <gitster@pobox.com> | 2021-06-10 12:04:23 +0900 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-06-10 12:04:23 +0900 |
commit | d6e35a2644d6c0050989061ec93ed0d9111c5ee4 (patch) | |
tree | e19e04d45c6120652cfaa99cd4c214d46b14b831 /git-compat-util.h | |
parent | bb6a63a4e556262be5da397aa624a65d7582f611 (diff) | |
parent | aafa5df0df39036c6500846acd3db5b75d264a3b (diff) | |
download | git-d6e35a2644d6c0050989061ec93ed0d9111c5ee4.tar.gz |
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
Diffstat (limited to 'git-compat-util.h')
-rw-r--r-- | git-compat-util.h | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/git-compat-util.h b/git-compat-util.h index a508dbe5a3..fb6e9af76b 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -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))) |