Consolidate numeric limit macros in one place; include them

only on platforms that need them.  FreeBSD doesn't.
This commit is contained in:
Tim Kientzle 2007-04-15 00:53:38 +00:00
parent e115d3c2dd
commit f912fb118f
6 changed files with 44 additions and 49 deletions

View File

@ -9,7 +9,7 @@ LDADD= -lbz2 -lz
# Major: Bumped ONLY when API/ABI breakage happens (see SHLIB_MAJOR)
# Minor: Bumped when significant new features are added
# Revision: Bumped on any notable change
VERSION= 2.0.30
VERSION= 2.0.31
ARCHIVE_API_MAJOR!= echo ${VERSION} | sed -e 's/[^0-9]/./g' -e 's/\..*//'
ARCHIVE_API_MINOR!= echo ${VERSION} | sed -e 's/[^0-9]/./g' -e 's/[0-9]*\.//' -e 's/\..*//'

View File

@ -67,6 +67,23 @@
#include <stdint.h>
#endif
/* Some platforms lack the standard *_MAX definitions. */
#if !HAVE_DECL_SIZE_MAX
#define SIZE_MAX (~(size_t)0)
#endif
#if !HAVE_DECL_UINT32_MAX
#define UINT32_MAX (~(uint32_t)0)
#endif
#if !HAVE_DECL_UINT64_MAX
#define UINT64_MAX (~(uint64_t)0)
#endif
#if !HAVE_DECL_INT64_MAX
#define INT64_MAX ((int64_t)(UINT64_MAX >> 1))
#endif
#if !HAVE_DECL_INT64_MIN
#define INT64_MIN ((int64_t)(~INT64_MAX))
#endif
/*
* If this platform has <sys/acl.h>, acl_create(), acl_init(),
* acl_set_file(), and ACL_USER, we assume it has the rest of the

View File

@ -556,13 +556,12 @@ ar_parse_gnu_filename_table(struct archive_read *a, struct ar *ar,
static uint64_t
ar_atol8(const char *p, unsigned char_cnt)
{
static const uint64_t max_uint64 = ~(uint64_t)0;
uint64_t l, limit, last_digit_limit;
unsigned int digit, base;
base = 8;
limit = max_uint64 / base;
last_digit_limit = max_uint64 % base;
limit = UINT64_MAX / base;
last_digit_limit = UINT64_MAX % base;
while ((*p == ' ' || *p == '\t') && char_cnt-- > 0)
p++;
@ -571,7 +570,7 @@ ar_atol8(const char *p, unsigned char_cnt)
digit = *p - '0';
while (*p >= '0' && digit < base && char_cnt-- > 0) {
if (l>limit || (l == limit && digit > last_digit_limit)) {
l = max_uint64; /* Truncate on overflow. */
l = UINT64_MAX; /* Truncate on overflow. */
break;
}
l = (l * base) + digit;
@ -583,13 +582,12 @@ ar_atol8(const char *p, unsigned char_cnt)
static uint64_t
ar_atol10(const char *p, unsigned char_cnt)
{
static const uint64_t max_uint64 = ~(uint64_t)0;
uint64_t l, limit, last_digit_limit;
unsigned int base, digit;
base = 10;
limit = max_uint64 / base;
last_digit_limit = max_uint64 % base;
limit = UINT64_MAX / base;
last_digit_limit = UINT64_MAX % base;
while ((*p == ' ' || *p == '\t') && char_cnt-- > 0)
p++;
@ -597,7 +595,7 @@ ar_atol10(const char *p, unsigned char_cnt)
digit = *p - '0';
while (*p >= '0' && digit < base && char_cnt-- > 0) {
if (l > limit || (l == limit && digit > last_digit_limit)) {
l = max_uint64; /* Truncate on overflow. */
l = UINT64_MAX; /* Truncate on overflow. */
break;
}
l = (l * base) + digit;

View File

@ -225,28 +225,6 @@ static char *url_decode(const char *);
static int utf8_decode(wchar_t *, const char *, size_t length);
static char *wide_to_narrow(const wchar_t *wval);
/*
* ANSI C99 defines constants for these, but not everyone supports
* those constants, so I define a couple of static variables here and
* compute the values. These calculations should be portable to any
* 2s-complement architecture.
*/
#ifdef UINT64_MAX
static const uint64_t max_uint64 = UINT64_MAX;
#else
static const uint64_t max_uint64 = ~(uint64_t)0;
#endif
#ifdef INT64_MAX
static const int64_t max_int64 = INT64_MAX;
#else
static const int64_t max_int64 = (int64_t)((~(uint64_t)0) >> 1);
#endif
#ifdef INT64_MIN
static const int64_t min_int64 = INT64_MIN;
#else
static const int64_t min_int64 = (int64_t)(~((~(uint64_t)0) >> 1));
#endif
int
archive_read_support_format_gnutar(struct archive *a)
{
@ -1379,8 +1357,8 @@ pax_time(const wchar_t *p, int64_t *ps, long *pn)
int sign;
int64_t limit, last_digit_limit;
limit = max_int64 / 10;
last_digit_limit = max_int64 % 10;
limit = INT64_MAX / 10;
last_digit_limit = INT64_MAX % 10;
s = 0;
sign = 1;
@ -1392,7 +1370,7 @@ pax_time(const wchar_t *p, int64_t *ps, long *pn)
digit = *p - '0';
if (s > limit ||
(s == limit && digit > last_digit_limit)) {
s = max_uint64;
s = UINT64_MAX;
break;
}
s = (s * 10) + digit;
@ -1593,8 +1571,8 @@ tar_atol8(const char *p, unsigned char_cnt)
int digit, sign, base;
base = 8;
limit = max_int64 / base;
last_digit_limit = max_int64 % base;
limit = INT64_MAX / base;
last_digit_limit = INT64_MAX % base;
while (*p == ' ' || *p == '\t')
p++;
@ -1608,7 +1586,7 @@ tar_atol8(const char *p, unsigned char_cnt)
digit = *p - '0';
while (digit >= 0 && digit < base && char_cnt-- > 0) {
if (l>limit || (l == limit && digit > last_digit_limit)) {
l = max_uint64; /* Truncate on overflow. */
l = UINT64_MAX; /* Truncate on overflow. */
break;
}
l = (l * base) + digit;
@ -1630,8 +1608,8 @@ tar_atol10(const wchar_t *p, unsigned char_cnt)
int base, digit, sign;
base = 10;
limit = max_int64 / base;
last_digit_limit = max_int64 % base;
limit = INT64_MAX / base;
last_digit_limit = INT64_MAX % base;
while (*p == ' ' || *p == '\t')
p++;
@ -1645,7 +1623,7 @@ tar_atol10(const wchar_t *p, unsigned char_cnt)
digit = *p - '0';
while (digit >= 0 && digit < base && char_cnt-- > 0) {
if (l > limit || (l == limit && digit > last_digit_limit)) {
l = max_uint64; /* Truncate on overflow. */
l = UINT64_MAX; /* Truncate on overflow. */
break;
}
l = (l * base) + digit;
@ -1668,8 +1646,8 @@ tar_atol256(const char *_p, unsigned char_cnt)
int64_t l, upper_limit, lower_limit;
const unsigned char *p = (const unsigned char *)_p;
upper_limit = max_int64 / 256;
lower_limit = min_int64 / 256;
upper_limit = INT64_MAX / 256;
lower_limit = INT64_MIN / 256;
/* Pad with 1 or 0 bits, depending on sign. */
if ((0x40 & *p) == 0x40)
@ -1679,10 +1657,10 @@ tar_atol256(const char *_p, unsigned char_cnt)
l = (l << 6) | (0x3f & *p++);
while (--char_cnt > 0) {
if (l > upper_limit) {
l = max_int64; /* Truncate on overflow */
l = INT64_MAX; /* Truncate on overflow */
break;
} else if (l < lower_limit) {
l = min_int64;
l = INT64_MIN;
break;
}
l = (l << 8) | (0xff & (int64_t)*p++);

View File

@ -137,9 +137,6 @@ static int zip_read_file_header(struct archive_read *a,
static time_t zip_time(const char *);
static void process_extra(const void* extra, struct zip* zip);
/* Largest 32-bit unsigned value, stored in a 64-bit constant. */
static const uint64_t max_uint32 = (((uint64_t)1) << 32) - 1;
int
archive_read_support_format_zip(struct archive *_a)
{
@ -412,8 +409,8 @@ archive_read_format_zip_read_data(struct archive_read *a,
return (ARCHIVE_WARN);
}
/* Size field only stores the lower 32 bits of the actual size. */
if ((zip->uncompressed_size & max_uint32)
!= (zip->entry_uncompressed_bytes_read & max_uint32)) {
if ((zip->uncompressed_size & UINT32_MAX)
!= (zip->entry_uncompressed_bytes_read & UINT32_MAX)) {
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
"ZIP uncompressed data is wrong size");
return (ARCHIVE_WARN);

View File

@ -37,7 +37,12 @@
#define HAVE_BZLIB_H 1
#define HAVE_CHFLAGS 1
#define HAVE_DECL_INT64_MAX 1
#define HAVE_DECL_INT64_MIN 1
#define HAVE_DECL_SIZE_MAX 1
#define HAVE_DECL_STRERROR_R 1
#define HAVE_DECL_UINT32_MAX 1
#define HAVE_DECL_UINT64_MAX 1
#define HAVE_EFTYPE 1
#define HAVE_EILSEQ 1
#define HAVE_ERRNO_H 1