hbmap: fix iterator truncation when size_t < 32bit
[rofl0r-agsutils.git] / miniz.h
blob216e82b7e0106278ed68f3133a2e9a6738c70af6
1 #include <stddef.h>
2 #include <stdint.h>
4 /* Decompression flags used by tinfl_decompress(). */
5 /* TINFL_FLAG_PARSE_ZLIB_HEADER: If set, the input has a valid zlib header and ends with an adler32 checksum (it's a valid zlib stream). Otherwise, the input is a raw deflate stream. */
6 /* TINFL_FLAG_HAS_MORE_INPUT: If set, there are more input bytes available beyond the end of the supplied input buffer. If clear, the input buffer contains all remaining input. */
7 /* TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF: If set, the output buffer is large enough to hold the entire decompressed stream. If clear, the output buffer is at least the size of the dictionary (typically 32KB). */
8 /* TINFL_FLAG_COMPUTE_ADLER32: Force adler-32 checksum computation of the decompressed bytes. */
9 enum
11 TINFL_FLAG_PARSE_ZLIB_HEADER = 1,
12 TINFL_FLAG_HAS_MORE_INPUT = 2,
13 TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF = 4,
14 TINFL_FLAG_COMPUTE_ADLER32 = 8
17 void *tinfl_decompress_mem_to_heap(const void *, size_t, size_t *, int);
19 #ifdef MINIZ_PRIVATE
21 #include <string.h>
22 #include <stdlib.h>
24 typedef unsigned char mz_uint8;
25 typedef signed short mz_int16;
26 typedef unsigned short mz_uint16;
27 typedef unsigned int mz_uint32;
28 typedef unsigned int mz_uint;
29 typedef int64_t mz_int64;
30 typedef uint64_t mz_uint64;
31 typedef int mz_bool;
33 typedef mz_uint32 tinfl_bit_buf_t;
34 #define TINFL_BITBUF_SIZE (32)
36 enum
38 TINFL_MAX_HUFF_TABLES = 3,
39 TINFL_MAX_HUFF_SYMBOLS_0 = 288,
40 TINFL_MAX_HUFF_SYMBOLS_1 = 32,
41 TINFL_MAX_HUFF_SYMBOLS_2 = 19,
42 TINFL_FAST_LOOKUP_BITS = 10,
43 TINFL_FAST_LOOKUP_SIZE = 1 << TINFL_FAST_LOOKUP_BITS
46 struct tinfl_decompressor_tag;
47 typedef struct tinfl_decompressor_tag tinfl_decompressor;
48 struct tinfl_decompressor_tag
50 mz_uint32 m_state, m_num_bits, m_zhdr0, m_zhdr1, m_z_adler32, m_final, m_type, m_check_adler32, m_dist, m_counter, m_num_extra, m_table_sizes[TINFL_MAX_HUFF_TABLES];
51 tinfl_bit_buf_t m_bit_buf;
52 size_t m_dist_from_out_buf_start;
53 mz_int16 m_look_up[TINFL_MAX_HUFF_TABLES][TINFL_FAST_LOOKUP_SIZE];
54 mz_int16 m_tree_0[TINFL_MAX_HUFF_SYMBOLS_0 * 2];
55 mz_int16 m_tree_1[TINFL_MAX_HUFF_SYMBOLS_1 * 2];
56 mz_int16 m_tree_2[TINFL_MAX_HUFF_SYMBOLS_2 * 2];
57 mz_uint8 m_code_size_0[TINFL_MAX_HUFF_SYMBOLS_0];
58 mz_uint8 m_code_size_1[TINFL_MAX_HUFF_SYMBOLS_1];
59 mz_uint8 m_code_size_2[TINFL_MAX_HUFF_SYMBOLS_2];
60 mz_uint8 m_raw_header[4], m_len_codes[TINFL_MAX_HUFF_SYMBOLS_0 + TINFL_MAX_HUFF_SYMBOLS_1 + 137];
63 #define MZ_MALLOC(x) malloc(x)
64 #define MZ_FREE(x) free(x)
65 #define MZ_REALLOC(p, x) realloc(p, x)
67 #define MZ_MAX(a, b) (((a) > (b)) ? (a) : (b))
68 #define MZ_MIN(a, b) (((a) < (b)) ? (a) : (b))
69 #define MZ_CLEAR_OBJ(obj) memset(&(obj), 0, sizeof(obj))
70 #define MZ_CLEAR_ARR(obj) memset((obj), 0, sizeof(obj))
71 #define MZ_CLEAR_PTR(obj) memset((obj), 0, sizeof(*obj))
73 /* Return status. */
74 typedef enum {
75 /* This flags indicates the inflator needs 1 or more input bytes to make forward progress, but the caller is indicating that no more are available. The compressed data */
76 /* is probably corrupted. If you call the inflator again with more bytes it'll try to continue processing the input but this is a BAD sign (either the data is corrupted or you called it incorrectly). */
77 /* If you call it again with no input you'll just get TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS again. */
78 TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS = -4,
80 /* This flag indicates that one or more of the input parameters was obviously bogus. (You can try calling it again, but if you get this error the calling code is wrong.) */
81 TINFL_STATUS_BAD_PARAM = -3,
83 /* This flags indicate the inflator is finished but the adler32 check of the uncompressed data didn't match. If you call it again it'll return TINFL_STATUS_DONE. */
84 TINFL_STATUS_ADLER32_MISMATCH = -2,
86 /* This flags indicate the inflator has somehow failed (bad code, corrupted input, etc.). If you call it again without resetting via tinfl_init() it it'll just keep on returning the same status failure code. */
87 TINFL_STATUS_FAILED = -1,
89 /* Any status code less than TINFL_STATUS_DONE must indicate a failure. */
91 /* This flag indicates the inflator has returned every byte of uncompressed data that it can, has consumed every byte that it needed, has successfully reached the end of the deflate stream, and */
92 /* if zlib headers and adler32 checking enabled that it has successfully checked the uncompressed data's adler32. If you call it again you'll just get TINFL_STATUS_DONE over and over again. */
93 TINFL_STATUS_DONE = 0,
95 /* This flag indicates the inflator MUST have more input data (even 1 byte) before it can make any more forward progress, or you need to clear the TINFL_FLAG_HAS_MORE_INPUT */
96 /* flag on the next call if you don't have any more source data. If the source data was somehow corrupted it's also possible (but unlikely) for the inflator to keep on demanding input to */
97 /* proceed, so be sure to properly set the TINFL_FLAG_HAS_MORE_INPUT flag. */
98 TINFL_STATUS_NEEDS_MORE_INPUT = 1,
100 /* This flag indicates the inflator definitely has 1 or more bytes of uncompressed data available, but it cannot write this data into the output buffer. */
101 /* Note if the source compressed data was corrupted it's possible for the inflator to return a lot of uncompressed data to the caller. I've been assuming you know how much uncompressed data to expect */
102 /* (either exact or worst case) and will stop calling the inflator and fail after receiving too much. In pure streaming scenarios where you have no idea how many bytes to expect this may not be possible */
103 /* so I may need to add some code to address this. */
104 TINFL_STATUS_HAS_MORE_OUTPUT = 2
105 } tinfl_status;
107 #define MZ_MACRO_END while (0)
108 #define MZ_READ_LE16(p) ((mz_uint32)(((const mz_uint8 *)(p))[0]) | ((mz_uint32)(((const mz_uint8 *)(p))[1]) << 8U))
109 #define MZ_READ_LE32(p) ((mz_uint32)(((const mz_uint8 *)(p))[0]) | ((mz_uint32)(((const mz_uint8 *)(p))[1]) << 8U) | ((mz_uint32)(((const mz_uint8 *)(p))[2]) << 16U) | ((mz_uint32)(((const mz_uint8 *)(p))[3]) << 24U))
111 #define TINFL_DECOMPRESS_MEM_TO_MEM_FAILED ((size_t)(-1))
113 #if 0
114 #include <assert.h>
115 #define MZ_ASSERT(X) assert(X)
116 #else
117 #define MZ_ASSERT(X)
118 #endif
120 /* Initializes the decompressor to its initial state. */
121 #define tinfl_init(r) \
122 do \
124 (r)->m_state = 0; \
126 MZ_MACRO_END
128 typedef int (*tinfl_put_buf_func_ptr)(const void *pBuf, int len, void *pUser);
130 /* Max size of LZ dictionary. */
131 #define TINFL_LZ_DICT_SIZE 32768
133 #endif