diff options
author | Brad King <brad.king@kitware.com> | 2013-11-25 16:16:45 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2013-11-25 16:16:45 (GMT) |
commit | 5ee1297d6be6ffc946ac4b7947bfd60443583afc (patch) | |
tree | 3ac8846f2f0e390afb6a1b38563ca59ef7274c84 /Utilities | |
parent | da6b86f4f031b189768dc474721145a1b99f71ea (diff) | |
download | CMake-5ee1297d6be6ffc946ac4b7947bfd60443583afc.zip CMake-5ee1297d6be6ffc946ac4b7947bfd60443583afc.tar.gz CMake-5ee1297d6be6ffc946ac4b7947bfd60443583afc.tar.bz2 |
libarchive: Port upstream issue 320 fix
Port upstream commit 533e8fda (Rework the sign-extension to avoid
left-shift of an explicit negative number, 2013-06-29) into CMake.
Inspired-by: Tim Kientzle <kientzle@freebsd.org>
Diffstat (limited to 'Utilities')
-rw-r--r-- | Utilities/cmlibarchive/libarchive/archive_read_support_format_tar.c | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_tar.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_tar.c index e9523cb..a4dc710 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_tar.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_tar.c @@ -2475,20 +2475,16 @@ tar_atol256(const char *_p, size_t char_cnt) upper_limit = INT64_MAX / 256; lower_limit = INT64_MIN / 256; - /* Pad with 1 or 0 bits, depending on sign. */ + /* Sign-extend the 7-bit value to 64 bits. */ if ((0x40 & *p) == 0x40) - l = (int64_t)-1; + l = ~((int64_t)0x3f) | *p++; else - l = 0; - l = (l << 6) | (0x3f & *p++); + l = 0x3f & *p++; while (--char_cnt > 0) { - if (l > upper_limit) { - l = INT64_MAX; /* Truncate on overflow */ - break; - } else if (l < lower_limit) { - l = INT64_MIN; - break; - } + if (l > upper_limit) + return (INT64_MAX); /* Truncate on overflow */ + else if (l < lower_limit) + return (INT64_MIN); l = (l << 8) | (0xff & (int64_t)*p++); } return (l); |