madler / zlib

A massively spiffy yet delicately unobtrusive compression library.

Home Page:http://zlib.net/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

include <stdint.h> only if HAS_STDINT_H is defined

minchai23 opened this issue · comments

https://github.com/madler/zlib/blob/develop/contrib/minizip/zip.c#L28

#include <stdint.h>

https://github.com/madler/zlib/blob/develop/contrib/minizip/ioapi.h#L89

#ifdef HAS_STDINT_H
#include "stdint.h"
typedef uint64_t ZPOS64_T;
#else
...
#endif

Otherwise,compiling error on an older compiler,because the stdint.h header file is not found.
@madler

What compiler is this?

What compiler is this?

gcc 2.96 in tornado 2.2,support C standard library version is C89

Does it have limits.h? long long?

Does it have limits.h? long long?

yes, both limits.h and long long exists

Please let me know if this compiles without error:

#ifndef INTS_H
#define INTS_H
#include <limits.h>
#if defined(UCHAR_MAX) && UCHAR_MAX == 0xff
    typedef signed char i8_t;
    typedef unsigned char ui8_t;
#else
#   error "no 8-bit integer"
#endif
#if defined(USHRT_MAX) && USHRT_MAX == 0xffff
    typedef short i16_t;
    typedef unsigned short ui16_t;
#elif defined(UINT_MAX) && UINT_MAX == 0xffff
    typedef int i16_t;
    typedef unsigned ui16_t;
#else
#   error "no 16-bit integer"
#endif
#if defined(UINT_MAX) && UINT_MAX == 0xffffffff
    typedef int i32_t;
    typedef unsigned ui32_t;
#elif defined(ULONG_MAX) && ULONG_MAX == 0xffffffff
    typedef long i32_t;
    typedef unsigned long ui32_t;
#else
#   error "no 32-bit integer"
#endif
#if defined(ULONG_MAX) && ULONG_MAX == 0xffffffffffffffff
    typedef long i64_t;
    typedef unsigned long ui64_t;
#elif defined(ULLONG_MAX) && ULLONG_MAX == 0xffffffffffffffff
    typedef long long i64_t;
    typedef unsigned long long ui64_t;
#else
#   error "no 64-bit integer"
#endif
#endif

error "no 64-bit integer

image

Is ULLONG_MAX not defined in limits.h (or what it may itself include)?

Is ULLONG_MAX not defined in limits.h (or what it may itself include)?

ULLONG_MAX not defined,but ULONG_MAX and ULONG_LONG_MAX
image
image

View Commit Log , #include <stdint.h> just to use uintptr_t.

zi->ci.stream.next_in = (Bytef*)(uintptr_t)buf;

Can uintptr_t typecast be removed here? Direct typecast seems to be fine.

It's not fine as is, since that generates a warning about removing the const constraint on buf. However I have already removed the uintptr_t cast in my local branch by preceding the #include "zlib.h" with a #define ZLIB_CONST, which makes next_in const, and also removing the Bytef* cast. There is then no removal of the const constraint, and no warning.

Weird. Ok. Please try this:

#ifndef INTS_H
#define INTS_H
#include <limits.h>
#if defined(UCHAR_MAX) && UCHAR_MAX == 0xff
    typedef signed char i8_t;
    typedef unsigned char ui8_t;
#else
#   error "no 8-bit integer"
#endif
#if defined(USHRT_MAX) && USHRT_MAX == 0xffff
    typedef short i16_t;
    typedef unsigned short ui16_t;
#elif defined(UINT_MAX) && UINT_MAX == 0xffff
    typedef int i16_t;
    typedef unsigned ui16_t;
#else
#   error "no 16-bit integer"
#endif
#if defined(UINT_MAX) && UINT_MAX == 0xffffffff
    typedef int i32_t;
    typedef unsigned ui32_t;
#   define PI32 "d"
#   define PUI32 "u"
#elif defined(ULONG_MAX) && ULONG_MAX == 0xffffffff
    typedef long i32_t;
    typedef unsigned long ui32_t;
#   define PI32 "ld"
#   define PUI32 "lu"
#else
#   error "no 32-bit integer"
#endif
#if defined(ULONG_MAX) && ULONG_MAX == 0xffffffffffffffff
    typedef long i64_t;
    typedef unsigned long ui64_t;
#   define PI64 "ld"
#   define PUI64 "lu"
#elif defined(ULLONG_MAX) && ULLONG_MAX == 0xffffffffffffffff
    typedef long long i64_t;
    typedef unsigned long long ui64_t;
#   define PI64 "lld"
#   define PUI64 "llu"
#elif defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 0xffffffffffffffff
    typedef long long i64_t;
    typedef unsigned long long ui64_t;
#   define PI64 "lld"
#   define PUI64 "llu"
#else
#   error "no 64-bit integer"
#endif
#endif

Weird. Ok. Please try this:

#ifndef INTS_H
#define INTS_H
#include <limits.h>
#if defined(UCHAR_MAX) && UCHAR_MAX == 0xff
    typedef signed char i8_t;
    typedef unsigned char ui8_t;
#else
#   error "no 8-bit integer"
#endif
#if defined(USHRT_MAX) && USHRT_MAX == 0xffff
    typedef short i16_t;
    typedef unsigned short ui16_t;
#elif defined(UINT_MAX) && UINT_MAX == 0xffff
    typedef int i16_t;
    typedef unsigned ui16_t;
#else
#   error "no 16-bit integer"
#endif
#if defined(UINT_MAX) && UINT_MAX == 0xffffffff
    typedef int i32_t;
    typedef unsigned ui32_t;
#   define PI32 "d"
#   define PUI32 "u"
#elif defined(ULONG_MAX) && ULONG_MAX == 0xffffffff
    typedef long i32_t;
    typedef unsigned long ui32_t;
#   define PI32 "ld"
#   define PUI32 "lu"
#else
#   error "no 32-bit integer"
#endif
#if defined(ULONG_MAX) && ULONG_MAX == 0xffffffffffffffff
    typedef long i64_t;
    typedef unsigned long ui64_t;
#   define PI64 "ld"
#   define PUI64 "lu"
#elif defined(ULLONG_MAX) && ULLONG_MAX == 0xffffffffffffffff
    typedef long long i64_t;
    typedef unsigned long long ui64_t;
#   define PI64 "lld"
#   define PUI64 "llu"
#elif defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 0xffffffffffffffff
    typedef long long i64_t;
    typedef unsigned long long ui64_t;
#   define PI64 "lld"
#   define PUI64 "llu"
#else
#   error "no 64-bit integer"
#endif
#endif

compile success !!!

Great! Thank you for your help.

if there's a rough estimate of when a fix might be available?

Soon.

As an aside, I found that gcc 2.96 was never a released version!
https://gcc.gnu.org/gcc-2.96.html

be24a8f should fix it.