aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2024-07-29 14:30:50 -0700
committerMark Adler <madler@alumni.caltech.edu>2024-07-29 14:30:50 -0700
commit164b8e3c9f02e2680dfad35f8c0778f8f2ce3096 (patch)
treee6fcf4ab68cd7b8145c1b3abfd37f6534674e3c5 /examples
parent3f44e55d5d3a3c094861b3d00f0e136fa1956be9 (diff)
downloadzlib-164b8e3c9f02e2680dfad35f8c0778f8f2ce3096.tar.gz
zlib-164b8e3c9f02e2680dfad35f8c0778f8f2ce3096.tar.bz2
zlib-164b8e3c9f02e2680dfad35f8c0778f8f2ce3096.zip
Avoid use of uintmax_t in enough.c.
Diffstat (limited to 'examples')
-rw-r--r--examples/enough.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/examples/enough.c b/examples/enough.c
index 8a3cade..43112a4 100644
--- a/examples/enough.c
+++ b/examples/enough.c
@@ -1,7 +1,7 @@
1/* enough.c -- determine the maximum size of inflate's Huffman code tables over 1/* enough.c -- determine the maximum size of inflate's Huffman code tables over
2 * all possible valid and complete prefix codes, subject to a length limit. 2 * all possible valid and complete prefix codes, subject to a length limit.
3 * Copyright (C) 2007, 2008, 2012, 2018 Mark Adler 3 * Copyright (C) 2007, 2008, 2012, 2018, 2024 Mark Adler
4 * Version 1.5 5 August 2018 Mark Adler 4 * Version 1.6 29 July 2024 Mark Adler
5 */ 5 */
6 6
7/* Version history: 7/* Version history:
@@ -19,6 +19,7 @@
19 Clean up code indentation 19 Clean up code indentation
20 1.5 5 Aug 2018 Clean up code style, formatting, and comments 20 1.5 5 Aug 2018 Clean up code style, formatting, and comments
21 Show all the codes for the maximum, and only the maximum 21 Show all the codes for the maximum, and only the maximum
22 1.6 29 Jul 2024 Avoid use of uintmax_t
22 */ 23 */
23 24
24/* 25/*
@@ -88,33 +89,32 @@
88 need to be examined to cover all of the possible table memory usage cases 89 need to be examined to cover all of the possible table memory usage cases
89 for the default arguments of 286 symbols limited to 15-bit codes. 90 for the default arguments of 286 symbols limited to 15-bit codes.
90 91
91 Note that the uintmax_t type is used for counting. It is quite easy to 92 Note that unsigned long long is used for counting. It is quite easy to
92 exceed the capacity of an eight-byte integer with a large number of symbols 93 exceed the capacity of an eight-byte integer with a large number of symbols
93 and a large maximum code length, so multiple-precision arithmetic would need 94 and a large maximum code length, so multiple-precision arithmetic would need
94 to replace the integer arithmetic in that case. This program will abort if 95 to replace the integer arithmetic in that case. This program will abort if
95 an overflow occurs. The big_t type identifies where the counting takes 96 an overflow occurs. The big_t type identifies where the counting takes
96 place. 97 place.
97 98
98 The uintmax_t type is also used for calculating the number of possible codes 99 The unsigned long long type is also used for calculating the number of
99 remaining at the maximum length. This limits the maximum code length to the 100 possible codes remaining at the maximum length. This limits the maximum code
100 number of bits in a long long minus the number of bits needed to represent 101 length to the number of bits in a long long minus the number of bits needed
101 the symbols in a flat code. The code_t type identifies where the bit-pattern 102 to represent the symbols in a flat code. The code_t type identifies where
102 counting takes place. 103 the bit-pattern counting takes place.
103 */ 104 */
104 105
105#include <stdio.h> 106#include <stdio.h>
106#include <stdlib.h> 107#include <stdlib.h>
107#include <string.h> 108#include <string.h>
108#include <stdarg.h> 109#include <stdarg.h>
109#include <stdint.h>
110#include <assert.h> 110#include <assert.h>
111 111
112#define local static 112#define local static
113 113
114// Special data types. 114// Special data types.
115typedef uintmax_t big_t; // type for code counting 115typedef unsigned long long big_t; // type for code counting
116#define PRIbig "ju" // printf format for big_t 116#define PRIbig "llu" // printf format for big_t
117typedef uintmax_t code_t; // type for bit pattern counting 117typedef big_t code_t; // type for bit pattern counting
118struct tab { // type for been-here check 118struct tab { // type for been-here check
119 size_t len; // allocated length of bit vector in octets 119 size_t len; // allocated length of bit vector in octets
120 char *vec; // allocated bit vector 120 char *vec; // allocated bit vector