/src/CMake/Utilities/cmlibarchive/libarchive/archive_integer.h
Line | Count | Source |
1 | | /*- |
2 | | * Copyright (c) 2026 Tobias Stoeckmann |
3 | | * All rights reserved. |
4 | | * |
5 | | * Redistribution and use in source and binary forms, with or without |
6 | | * modification, are permitted provided that the following conditions |
7 | | * are met: |
8 | | * 1. Redistributions of source code must retain the above copyright |
9 | | * notice, this list of conditions and the following disclaimer. |
10 | | * 2. Redistributions in binary form must reproduce the above copyright |
11 | | * notice, this list of conditions and the following disclaimer in the |
12 | | * documentation and/or other materials provided with the distribution. |
13 | | * |
14 | | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
15 | | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
16 | | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
17 | | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
18 | | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
19 | | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
20 | | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
21 | | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
22 | | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
23 | | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
24 | | * SUCH DAMAGE. |
25 | | */ |
26 | | |
27 | | #ifndef ARCHIVE_INTEGER_H_INCLUDED |
28 | | #define ARCHIVE_INTEGER_H_INCLUDED |
29 | | |
30 | | #ifdef CM_PARSE_DATE |
31 | | #define HAVE_STDINT_H 1 |
32 | | #define USE_STDCKDINT 0 |
33 | | #else |
34 | | #include "archive_platform.h" |
35 | | |
36 | | /* Note: This is a purely internal header! */ |
37 | | /* Do not use this outside of libarchive internal code! */ |
38 | | |
39 | | #ifndef __LIBARCHIVE_BUILD |
40 | | #error This header is only to be used internally to libarchive. |
41 | | #endif |
42 | | #endif |
43 | | |
44 | | #ifdef HAVE_INTSAFE_H |
45 | | #define ENABLE_INTSAFE_SIGNED_FUNCTIONS |
46 | | #include <intsafe.h> |
47 | | #endif |
48 | | #ifdef HAVE_LIMITS_H |
49 | | #include <limits.h> |
50 | | #endif |
51 | | #ifdef HAVE_STDCKDINT_H |
52 | | #include <stdckdint.h> |
53 | | #endif |
54 | | #ifdef HAVE_STDINT_H |
55 | | #include <stdint.h> |
56 | | #endif |
57 | | #ifdef HAVE_TIME_H |
58 | | #include <time.h> |
59 | | #endif |
60 | | #ifdef HAVE_UNISTD_H |
61 | | #include <unistd.h> |
62 | | #endif |
63 | | |
64 | | #ifndef __has_builtin |
65 | | #define __has_builtin(x) 0 |
66 | | #endif |
67 | | |
68 | | #ifdef HAVE_STDCKDINT_H |
69 | | #define USE_STDCKDINT 1 |
70 | | #elif (__GNUC__ >= 5 && !defined(__INTEL_COMPILER)) |
71 | | #define USE_BUILTIN 1 |
72 | | #elif __has_builtin(__builtin_add_overflow) |
73 | | #define USE_BUILTIN 1 |
74 | | #elif defined HAVE_INTSAFE_H |
75 | | #define USE_INTSAFE 1 |
76 | | #endif |
77 | | |
78 | | /* |
79 | | * Disabling inline keyword for compilers known to choke on it: |
80 | | * - Watcom C++ in C code. (For any version?) |
81 | | * - SGI MIPSpro |
82 | | * - Microsoft Visual C++ 6.0 (supposedly newer versions too) |
83 | | * - IBM VisualAge 6 (XL v6) |
84 | | * - Sun WorkShop C (SunPro) before 5.9 |
85 | | */ |
86 | | #if defined(__WATCOMC__) || defined(__sgi) || defined(__hpux) || defined(__BORLANDC__) |
87 | | #define inline |
88 | | #elif defined(__IBMC__) && __IBMC__ < 700 |
89 | | #define inline |
90 | | #elif defined(__SUNPRO_C) && __SUNPRO_C < 0x590 |
91 | | #define inline |
92 | | #elif defined(_MSC_VER) || defined(__osf__) |
93 | | #define inline __inline |
94 | | #endif |
95 | | |
96 | | /* Returns 0 on success, a non-zero value otherwise. */ |
97 | | static inline int |
98 | | archive_ckd_add_i64(int64_t *result, int64_t a, int64_t b) |
99 | 224k | { |
100 | 224k | #if USE_STDCKDINT |
101 | 224k | return ckd_add(result, a, b); |
102 | | #elif USE_BUILTIN |
103 | | return __builtin_add_overflow(a, b, result); |
104 | | #elif USE_INTSAFE |
105 | | LONGLONG res; |
106 | | int ret; |
107 | | |
108 | | ret = LongLongAdd(a, b, &res); |
109 | | *result = (int64_t)res; |
110 | | return ret; |
111 | | #else |
112 | | if ((b > 0 && a > INT64_MAX - b) || |
113 | | (b < 0 && a < INT64_MIN - b)) |
114 | | return 1; |
115 | | |
116 | | *result = a + b; |
117 | | return 0; |
118 | | #endif |
119 | 224k | } Unexecuted instantiation: cm_parse_date.c:archive_ckd_add_i64 Unexecuted instantiation: archive_match.c:archive_ckd_add_i64 Unexecuted instantiation: archive_parse_date.c:archive_ckd_add_i64 Unexecuted instantiation: archive_read.c:archive_ckd_add_i64 Unexecuted instantiation: archive_read_disk_set_standard_lookup.c:archive_ckd_add_i64 Unexecuted instantiation: archive_read_support_filter_lz4.c:archive_ckd_add_i64 Unexecuted instantiation: archive_read_support_filter_zstd.c:archive_ckd_add_i64 Unexecuted instantiation: archive_read_support_format_ar.c:archive_ckd_add_i64 Unexecuted instantiation: archive_read_support_format_iso9660.c:archive_ckd_add_i64 archive_read_support_format_mtree.c:archive_ckd_add_i64 Line | Count | Source | 99 | 20.2k | { | 100 | 20.2k | #if USE_STDCKDINT | 101 | 20.2k | return ckd_add(result, a, b); | 102 | | #elif USE_BUILTIN | 103 | | return __builtin_add_overflow(a, b, result); | 104 | | #elif USE_INTSAFE | 105 | | LONGLONG res; | 106 | | int ret; | 107 | | | 108 | | ret = LongLongAdd(a, b, &res); | 109 | | *result = (int64_t)res; | 110 | | return ret; | 111 | | #else | 112 | | if ((b > 0 && a > INT64_MAX - b) || | 113 | | (b < 0 && a < INT64_MIN - b)) | 114 | | return 1; | 115 | | | 116 | | *result = a + b; | 117 | | return 0; | 118 | | #endif | 119 | 20.2k | } |
Unexecuted instantiation: archive_read_support_format_rar.c:archive_ckd_add_i64 Unexecuted instantiation: archive_read_support_format_rar5.c:archive_ckd_add_i64 Unexecuted instantiation: archive_read_support_format_raw.c:archive_ckd_add_i64 archive_read_support_format_tar.c:archive_ckd_add_i64 Line | Count | Source | 99 | 204k | { | 100 | 204k | #if USE_STDCKDINT | 101 | 204k | return ckd_add(result, a, b); | 102 | | #elif USE_BUILTIN | 103 | | return __builtin_add_overflow(a, b, result); | 104 | | #elif USE_INTSAFE | 105 | | LONGLONG res; | 106 | | int ret; | 107 | | | 108 | | ret = LongLongAdd(a, b, &res); | 109 | | *result = (int64_t)res; | 110 | | return ret; | 111 | | #else | 112 | | if ((b > 0 && a > INT64_MAX - b) || | 113 | | (b < 0 && a < INT64_MIN - b)) | 114 | | return 1; | 115 | | | 116 | | *result = a + b; | 117 | | return 0; | 118 | | #endif | 119 | 204k | } |
Unexecuted instantiation: archive_read_support_format_warc.c:archive_ckd_add_i64 Unexecuted instantiation: archive_read_support_format_xar.c:archive_ckd_add_i64 Unexecuted instantiation: archive_time.c:archive_ckd_add_i64 Unexecuted instantiation: archive_write_set_format_cpio_binary.c:archive_ckd_add_i64 Unexecuted instantiation: archive_write_set_format_cpio_odc.c:archive_ckd_add_i64 Unexecuted instantiation: archive_write_set_format_pax.c:archive_ckd_add_i64 Unexecuted instantiation: archive_write_set_format_zip.c:archive_ckd_add_i64 Unexecuted instantiation: archive_entry_link_resolver.c:archive_ckd_add_i64 archive_read_support_format_7zip.c:archive_ckd_add_i64 Line | Count | Source | 99 | 156 | { | 100 | 156 | #if USE_STDCKDINT | 101 | 156 | return ckd_add(result, a, b); | 102 | | #elif USE_BUILTIN | 103 | | return __builtin_add_overflow(a, b, result); | 104 | | #elif USE_INTSAFE | 105 | | LONGLONG res; | 106 | | int ret; | 107 | | | 108 | | ret = LongLongAdd(a, b, &res); | 109 | | *result = (int64_t)res; | 110 | | return ret; | 111 | | #else | 112 | | if ((b > 0 && a > INT64_MAX - b) || | 113 | | (b < 0 && a < INT64_MIN - b)) | 114 | | return 1; | 115 | | | 116 | | *result = a + b; | 117 | | return 0; | 118 | | #endif | 119 | 156 | } |
|
120 | | |
121 | | /* Returns 0 on success, a non-zero value otherwise. */ |
122 | | static inline int |
123 | | archive_ckd_add_size(size_t *result, size_t a, size_t b) |
124 | 888 | { |
125 | 888 | #if USE_STDCKDINT |
126 | 888 | return ckd_add(result, a, b); |
127 | | #elif USE_BUILTIN |
128 | | return __builtin_add_overflow(a, b, result); |
129 | | #elif USE_INTSAFE |
130 | | return SizeTAdd(a, b, result); |
131 | | #else |
132 | | if (a > SIZE_MAX - b) |
133 | | return 1; |
134 | | *result = a + b; |
135 | | return 0; |
136 | | #endif |
137 | 888 | } Unexecuted instantiation: cm_parse_date.c:archive_ckd_add_size Unexecuted instantiation: archive_match.c:archive_ckd_add_size Unexecuted instantiation: archive_parse_date.c:archive_ckd_add_size Unexecuted instantiation: archive_read.c:archive_ckd_add_size Unexecuted instantiation: archive_read_disk_set_standard_lookup.c:archive_ckd_add_size archive_read_support_filter_lz4.c:archive_ckd_add_size Line | Count | Source | 124 | 376 | { | 125 | 376 | #if USE_STDCKDINT | 126 | 376 | return ckd_add(result, a, b); | 127 | | #elif USE_BUILTIN | 128 | | return __builtin_add_overflow(a, b, result); | 129 | | #elif USE_INTSAFE | 130 | | return SizeTAdd(a, b, result); | 131 | | #else | 132 | | if (a > SIZE_MAX - b) | 133 | | return 1; | 134 | | *result = a + b; | 135 | | return 0; | 136 | | #endif | 137 | 376 | } |
archive_read_support_filter_zstd.c:archive_ckd_add_size Line | Count | Source | 124 | 512 | { | 125 | 512 | #if USE_STDCKDINT | 126 | 512 | return ckd_add(result, a, b); | 127 | | #elif USE_BUILTIN | 128 | | return __builtin_add_overflow(a, b, result); | 129 | | #elif USE_INTSAFE | 130 | | return SizeTAdd(a, b, result); | 131 | | #else | 132 | | if (a > SIZE_MAX - b) | 133 | | return 1; | 134 | | *result = a + b; | 135 | | return 0; | 136 | | #endif | 137 | 512 | } |
Unexecuted instantiation: archive_read_support_format_ar.c:archive_ckd_add_size Unexecuted instantiation: archive_read_support_format_iso9660.c:archive_ckd_add_size Unexecuted instantiation: archive_read_support_format_mtree.c:archive_ckd_add_size Unexecuted instantiation: archive_read_support_format_rar.c:archive_ckd_add_size Unexecuted instantiation: archive_read_support_format_rar5.c:archive_ckd_add_size Unexecuted instantiation: archive_read_support_format_raw.c:archive_ckd_add_size Unexecuted instantiation: archive_read_support_format_tar.c:archive_ckd_add_size Unexecuted instantiation: archive_read_support_format_warc.c:archive_ckd_add_size Unexecuted instantiation: archive_read_support_format_xar.c:archive_ckd_add_size Unexecuted instantiation: archive_time.c:archive_ckd_add_size Unexecuted instantiation: archive_write_set_format_cpio_binary.c:archive_ckd_add_size Unexecuted instantiation: archive_write_set_format_cpio_odc.c:archive_ckd_add_size Unexecuted instantiation: archive_write_set_format_pax.c:archive_ckd_add_size Unexecuted instantiation: archive_write_set_format_zip.c:archive_ckd_add_size Unexecuted instantiation: archive_entry_link_resolver.c:archive_ckd_add_size Unexecuted instantiation: archive_read_support_format_7zip.c:archive_ckd_add_size |
138 | | |
139 | | /* Returns 0 on success, a non-zero value otherwise. */ |
140 | | static inline int |
141 | | archive_ckd_add_u64(uint64_t *result, uint64_t a, uint64_t b) |
142 | 5.25k | { |
143 | | #if USE_STDCKDINT |
144 | | return ckd_add(result, a, b); |
145 | | #elif USE_BUILTIN |
146 | | return __builtin_add_overflow(a, b, result); |
147 | | #elif USE_INTSAFE |
148 | | ULONGLONG res; |
149 | | int ret; |
150 | | |
151 | | ret = ULongLongAdd(a, b, &res); |
152 | | *result = (uint64_t)res; |
153 | | return ret; |
154 | | #else |
155 | | if (a > UINT64_MAX - b) |
156 | | return 1; |
157 | | *result = a + b; |
158 | | return 0; |
159 | | #endif |
160 | 5.25k | } Unexecuted instantiation: cm_parse_date.c:archive_ckd_add_u64 Unexecuted instantiation: archive_match.c:archive_ckd_add_u64 Unexecuted instantiation: archive_parse_date.c:archive_ckd_add_u64 Unexecuted instantiation: archive_read.c:archive_ckd_add_u64 Unexecuted instantiation: archive_read_disk_set_standard_lookup.c:archive_ckd_add_u64 Unexecuted instantiation: archive_read_support_filter_lz4.c:archive_ckd_add_u64 Unexecuted instantiation: archive_read_support_filter_zstd.c:archive_ckd_add_u64 archive_read_support_format_ar.c:archive_ckd_add_u64 Line | Count | Source | 142 | 4.83k | { | 143 | 4.83k | #if USE_STDCKDINT | 144 | 4.83k | return ckd_add(result, a, b); | 145 | | #elif USE_BUILTIN | 146 | | return __builtin_add_overflow(a, b, result); | 147 | | #elif USE_INTSAFE | 148 | | ULONGLONG res; | 149 | | int ret; | 150 | | | 151 | | ret = ULongLongAdd(a, b, &res); | 152 | | *result = (uint64_t)res; | 153 | | return ret; | 154 | | #else | 155 | | if (a > UINT64_MAX - b) | 156 | | return 1; | 157 | | *result = a + b; | 158 | | return 0; | 159 | | #endif | 160 | 4.83k | } |
Unexecuted instantiation: archive_read_support_format_iso9660.c:archive_ckd_add_u64 Unexecuted instantiation: archive_read_support_format_mtree.c:archive_ckd_add_u64 Unexecuted instantiation: archive_read_support_format_rar.c:archive_ckd_add_u64 archive_read_support_format_rar5.c:archive_ckd_add_u64 Line | Count | Source | 142 | 422 | { | 143 | 422 | #if USE_STDCKDINT | 144 | 422 | return ckd_add(result, a, b); | 145 | | #elif USE_BUILTIN | 146 | | return __builtin_add_overflow(a, b, result); | 147 | | #elif USE_INTSAFE | 148 | | ULONGLONG res; | 149 | | int ret; | 150 | | | 151 | | ret = ULongLongAdd(a, b, &res); | 152 | | *result = (uint64_t)res; | 153 | | return ret; | 154 | | #else | 155 | | if (a > UINT64_MAX - b) | 156 | | return 1; | 157 | | *result = a + b; | 158 | | return 0; | 159 | | #endif | 160 | 422 | } |
Unexecuted instantiation: archive_read_support_format_raw.c:archive_ckd_add_u64 Unexecuted instantiation: archive_read_support_format_tar.c:archive_ckd_add_u64 Unexecuted instantiation: archive_read_support_format_warc.c:archive_ckd_add_u64 Unexecuted instantiation: archive_read_support_format_xar.c:archive_ckd_add_u64 Unexecuted instantiation: archive_time.c:archive_ckd_add_u64 Unexecuted instantiation: archive_write_set_format_cpio_binary.c:archive_ckd_add_u64 Unexecuted instantiation: archive_write_set_format_cpio_odc.c:archive_ckd_add_u64 Unexecuted instantiation: archive_write_set_format_pax.c:archive_ckd_add_u64 Unexecuted instantiation: archive_write_set_format_zip.c:archive_ckd_add_u64 Unexecuted instantiation: archive_entry_link_resolver.c:archive_ckd_add_u64 Unexecuted instantiation: archive_read_support_format_7zip.c:archive_ckd_add_u64 |
161 | | |
162 | | /* Returns 0 on success, a non-zero value otherwise. */ |
163 | | static inline int |
164 | | archive_ckd_mul_i64(int64_t *result, int64_t a, int64_t b) |
165 | 247k | { |
166 | 247k | #if USE_STDCKDINT |
167 | 247k | return ckd_mul(result, a, b); |
168 | | #elif USE_BUILTIN |
169 | | return __builtin_mul_overflow(a, b, result); |
170 | | #elif USE_INTSAFE |
171 | | LONGLONG res; |
172 | | int ret; |
173 | | |
174 | | ret = LongLongMult(a, b, &res); |
175 | | *result = (int64_t)res; |
176 | | return ret; |
177 | | #else |
178 | | if ((a > 0 && b > 0 && a > INT64_MAX / b) || |
179 | | (a < 0 && b > 0 && a < INT64_MIN / b) || |
180 | | (a > 0 && b < 0 && b < INT64_MIN / a) || |
181 | | (a < 0 && b < 0 && a < INT64_MAX / b)) |
182 | | return 1; |
183 | | |
184 | | *result = a * b; |
185 | | return 0; |
186 | | #endif |
187 | 247k | } Unexecuted instantiation: cm_parse_date.c:archive_ckd_mul_i64 Unexecuted instantiation: archive_match.c:archive_ckd_mul_i64 Unexecuted instantiation: archive_parse_date.c:archive_ckd_mul_i64 Unexecuted instantiation: archive_read.c:archive_ckd_mul_i64 Unexecuted instantiation: archive_read_disk_set_standard_lookup.c:archive_ckd_mul_i64 Unexecuted instantiation: archive_read_support_filter_lz4.c:archive_ckd_mul_i64 Unexecuted instantiation: archive_read_support_filter_zstd.c:archive_ckd_mul_i64 Unexecuted instantiation: archive_read_support_format_ar.c:archive_ckd_mul_i64 Unexecuted instantiation: archive_read_support_format_iso9660.c:archive_ckd_mul_i64 archive_read_support_format_mtree.c:archive_ckd_mul_i64 Line | Count | Source | 165 | 43.3k | { | 166 | 43.3k | #if USE_STDCKDINT | 167 | 43.3k | return ckd_mul(result, a, b); | 168 | | #elif USE_BUILTIN | 169 | | return __builtin_mul_overflow(a, b, result); | 170 | | #elif USE_INTSAFE | 171 | | LONGLONG res; | 172 | | int ret; | 173 | | | 174 | | ret = LongLongMult(a, b, &res); | 175 | | *result = (int64_t)res; | 176 | | return ret; | 177 | | #else | 178 | | if ((a > 0 && b > 0 && a > INT64_MAX / b) || | 179 | | (a < 0 && b > 0 && a < INT64_MIN / b) || | 180 | | (a > 0 && b < 0 && b < INT64_MIN / a) || | 181 | | (a < 0 && b < 0 && a < INT64_MAX / b)) | 182 | | return 1; | 183 | | | 184 | | *result = a * b; | 185 | | return 0; | 186 | | #endif | 187 | 43.3k | } |
Unexecuted instantiation: archive_read_support_format_rar.c:archive_ckd_mul_i64 Unexecuted instantiation: archive_read_support_format_rar5.c:archive_ckd_mul_i64 Unexecuted instantiation: archive_read_support_format_raw.c:archive_ckd_mul_i64 archive_read_support_format_tar.c:archive_ckd_mul_i64 Line | Count | Source | 165 | 204k | { | 166 | 204k | #if USE_STDCKDINT | 167 | 204k | return ckd_mul(result, a, b); | 168 | | #elif USE_BUILTIN | 169 | | return __builtin_mul_overflow(a, b, result); | 170 | | #elif USE_INTSAFE | 171 | | LONGLONG res; | 172 | | int ret; | 173 | | | 174 | | ret = LongLongMult(a, b, &res); | 175 | | *result = (int64_t)res; | 176 | | return ret; | 177 | | #else | 178 | | if ((a > 0 && b > 0 && a > INT64_MAX / b) || | 179 | | (a < 0 && b > 0 && a < INT64_MIN / b) || | 180 | | (a > 0 && b < 0 && b < INT64_MIN / a) || | 181 | | (a < 0 && b < 0 && a < INT64_MAX / b)) | 182 | | return 1; | 183 | | | 184 | | *result = a * b; | 185 | | return 0; | 186 | | #endif | 187 | 204k | } |
Unexecuted instantiation: archive_read_support_format_warc.c:archive_ckd_mul_i64 Unexecuted instantiation: archive_read_support_format_xar.c:archive_ckd_mul_i64 Unexecuted instantiation: archive_time.c:archive_ckd_mul_i64 Unexecuted instantiation: archive_write_set_format_cpio_binary.c:archive_ckd_mul_i64 Unexecuted instantiation: archive_write_set_format_cpio_odc.c:archive_ckd_mul_i64 Unexecuted instantiation: archive_write_set_format_pax.c:archive_ckd_mul_i64 Unexecuted instantiation: archive_write_set_format_zip.c:archive_ckd_mul_i64 Unexecuted instantiation: archive_entry_link_resolver.c:archive_ckd_mul_i64 Unexecuted instantiation: archive_read_support_format_7zip.c:archive_ckd_mul_i64 |
188 | | |
189 | | /* Returns 0 on success, a non-zero value otherwise. */ |
190 | | static inline int |
191 | | archive_ckd_mul_size(size_t *result, size_t a, size_t b) |
192 | 43.6k | { |
193 | 43.6k | #if USE_STDCKDINT |
194 | 43.6k | return ckd_mul(result, a, b); |
195 | | #elif USE_BUILTIN |
196 | | return __builtin_mul_overflow(a, b, result); |
197 | | #elif USE_INTSAFE |
198 | | return SizeTMult(a, b, result); |
199 | | #else |
200 | | if (b != 0 && a > SIZE_MAX / b) |
201 | | return 1; |
202 | | *result = a * b; |
203 | | return 0; |
204 | | #endif |
205 | 43.6k | } Unexecuted instantiation: cm_parse_date.c:archive_ckd_mul_size Unexecuted instantiation: archive_match.c:archive_ckd_mul_size Unexecuted instantiation: archive_parse_date.c:archive_ckd_mul_size archive_read.c:archive_ckd_mul_size Line | Count | Source | 192 | 43.6k | { | 193 | 43.6k | #if USE_STDCKDINT | 194 | 43.6k | return ckd_mul(result, a, b); | 195 | | #elif USE_BUILTIN | 196 | | return __builtin_mul_overflow(a, b, result); | 197 | | #elif USE_INTSAFE | 198 | | return SizeTMult(a, b, result); | 199 | | #else | 200 | | if (b != 0 && a > SIZE_MAX / b) | 201 | | return 1; | 202 | | *result = a * b; | 203 | | return 0; | 204 | | #endif | 205 | 43.6k | } |
Unexecuted instantiation: archive_read_disk_set_standard_lookup.c:archive_ckd_mul_size Unexecuted instantiation: archive_read_support_filter_lz4.c:archive_ckd_mul_size Unexecuted instantiation: archive_read_support_filter_zstd.c:archive_ckd_mul_size Unexecuted instantiation: archive_read_support_format_ar.c:archive_ckd_mul_size Unexecuted instantiation: archive_read_support_format_iso9660.c:archive_ckd_mul_size Unexecuted instantiation: archive_read_support_format_mtree.c:archive_ckd_mul_size Unexecuted instantiation: archive_read_support_format_rar.c:archive_ckd_mul_size Unexecuted instantiation: archive_read_support_format_rar5.c:archive_ckd_mul_size Unexecuted instantiation: archive_read_support_format_raw.c:archive_ckd_mul_size Unexecuted instantiation: archive_read_support_format_tar.c:archive_ckd_mul_size Unexecuted instantiation: archive_read_support_format_warc.c:archive_ckd_mul_size Unexecuted instantiation: archive_read_support_format_xar.c:archive_ckd_mul_size Unexecuted instantiation: archive_time.c:archive_ckd_mul_size Unexecuted instantiation: archive_write_set_format_cpio_binary.c:archive_ckd_mul_size Unexecuted instantiation: archive_write_set_format_cpio_odc.c:archive_ckd_mul_size Unexecuted instantiation: archive_write_set_format_pax.c:archive_ckd_mul_size Unexecuted instantiation: archive_write_set_format_zip.c:archive_ckd_mul_size Unexecuted instantiation: archive_entry_link_resolver.c:archive_ckd_mul_size Unexecuted instantiation: archive_read_support_format_7zip.c:archive_ckd_mul_size |
206 | | |
207 | | /* Returns 0 on success, a non-zero value otherwise. */ |
208 | | static inline int |
209 | | archive_ckd_mul_u64(uint64_t *result, uint64_t a, uint64_t b) |
210 | 5.26k | { |
211 | | #if USE_STDCKDINT |
212 | | return ckd_mul(result, a, b); |
213 | | #elif USE_BUILTIN |
214 | | return __builtin_mul_overflow(a, b, result); |
215 | | #elif USE_INTSAFE |
216 | | ULONGLONG res; |
217 | | int ret; |
218 | | |
219 | | ret = ULongLongMult(a, b, &res); |
220 | | *result = (uint64_t)res; |
221 | | return ret; |
222 | | #else |
223 | | if (b != 0 && a > UINT64_MAX / b) |
224 | | return 1; |
225 | | *result = a * b; |
226 | | return 0; |
227 | | #endif |
228 | 5.26k | } Unexecuted instantiation: cm_parse_date.c:archive_ckd_mul_u64 Unexecuted instantiation: archive_match.c:archive_ckd_mul_u64 Unexecuted instantiation: archive_parse_date.c:archive_ckd_mul_u64 Unexecuted instantiation: archive_read.c:archive_ckd_mul_u64 Unexecuted instantiation: archive_read_disk_set_standard_lookup.c:archive_ckd_mul_u64 Unexecuted instantiation: archive_read_support_filter_lz4.c:archive_ckd_mul_u64 Unexecuted instantiation: archive_read_support_filter_zstd.c:archive_ckd_mul_u64 archive_read_support_format_ar.c:archive_ckd_mul_u64 Line | Count | Source | 210 | 4.83k | { | 211 | 4.83k | #if USE_STDCKDINT | 212 | 4.83k | return ckd_mul(result, a, b); | 213 | | #elif USE_BUILTIN | 214 | | return __builtin_mul_overflow(a, b, result); | 215 | | #elif USE_INTSAFE | 216 | | ULONGLONG res; | 217 | | int ret; | 218 | | | 219 | | ret = ULongLongMult(a, b, &res); | 220 | | *result = (uint64_t)res; | 221 | | return ret; | 222 | | #else | 223 | | if (b != 0 && a > UINT64_MAX / b) | 224 | | return 1; | 225 | | *result = a * b; | 226 | | return 0; | 227 | | #endif | 228 | 4.83k | } |
Unexecuted instantiation: archive_read_support_format_iso9660.c:archive_ckd_mul_u64 Unexecuted instantiation: archive_read_support_format_mtree.c:archive_ckd_mul_u64 Unexecuted instantiation: archive_read_support_format_rar.c:archive_ckd_mul_u64 archive_read_support_format_rar5.c:archive_ckd_mul_u64 Line | Count | Source | 210 | 432 | { | 211 | 432 | #if USE_STDCKDINT | 212 | 432 | return ckd_mul(result, a, b); | 213 | | #elif USE_BUILTIN | 214 | | return __builtin_mul_overflow(a, b, result); | 215 | | #elif USE_INTSAFE | 216 | | ULONGLONG res; | 217 | | int ret; | 218 | | | 219 | | ret = ULongLongMult(a, b, &res); | 220 | | *result = (uint64_t)res; | 221 | | return ret; | 222 | | #else | 223 | | if (b != 0 && a > UINT64_MAX / b) | 224 | | return 1; | 225 | | *result = a * b; | 226 | | return 0; | 227 | | #endif | 228 | 432 | } |
Unexecuted instantiation: archive_read_support_format_raw.c:archive_ckd_mul_u64 Unexecuted instantiation: archive_read_support_format_tar.c:archive_ckd_mul_u64 Unexecuted instantiation: archive_read_support_format_warc.c:archive_ckd_mul_u64 Unexecuted instantiation: archive_read_support_format_xar.c:archive_ckd_mul_u64 Unexecuted instantiation: archive_time.c:archive_ckd_mul_u64 Unexecuted instantiation: archive_write_set_format_cpio_binary.c:archive_ckd_mul_u64 Unexecuted instantiation: archive_write_set_format_cpio_odc.c:archive_ckd_mul_u64 Unexecuted instantiation: archive_write_set_format_pax.c:archive_ckd_mul_u64 Unexecuted instantiation: archive_write_set_format_zip.c:archive_ckd_mul_u64 Unexecuted instantiation: archive_entry_link_resolver.c:archive_ckd_mul_u64 Unexecuted instantiation: archive_read_support_format_7zip.c:archive_ckd_mul_u64 |
229 | | |
230 | | /* Returns 0 on success, a non-zero value otherwise. */ |
231 | | static inline int |
232 | | archive_ckd_sub_i64(int64_t *result, int64_t a, int64_t b) |
233 | 23.0k | { |
234 | 23.0k | #if USE_STDCKDINT |
235 | 23.0k | return ckd_sub(result, a, b); |
236 | | #elif USE_BUILTIN |
237 | | return __builtin_sub_overflow(a, b, result); |
238 | | #elif USE_INTSAFE |
239 | | LONGLONG res; |
240 | | int ret; |
241 | | |
242 | | ret = LongLongSub(a, b, &res); |
243 | | *result = (int64_t)res; |
244 | | return ret; |
245 | | #else |
246 | | if ((b > 0 && a < INT64_MIN + b) || |
247 | | (b < 0 && a > INT64_MAX + b)) |
248 | | return 1; |
249 | | |
250 | | *result = a - b; |
251 | | return 0; |
252 | | #endif |
253 | 23.0k | } Unexecuted instantiation: cm_parse_date.c:archive_ckd_sub_i64 Unexecuted instantiation: archive_match.c:archive_ckd_sub_i64 Unexecuted instantiation: archive_parse_date.c:archive_ckd_sub_i64 Unexecuted instantiation: archive_read.c:archive_ckd_sub_i64 Unexecuted instantiation: archive_read_disk_set_standard_lookup.c:archive_ckd_sub_i64 Unexecuted instantiation: archive_read_support_filter_lz4.c:archive_ckd_sub_i64 Unexecuted instantiation: archive_read_support_filter_zstd.c:archive_ckd_sub_i64 Unexecuted instantiation: archive_read_support_format_ar.c:archive_ckd_sub_i64 Unexecuted instantiation: archive_read_support_format_iso9660.c:archive_ckd_sub_i64 archive_read_support_format_mtree.c:archive_ckd_sub_i64 Line | Count | Source | 233 | 23.0k | { | 234 | 23.0k | #if USE_STDCKDINT | 235 | 23.0k | return ckd_sub(result, a, b); | 236 | | #elif USE_BUILTIN | 237 | | return __builtin_sub_overflow(a, b, result); | 238 | | #elif USE_INTSAFE | 239 | | LONGLONG res; | 240 | | int ret; | 241 | | | 242 | | ret = LongLongSub(a, b, &res); | 243 | | *result = (int64_t)res; | 244 | | return ret; | 245 | | #else | 246 | | if ((b > 0 && a < INT64_MIN + b) || | 247 | | (b < 0 && a > INT64_MAX + b)) | 248 | | return 1; | 249 | | | 250 | | *result = a - b; | 251 | | return 0; | 252 | | #endif | 253 | 23.0k | } |
Unexecuted instantiation: archive_read_support_format_rar.c:archive_ckd_sub_i64 Unexecuted instantiation: archive_read_support_format_rar5.c:archive_ckd_sub_i64 Unexecuted instantiation: archive_read_support_format_raw.c:archive_ckd_sub_i64 Unexecuted instantiation: archive_read_support_format_tar.c:archive_ckd_sub_i64 Unexecuted instantiation: archive_read_support_format_warc.c:archive_ckd_sub_i64 Unexecuted instantiation: archive_read_support_format_xar.c:archive_ckd_sub_i64 Unexecuted instantiation: archive_time.c:archive_ckd_sub_i64 Unexecuted instantiation: archive_write_set_format_cpio_binary.c:archive_ckd_sub_i64 Unexecuted instantiation: archive_write_set_format_cpio_odc.c:archive_ckd_sub_i64 Unexecuted instantiation: archive_write_set_format_pax.c:archive_ckd_sub_i64 Unexecuted instantiation: archive_write_set_format_zip.c:archive_ckd_sub_i64 Unexecuted instantiation: archive_entry_link_resolver.c:archive_ckd_sub_i64 Unexecuted instantiation: archive_read_support_format_7zip.c:archive_ckd_sub_i64 |
254 | | |
255 | | #if !defined(TIME_MAX) |
256 | 7.91k | #define TIME_MAX (((time_t)0 < (time_t)-1) ? (time_t)~0 : \ |
257 | 7.91k | sizeof(time_t) == sizeof(long long) ? (time_t)LLONG_MAX : \ |
258 | 7.91k | sizeof(time_t) == sizeof(long) ? (time_t)LONG_MAX : \ |
259 | 0 | sizeof(time_t) == sizeof(int) ? (time_t)INT_MAX : \ |
260 | 0 | sizeof(time_t) == sizeof(short) ? (time_t)SHRT_MAX : \ |
261 | 0 | 1 /* I give up */) |
262 | | #endif |
263 | | #if !defined(TIME_MIN) |
264 | 7.91k | #define TIME_MIN (((time_t)0 < (time_t)-1) ? (time_t)0 : \ |
265 | 7.91k | sizeof(time_t) == sizeof(long long) ? (time_t)LLONG_MIN : \ |
266 | 7.91k | sizeof(time_t) == sizeof(long) ? (time_t)LONG_MIN : \ |
267 | 0 | sizeof(time_t) == sizeof(int) ? (time_t)INT_MIN : \ |
268 | 0 | sizeof(time_t) == sizeof(short) ? (time_t)SHRT_MIN : \ |
269 | 0 | -1 /* I give up */) |
270 | | #endif |
271 | | |
272 | | #endif |