From 533e8fdaf3669fe0e246f675178f785e4eecd55a Mon Sep 17 00:00:00 2001 From: Tim Kientzle Date: Sat, 29 Jun 2013 08:15:23 -0700 Subject: [PATCH] Rework the sign-extension to avoid left-shift of an explicit negative number (which newer GCC complains about). --- libarchive/archive_read_support_format_tar.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/libarchive/archive_read_support_format_tar.c b/libarchive/archive_read_support_format_tar.c index 1f33feeed..95960a2c1 100644 --- a/libarchive/archive_read_support_format_tar.c +++ b/libarchive/archive_read_support_format_tar.c @@ -2477,20 +2477,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); -- 2.47.2