/src/git/git-compat-util.h
Line | Count | Source |
1 | | #ifndef GIT_COMPAT_UTIL_H |
2 | | #define GIT_COMPAT_UTIL_H |
3 | | |
4 | | #if __STDC_VERSION__ - 0 < 199901L |
5 | | /* |
6 | | * Git is in a testing period for mandatory C99 support in the compiler. If |
7 | | * your compiler is reasonably recent, you can try to enable C99 support (or, |
8 | | * for MSVC, C11 support). If you encounter a problem and can't enable C99 |
9 | | * support with your compiler (such as with "-std=gnu99") and don't have access |
10 | | * to one with this support, such as GCC or Clang, you can remove this #if |
11 | | * directive, but please report the details of your system to |
12 | | * git@vger.kernel.org. |
13 | | */ |
14 | | #error "Required C99 support is in a test phase. Please see git-compat-util.h for more details." |
15 | | #endif |
16 | | |
17 | | #ifdef USE_MSVC_CRTDBG |
18 | | /* |
19 | | * For these to work they must appear very early in each |
20 | | * file -- before most of the standard header files. |
21 | | */ |
22 | | #include <stdlib.h> |
23 | | #include <crtdbg.h> |
24 | | #endif |
25 | | |
26 | | #include "compat/posix.h" |
27 | | |
28 | | struct strbuf; |
29 | | |
30 | | #if defined(__GNUC__) || defined(__clang__) |
31 | | # define PRAGMA(pragma) _Pragma(#pragma) |
32 | | # define DISABLE_WARNING(warning) PRAGMA(GCC diagnostic ignored #warning) |
33 | | #else |
34 | | # define DISABLE_WARNING(warning) |
35 | | #endif |
36 | | |
37 | | #undef FLEX_ARRAY |
38 | | #define FLEX_ARRAY /* empty - weather balloon to require C99 FAM */ |
39 | | |
40 | | /* |
41 | | * BUILD_ASSERT_OR_ZERO - assert a build-time dependency, as an expression. |
42 | | * @cond: the compile-time condition which must be true. |
43 | | * |
44 | | * Your compile will fail if the condition isn't true, or can't be evaluated |
45 | | * by the compiler. This can be used in an expression: its value is "0". |
46 | | * |
47 | | * Example: |
48 | | * #define foo_to_char(foo) \ |
49 | | * ((char *)(foo) \ |
50 | | * + BUILD_ASSERT_OR_ZERO(offsetof(struct foo, string) == 0)) |
51 | | */ |
52 | | #define BUILD_ASSERT_OR_ZERO(cond) \ |
53 | 0 | (sizeof(char [1 - 2*!(cond)]) - 1) |
54 | | |
55 | | #if GIT_GNUC_PREREQ(3, 1) |
56 | | /* &arr[0] degrades to a pointer: a different type from an array */ |
57 | | # define BARF_UNLESS_AN_ARRAY(arr) \ |
58 | 0 | BUILD_ASSERT_OR_ZERO(!__builtin_types_compatible_p(__typeof__(arr), \ |
59 | 0 | __typeof__(&(arr)[0]))) |
60 | | # define BARF_UNLESS_COPYABLE(dst, src) \ |
61 | 0 | BUILD_ASSERT_OR_ZERO(__builtin_types_compatible_p(__typeof__(*(dst)), \ |
62 | 0 | __typeof__(*(src)))) |
63 | | |
64 | 0 | # define BARF_UNLESS_SIGNED(var) BUILD_ASSERT_OR_ZERO(((__typeof__(var)) -1) < 0) |
65 | 0 | # define BARF_UNLESS_UNSIGNED(var) BUILD_ASSERT_OR_ZERO(((__typeof__(var)) -1) > 0) |
66 | | #else |
67 | | # define BARF_UNLESS_AN_ARRAY(arr) 0 |
68 | | # define BARF_UNLESS_COPYABLE(dst, src) \ |
69 | | BUILD_ASSERT_OR_ZERO(0 ? ((*(dst) = *(src)), 0) : \ |
70 | | sizeof(*(dst)) == sizeof(*(src))) |
71 | | |
72 | | # define BARF_UNLESS_SIGNED(var) 0 |
73 | | # define BARF_UNLESS_UNSIGNED(var) 0 |
74 | | #endif |
75 | | |
76 | | /* |
77 | | * ARRAY_SIZE - get the number of elements in a visible array |
78 | | * @x: the array whose size you want. |
79 | | * |
80 | | * This does not work on pointers, or arrays declared as [], or |
81 | | * function parameters. With correct compiler support, such usage |
82 | | * will cause a build error (see the build_assert_or_zero macro). |
83 | | */ |
84 | 0 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]) + BARF_UNLESS_AN_ARRAY(x)) |
85 | | |
86 | 418 | #define bitsizeof(x) (CHAR_BIT * sizeof(x)) |
87 | | |
88 | | #define maximum_signed_value_of_type(a) \ |
89 | 0 | (INTMAX_MAX >> (bitsizeof(intmax_t) - bitsizeof(a))) |
90 | | |
91 | | #define maximum_unsigned_value_of_type(a) \ |
92 | 209 | (UINTMAX_MAX >> (bitsizeof(uintmax_t) - bitsizeof(a))) |
93 | | |
94 | | /* |
95 | | * Signed integer overflow is undefined in C, so here's a helper macro |
96 | | * to detect if the sum of two integers will overflow. |
97 | | * |
98 | | * Requires: a >= 0, typeof(a) equals typeof(b) |
99 | | */ |
100 | | #define signed_add_overflows(a, b) \ |
101 | 0 | ((b) > maximum_signed_value_of_type(a) - (a)) |
102 | | |
103 | | #define unsigned_add_overflows(a, b) \ |
104 | 0 | ((b) > maximum_unsigned_value_of_type(a) - (a)) |
105 | | |
106 | | /* |
107 | | * Returns true if the multiplication of "a" and "b" will |
108 | | * overflow. The types of "a" and "b" must match and must be unsigned. |
109 | | * Note that this macro evaluates "a" twice! |
110 | | */ |
111 | | #define unsigned_mult_overflows(a, b) \ |
112 | 268 | ((a) && (b) > maximum_unsigned_value_of_type(a) / (a)) |
113 | | |
114 | | /* |
115 | | * Returns true if the left shift of "a" by "shift" bits will |
116 | | * overflow. The type of "a" must be unsigned. |
117 | | */ |
118 | | #define unsigned_left_shift_overflows(a, shift) \ |
119 | 0 | ((shift) < bitsizeof(a) && \ |
120 | 0 | (a) > maximum_unsigned_value_of_type(a) >> (shift)) |
121 | | |
122 | | #ifdef __GNUC__ |
123 | 0 | #define TYPEOF(x) (__typeof__(x)) |
124 | | #else |
125 | | #define TYPEOF(x) |
126 | | #endif |
127 | | |
128 | 0 | #define MSB(x, bits) ((x) & TYPEOF(x)(~0ULL << (bitsizeof(x) - (bits)))) |
129 | 0 | #define HAS_MULTI_BITS(i) ((i) & ((i) - 1)) /* checks if an integer has more than 1 bit set */ |
130 | | |
131 | 0 | #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) |
132 | | |
133 | | /* Approximation of the length of the decimal representation of this type. */ |
134 | | #define decimal_length(x) ((int)(sizeof(x) * 2.56 + 0.5) + 1) |
135 | | |
136 | | #if defined(NO_UNIX_SOCKETS) || !defined(GIT_WINDOWS_NATIVE) |
137 | | static inline int _have_unix_sockets(void) |
138 | 0 | { |
139 | 0 | #if defined(NO_UNIX_SOCKETS) |
140 | 0 | return 0; |
141 | 0 | #else |
142 | 0 | return 1; |
143 | 0 | #endif |
144 | 0 | } Unexecuted instantiation: procinfo.c:_have_unix_sockets Unexecuted instantiation: fopen.c:_have_unix_sockets Unexecuted instantiation: strlcpy.c:_have_unix_sockets Unexecuted instantiation: qsort_s.c:_have_unix_sockets Unexecuted instantiation: system.c:_have_unix_sockets Unexecuted instantiation: sha1.c:_have_unix_sockets Unexecuted instantiation: ubc_check.c:_have_unix_sockets Unexecuted instantiation: fsm-ipc-unix.c:_have_unix_sockets Unexecuted instantiation: fsm-settings-unix.c:_have_unix_sockets Unexecuted instantiation: fsm-path-utils-linux.c:_have_unix_sockets |
145 | | #define have_unix_sockets _have_unix_sockets |
146 | | #endif |
147 | | |
148 | | /* Used by compat/win32/path-utils.h, and more */ |
149 | | static inline int is_xplatform_dir_sep(int c) |
150 | 0 | { |
151 | 0 | return c == '/' || c == '\\'; |
152 | 0 | } Unexecuted instantiation: submodule-config.c:is_xplatform_dir_sep Unexecuted instantiation: procinfo.c:is_xplatform_dir_sep Unexecuted instantiation: fopen.c:is_xplatform_dir_sep Unexecuted instantiation: strlcpy.c:is_xplatform_dir_sep Unexecuted instantiation: qsort_s.c:is_xplatform_dir_sep Unexecuted instantiation: dir.c:is_xplatform_dir_sep Unexecuted instantiation: path.c:is_xplatform_dir_sep Unexecuted instantiation: system.c:is_xplatform_dir_sep Unexecuted instantiation: sha1.c:is_xplatform_dir_sep Unexecuted instantiation: ubc_check.c:is_xplatform_dir_sep Unexecuted instantiation: fsm-ipc-unix.c:is_xplatform_dir_sep Unexecuted instantiation: fsm-settings-unix.c:is_xplatform_dir_sep Unexecuted instantiation: fsm-path-utils-linux.c:is_xplatform_dir_sep |
153 | | |
154 | | #if defined(__CYGWIN__) |
155 | | #include "compat/win32/path-utils.h" |
156 | | #endif |
157 | | #if defined(__MINGW32__) |
158 | | /* pull in Windows compatibility stuff */ |
159 | | #include "compat/win32/path-utils.h" |
160 | | #include "compat/mingw.h" |
161 | | #elif defined(_MSC_VER) |
162 | | #include "compat/win32/path-utils.h" |
163 | | #include "compat/msvc.h" |
164 | | #endif |
165 | | |
166 | | /* used on Mac OS X */ |
167 | | #ifdef PRECOMPOSE_UNICODE |
168 | | #include "compat/precompose_utf8.h" |
169 | | #else |
170 | | static inline const char *precompose_argv_prefix(int argc UNUSED, |
171 | | const char **argv UNUSED, |
172 | | const char *prefix) |
173 | 0 | { |
174 | 0 | return prefix; |
175 | 0 | } Unexecuted instantiation: procinfo.c:precompose_argv_prefix Unexecuted instantiation: fopen.c:precompose_argv_prefix Unexecuted instantiation: strlcpy.c:precompose_argv_prefix Unexecuted instantiation: qsort_s.c:precompose_argv_prefix Unexecuted instantiation: parse-options.c:precompose_argv_prefix Unexecuted instantiation: system.c:precompose_argv_prefix Unexecuted instantiation: sha1.c:precompose_argv_prefix Unexecuted instantiation: ubc_check.c:precompose_argv_prefix Unexecuted instantiation: fsm-ipc-unix.c:precompose_argv_prefix Unexecuted instantiation: fsm-settings-unix.c:precompose_argv_prefix Unexecuted instantiation: fsm-path-utils-linux.c:precompose_argv_prefix |
176 | | static inline const char *precompose_string_if_needed(const char *in) |
177 | 0 | { |
178 | 0 | return in; |
179 | 0 | } Unexecuted instantiation: setup.c:precompose_string_if_needed Unexecuted instantiation: procinfo.c:precompose_string_if_needed Unexecuted instantiation: fopen.c:precompose_string_if_needed Unexecuted instantiation: strlcpy.c:precompose_string_if_needed Unexecuted instantiation: qsort_s.c:precompose_string_if_needed Unexecuted instantiation: system.c:precompose_string_if_needed Unexecuted instantiation: sha1.c:precompose_string_if_needed Unexecuted instantiation: ubc_check.c:precompose_string_if_needed Unexecuted instantiation: fsm-ipc-unix.c:precompose_string_if_needed Unexecuted instantiation: fsm-settings-unix.c:precompose_string_if_needed Unexecuted instantiation: fsm-path-utils-linux.c:precompose_string_if_needed |
180 | | |
181 | | #define probe_utf8_pathname_composition() |
182 | | #endif |
183 | | |
184 | | #ifndef NO_OPENSSL |
185 | | #ifdef __APPLE__ |
186 | | #undef __AVAILABILITY_MACROS_USES_AVAILABILITY |
187 | | #define __AVAILABILITY_MACROS_USES_AVAILABILITY 0 |
188 | | #include <AvailabilityMacros.h> |
189 | | #undef DEPRECATED_ATTRIBUTE |
190 | | #define DEPRECATED_ATTRIBUTE |
191 | | #undef __AVAILABILITY_MACROS_USES_AVAILABILITY |
192 | | #endif |
193 | | #include <openssl/ssl.h> |
194 | | #include <openssl/err.h> |
195 | | #endif |
196 | | |
197 | | #ifdef HAVE_SYSINFO |
198 | | # include <sys/sysinfo.h> |
199 | | #endif |
200 | | |
201 | | #ifndef PATH_SEP |
202 | 0 | #define PATH_SEP ':' |
203 | | #endif |
204 | | |
205 | | #ifdef HAVE_PATHS_H |
206 | | #include <paths.h> |
207 | | #endif |
208 | | #ifndef _PATH_DEFPATH |
209 | | #define _PATH_DEFPATH "/usr/local/bin:/usr/bin:/bin" |
210 | | #endif |
211 | | |
212 | | #ifndef platform_core_config |
213 | | struct config_context; |
214 | | static inline int noop_core_config(const char *var UNUSED, |
215 | | const char *value UNUSED, |
216 | | const struct config_context *ctx UNUSED, |
217 | | void *cb UNUSED) |
218 | 0 | { |
219 | 0 | return 0; |
220 | 0 | } Unexecuted instantiation: procinfo.c:noop_core_config Unexecuted instantiation: fopen.c:noop_core_config Unexecuted instantiation: strlcpy.c:noop_core_config Unexecuted instantiation: qsort_s.c:noop_core_config Unexecuted instantiation: environment.c:noop_core_config Unexecuted instantiation: system.c:noop_core_config Unexecuted instantiation: sha1.c:noop_core_config Unexecuted instantiation: ubc_check.c:noop_core_config Unexecuted instantiation: fsm-ipc-unix.c:noop_core_config Unexecuted instantiation: fsm-settings-unix.c:noop_core_config Unexecuted instantiation: fsm-path-utils-linux.c:noop_core_config |
221 | 0 | #define platform_core_config noop_core_config |
222 | | #endif |
223 | | |
224 | | #ifndef has_dos_drive_prefix |
225 | | static inline int git_has_dos_drive_prefix(const char *path UNUSED) |
226 | 0 | { |
227 | 0 | return 0; |
228 | 0 | } Unexecuted instantiation: remote.c:git_has_dos_drive_prefix Unexecuted instantiation: repository.c:git_has_dos_drive_prefix Unexecuted instantiation: setup.c:git_has_dos_drive_prefix Unexecuted instantiation: submodule.c:git_has_dos_drive_prefix Unexecuted instantiation: tempfile.c:git_has_dos_drive_prefix Unexecuted instantiation: trace.c:git_has_dos_drive_prefix Unexecuted instantiation: tr2_dst.c:git_has_dos_drive_prefix Unexecuted instantiation: url.c:git_has_dos_drive_prefix Unexecuted instantiation: worktree.c:git_has_dos_drive_prefix Unexecuted instantiation: wrapper.c:git_has_dos_drive_prefix Unexecuted instantiation: procinfo.c:git_has_dos_drive_prefix Unexecuted instantiation: fopen.c:git_has_dos_drive_prefix Unexecuted instantiation: strlcpy.c:git_has_dos_drive_prefix Unexecuted instantiation: qsort_s.c:git_has_dos_drive_prefix Unexecuted instantiation: abspath.c:git_has_dos_drive_prefix Unexecuted instantiation: chdir-notify.c:git_has_dos_drive_prefix Unexecuted instantiation: config.c:git_has_dos_drive_prefix Unexecuted instantiation: connect.c:git_has_dos_drive_prefix Unexecuted instantiation: copy.c:git_has_dos_drive_prefix Unexecuted instantiation: diff.c:git_has_dos_drive_prefix Unexecuted instantiation: dir.c:git_has_dos_drive_prefix Unexecuted instantiation: editor.c:git_has_dos_drive_prefix Unexecuted instantiation: environment.c:git_has_dos_drive_prefix Unexecuted instantiation: exec-cmd.c:git_has_dos_drive_prefix Unexecuted instantiation: gettext.c:git_has_dos_drive_prefix Unexecuted instantiation: hook.c:git_has_dos_drive_prefix Unexecuted instantiation: lockfile.c:git_has_dos_drive_prefix Unexecuted instantiation: odb.c:git_has_dos_drive_prefix Unexecuted instantiation: source-files.c:git_has_dos_drive_prefix Unexecuted instantiation: source-loose.c:git_has_dos_drive_prefix Unexecuted instantiation: source-packed.c:git_has_dos_drive_prefix Unexecuted instantiation: parse-options.c:git_has_dos_drive_prefix Unexecuted instantiation: path.c:git_has_dos_drive_prefix Unexecuted instantiation: pathspec.c:git_has_dos_drive_prefix Unexecuted instantiation: read-cache.c:git_has_dos_drive_prefix Unexecuted instantiation: refs.c:git_has_dos_drive_prefix Unexecuted instantiation: files-backend.c:git_has_dos_drive_prefix Unexecuted instantiation: reftable-backend.c:git_has_dos_drive_prefix Unexecuted instantiation: sequencer.c:git_has_dos_drive_prefix Unexecuted instantiation: tmp-objdir.c:git_has_dos_drive_prefix Unexecuted instantiation: system.c:git_has_dos_drive_prefix Unexecuted instantiation: sha1.c:git_has_dos_drive_prefix Unexecuted instantiation: ubc_check.c:git_has_dos_drive_prefix Unexecuted instantiation: fsm-ipc-unix.c:git_has_dos_drive_prefix Unexecuted instantiation: fsm-settings-unix.c:git_has_dos_drive_prefix Unexecuted instantiation: fsm-path-utils-linux.c:git_has_dos_drive_prefix Unexecuted instantiation: apply.c:git_has_dos_drive_prefix Unexecuted instantiation: rerere.c:git_has_dos_drive_prefix |
229 | 0 | #define has_dos_drive_prefix git_has_dos_drive_prefix |
230 | | #endif |
231 | | |
232 | | #ifndef skip_dos_drive_prefix |
233 | | static inline int git_skip_dos_drive_prefix(char **path UNUSED) |
234 | 0 | { |
235 | 0 | return 0; |
236 | 0 | } Unexecuted instantiation: procinfo.c:git_skip_dos_drive_prefix Unexecuted instantiation: fopen.c:git_skip_dos_drive_prefix Unexecuted instantiation: strlcpy.c:git_skip_dos_drive_prefix Unexecuted instantiation: qsort_s.c:git_skip_dos_drive_prefix Unexecuted instantiation: system.c:git_skip_dos_drive_prefix Unexecuted instantiation: sha1.c:git_skip_dos_drive_prefix Unexecuted instantiation: ubc_check.c:git_skip_dos_drive_prefix Unexecuted instantiation: fsm-ipc-unix.c:git_skip_dos_drive_prefix Unexecuted instantiation: fsm-settings-unix.c:git_skip_dos_drive_prefix Unexecuted instantiation: fsm-path-utils-linux.c:git_skip_dos_drive_prefix |
237 | | #define skip_dos_drive_prefix git_skip_dos_drive_prefix |
238 | | #endif |
239 | | |
240 | | static inline int git_is_dir_sep(int c) |
241 | 0 | { |
242 | 0 | return c == '/'; |
243 | 0 | } Unexecuted instantiation: remote.c:git_is_dir_sep Unexecuted instantiation: repository.c:git_is_dir_sep Unexecuted instantiation: setup.c:git_is_dir_sep Unexecuted instantiation: strbuf.c:git_is_dir_sep Unexecuted instantiation: submodule.c:git_is_dir_sep Unexecuted instantiation: tempfile.c:git_is_dir_sep Unexecuted instantiation: trace.c:git_is_dir_sep Unexecuted instantiation: tr2_dst.c:git_is_dir_sep Unexecuted instantiation: utf8.c:git_is_dir_sep Unexecuted instantiation: worktree.c:git_is_dir_sep Unexecuted instantiation: wrapper.c:git_is_dir_sep Unexecuted instantiation: procinfo.c:git_is_dir_sep Unexecuted instantiation: fopen.c:git_is_dir_sep Unexecuted instantiation: strlcpy.c:git_is_dir_sep Unexecuted instantiation: qsort_s.c:git_is_dir_sep Unexecuted instantiation: abspath.c:git_is_dir_sep Unexecuted instantiation: chdir-notify.c:git_is_dir_sep Unexecuted instantiation: config.c:git_is_dir_sep Unexecuted instantiation: connect.c:git_is_dir_sep Unexecuted instantiation: copy.c:git_is_dir_sep Unexecuted instantiation: diff.c:git_is_dir_sep Unexecuted instantiation: dir.c:git_is_dir_sep Unexecuted instantiation: editor.c:git_is_dir_sep Unexecuted instantiation: environment.c:git_is_dir_sep Unexecuted instantiation: exec-cmd.c:git_is_dir_sep Unexecuted instantiation: gettext.c:git_is_dir_sep Unexecuted instantiation: hook.c:git_is_dir_sep Unexecuted instantiation: lockfile.c:git_is_dir_sep Unexecuted instantiation: name-hash.c:git_is_dir_sep Unexecuted instantiation: odb.c:git_is_dir_sep Unexecuted instantiation: source-files.c:git_is_dir_sep Unexecuted instantiation: source-loose.c:git_is_dir_sep Unexecuted instantiation: source-packed.c:git_is_dir_sep Unexecuted instantiation: parse-options.c:git_is_dir_sep Unexecuted instantiation: path.c:git_is_dir_sep Unexecuted instantiation: pathspec.c:git_is_dir_sep Unexecuted instantiation: read-cache.c:git_is_dir_sep Unexecuted instantiation: refs.c:git_is_dir_sep Unexecuted instantiation: files-backend.c:git_is_dir_sep Unexecuted instantiation: reftable-backend.c:git_is_dir_sep Unexecuted instantiation: sequencer.c:git_is_dir_sep Unexecuted instantiation: tmp-objdir.c:git_is_dir_sep Unexecuted instantiation: system.c:git_is_dir_sep Unexecuted instantiation: sha1.c:git_is_dir_sep Unexecuted instantiation: ubc_check.c:git_is_dir_sep Unexecuted instantiation: fsm-ipc-unix.c:git_is_dir_sep Unexecuted instantiation: fsm-settings-unix.c:git_is_dir_sep Unexecuted instantiation: fsm-path-utils-linux.c:git_is_dir_sep Unexecuted instantiation: apply.c:git_is_dir_sep Unexecuted instantiation: attr.c:git_is_dir_sep Unexecuted instantiation: dir-iterator.c:git_is_dir_sep Unexecuted instantiation: rerere.c:git_is_dir_sep |
244 | | #ifndef is_dir_sep |
245 | 0 | #define is_dir_sep git_is_dir_sep |
246 | | #endif |
247 | | |
248 | | #ifndef platform_has_symlinks |
249 | 0 | #define platform_has_symlinks() 1 |
250 | | #endif |
251 | | |
252 | | #ifndef offset_1st_component |
253 | | static inline int git_offset_1st_component(const char *path) |
254 | 0 | { |
255 | 0 | return is_dir_sep(path[0]); |
256 | 0 | } Unexecuted instantiation: setup.c:git_offset_1st_component Unexecuted instantiation: procinfo.c:git_offset_1st_component Unexecuted instantiation: fopen.c:git_offset_1st_component Unexecuted instantiation: strlcpy.c:git_offset_1st_component Unexecuted instantiation: qsort_s.c:git_offset_1st_component Unexecuted instantiation: abspath.c:git_offset_1st_component Unexecuted instantiation: connect.c:git_offset_1st_component Unexecuted instantiation: path.c:git_offset_1st_component Unexecuted instantiation: system.c:git_offset_1st_component Unexecuted instantiation: sha1.c:git_offset_1st_component Unexecuted instantiation: ubc_check.c:git_offset_1st_component Unexecuted instantiation: fsm-ipc-unix.c:git_offset_1st_component Unexecuted instantiation: fsm-settings-unix.c:git_offset_1st_component Unexecuted instantiation: fsm-path-utils-linux.c:git_offset_1st_component |
257 | 0 | #define offset_1st_component git_offset_1st_component |
258 | | #endif |
259 | | |
260 | | #ifndef fspathcmp |
261 | 0 | #define fspathcmp git_fspathcmp |
262 | | #endif |
263 | | |
264 | | #ifndef fspathncmp |
265 | 0 | #define fspathncmp git_fspathncmp |
266 | | #endif |
267 | | |
268 | | #ifndef is_valid_path |
269 | 0 | #define is_valid_path(path) 1 |
270 | | #endif |
271 | | |
272 | | #ifndef is_path_owned_by_current_user |
273 | | |
274 | | #ifdef __TANDEM |
275 | | #define ROOT_UID 65535 |
276 | | #else |
277 | 0 | #define ROOT_UID 0 |
278 | | #endif |
279 | | |
280 | | /* |
281 | | * Do not use this function when |
282 | | * (1) geteuid() did not say we are running as 'root', or |
283 | | * (2) using this function will compromise the system. |
284 | | * |
285 | | * PORTABILITY WARNING: |
286 | | * This code assumes uid_t is unsigned because that is what sudo does. |
287 | | * If your uid_t type is signed and all your ids are positive then it |
288 | | * should all work fine. |
289 | | * If your version of sudo uses negative values for uid_t or it is |
290 | | * buggy and return an overflowed value in SUDO_UID, then git might |
291 | | * fail to grant access to your repository properly or even mistakenly |
292 | | * grant access to someone else. |
293 | | * In the unlikely scenario this happened to you, and that is how you |
294 | | * got to this message, we would like to know about it; so sent us an |
295 | | * email to git@vger.kernel.org indicating which platform you are |
296 | | * using and which version of sudo, so we can improve this logic and |
297 | | * maybe provide you with a patch that would prevent this issue again |
298 | | * in the future. |
299 | | */ |
300 | | static inline void extract_id_from_env(const char *env, uid_t *id) |
301 | 0 | { |
302 | 0 | const char *real_uid = getenv(env); |
303 | 0 |
|
304 | 0 | /* discard anything empty to avoid a more complex check below */ |
305 | 0 | if (real_uid && *real_uid) { |
306 | 0 | char *endptr = NULL; |
307 | 0 | unsigned long env_id; |
308 | 0 |
|
309 | 0 | errno = 0; |
310 | 0 | /* silent overflow errors could trigger a bug here */ |
311 | 0 | env_id = strtoul(real_uid, &endptr, 10); |
312 | 0 | if (!*endptr && !errno) |
313 | 0 | *id = env_id; |
314 | 0 | } |
315 | 0 | } Unexecuted instantiation: setup.c:extract_id_from_env Unexecuted instantiation: procinfo.c:extract_id_from_env Unexecuted instantiation: fopen.c:extract_id_from_env Unexecuted instantiation: strlcpy.c:extract_id_from_env Unexecuted instantiation: qsort_s.c:extract_id_from_env Unexecuted instantiation: system.c:extract_id_from_env Unexecuted instantiation: sha1.c:extract_id_from_env Unexecuted instantiation: ubc_check.c:extract_id_from_env Unexecuted instantiation: fsm-ipc-unix.c:extract_id_from_env Unexecuted instantiation: fsm-settings-unix.c:extract_id_from_env Unexecuted instantiation: fsm-path-utils-linux.c:extract_id_from_env |
316 | | |
317 | | static inline int is_path_owned_by_current_uid(const char *path, |
318 | | struct strbuf *report UNUSED) |
319 | 0 | { |
320 | 0 | struct stat st; |
321 | 0 | uid_t euid; |
322 | 0 |
|
323 | 0 | if (lstat(path, &st)) |
324 | 0 | return 0; |
325 | 0 |
|
326 | 0 | euid = geteuid(); |
327 | 0 | if (euid == ROOT_UID) |
328 | 0 | { |
329 | 0 | if (st.st_uid == ROOT_UID) |
330 | 0 | return 1; |
331 | 0 | else |
332 | 0 | extract_id_from_env("SUDO_UID", &euid); |
333 | 0 | } |
334 | 0 |
|
335 | 0 | return st.st_uid == euid; |
336 | 0 | } Unexecuted instantiation: setup.c:is_path_owned_by_current_uid Unexecuted instantiation: procinfo.c:is_path_owned_by_current_uid Unexecuted instantiation: fopen.c:is_path_owned_by_current_uid Unexecuted instantiation: strlcpy.c:is_path_owned_by_current_uid Unexecuted instantiation: qsort_s.c:is_path_owned_by_current_uid Unexecuted instantiation: system.c:is_path_owned_by_current_uid Unexecuted instantiation: sha1.c:is_path_owned_by_current_uid Unexecuted instantiation: ubc_check.c:is_path_owned_by_current_uid Unexecuted instantiation: fsm-ipc-unix.c:is_path_owned_by_current_uid Unexecuted instantiation: fsm-settings-unix.c:is_path_owned_by_current_uid Unexecuted instantiation: fsm-path-utils-linux.c:is_path_owned_by_current_uid |
337 | | |
338 | 0 | #define is_path_owned_by_current_user is_path_owned_by_current_uid |
339 | | #endif |
340 | | |
341 | | #ifndef find_last_dir_sep |
342 | 0 | #define find_last_dir_sep(path) strrchr((path), '/') |
343 | | #endif |
344 | | |
345 | | #ifndef has_dir_sep |
346 | | static inline int git_has_dir_sep(const char *path) |
347 | 0 | { |
348 | 0 | return !!strchr(path, '/'); |
349 | 0 | } Unexecuted instantiation: run-command.c:git_has_dir_sep Unexecuted instantiation: procinfo.c:git_has_dir_sep Unexecuted instantiation: fopen.c:git_has_dir_sep Unexecuted instantiation: strlcpy.c:git_has_dir_sep Unexecuted instantiation: qsort_s.c:git_has_dir_sep Unexecuted instantiation: system.c:git_has_dir_sep Unexecuted instantiation: sha1.c:git_has_dir_sep Unexecuted instantiation: ubc_check.c:git_has_dir_sep Unexecuted instantiation: fsm-ipc-unix.c:git_has_dir_sep Unexecuted instantiation: fsm-settings-unix.c:git_has_dir_sep Unexecuted instantiation: fsm-path-utils-linux.c:git_has_dir_sep |
350 | 0 | #define has_dir_sep(path) git_has_dir_sep(path) |
351 | | #endif |
352 | | |
353 | | #ifndef query_user_email |
354 | 0 | #define query_user_email() NULL |
355 | | #endif |
356 | | |
357 | | #ifdef __TANDEM |
358 | | #include <floss.h(floss_execl,floss_execlp,floss_execv,floss_execvp)> |
359 | | #include <floss.h(floss_getpwuid)> |
360 | | #ifndef NSIG |
361 | | /* |
362 | | * NonStop NSE and NSX do not provide NSIG. SIGGUARDIAN(99) is the highest |
363 | | * known, by detective work using kill -l as a list is all signals |
364 | | * instead of signal.h where it should be. |
365 | | */ |
366 | | # define NSIG 100 |
367 | | #endif |
368 | | #endif |
369 | | |
370 | | #if defined(__HP_cc) && (__HP_cc >= 61000) |
371 | | #define NORETURN __attribute__((noreturn)) |
372 | | #define NORETURN_PTR |
373 | | #elif defined(__GNUC__) && !defined(NO_NORETURN) |
374 | | #define NORETURN __attribute__((__noreturn__)) |
375 | | #define NORETURN_PTR __attribute__((__noreturn__)) |
376 | | #elif defined(_MSC_VER) |
377 | | #define NORETURN __declspec(noreturn) |
378 | | #define NORETURN_PTR |
379 | | #else |
380 | | #define NORETURN |
381 | | #define NORETURN_PTR |
382 | | #ifndef __GNUC__ |
383 | | #ifndef __attribute__ |
384 | | #define __attribute__(x) |
385 | | #endif |
386 | | #endif |
387 | | #endif |
388 | | |
389 | | /* The sentinel attribute is valid from gcc version 4.0 */ |
390 | | #if defined(__GNUC__) && (__GNUC__ >= 4) |
391 | | #define LAST_ARG_MUST_BE_NULL __attribute__((sentinel)) |
392 | | /* warn_unused_result exists as of gcc 3.4.0, but be lazy and check 4.0 */ |
393 | | #define RESULT_MUST_BE_USED __attribute__ ((warn_unused_result)) |
394 | | #else |
395 | | #define LAST_ARG_MUST_BE_NULL |
396 | | #define RESULT_MUST_BE_USED |
397 | | #endif |
398 | | |
399 | | /* |
400 | | * MAYBE_UNUSED marks a function parameter that may be unused, but |
401 | | * whose use is not an error. It also can be used to annotate a |
402 | | * function, a variable, or a type that may be unused. |
403 | | * |
404 | | * Depending on a configuration, all uses of such a thing may become |
405 | | * #ifdef'ed away. Marking it with UNUSED would give a warning in a |
406 | | * compilation where it is indeed used, and not marking it at all |
407 | | * would give a warning in a compilation where it is unused. In such |
408 | | * a case, MAYBE_UNUSED is the appropriate annotation to use. |
409 | | */ |
410 | 0 | #define MAYBE_UNUSED __attribute__((__unused__)) |
411 | | |
412 | | #include "compat/bswap.h" |
413 | | |
414 | | #include "wrapper.h" |
415 | | |
416 | | /* General helper functions */ |
417 | | NORETURN void usage(const char *err); |
418 | | NORETURN void usagef(const char *err, ...) __attribute__((format (printf, 1, 2))); |
419 | | NORETURN void die(const char *err, ...) __attribute__((format (printf, 1, 2))); |
420 | | NORETURN void die_errno(const char *err, ...) __attribute__((format (printf, 1, 2))); |
421 | | int die_message(const char *err, ...) __attribute__((format (printf, 1, 2))); |
422 | | int die_message_errno(const char *err, ...) __attribute__((format (printf, 1, 2))); |
423 | | int error(const char *err, ...) __attribute__((format (printf, 1, 2))); |
424 | | int error_errno(const char *err, ...) __attribute__((format (printf, 1, 2))); |
425 | | void warning(const char *err, ...) __attribute__((format (printf, 1, 2))); |
426 | | void warning_errno(const char *err, ...) __attribute__((format (printf, 1, 2))); |
427 | | |
428 | | void show_usage_if_asked(int ac, const char **av, const char *err); |
429 | | |
430 | | NORETURN void you_still_use_that(const char *command_name, const char *hint); |
431 | | |
432 | | #ifndef NO_OPENSSL |
433 | | #ifdef APPLE_COMMON_CRYPTO |
434 | | #include "compat/apple-common-crypto.h" |
435 | | #else |
436 | | #include <openssl/evp.h> |
437 | | #include <openssl/hmac.h> |
438 | | #endif /* APPLE_COMMON_CRYPTO */ |
439 | | #include <openssl/x509v3.h> |
440 | | #endif /* NO_OPENSSL */ |
441 | | |
442 | | #ifdef HAVE_OPENSSL_CSPRNG |
443 | | #include <openssl/rand.h> |
444 | | #endif |
445 | | |
446 | | /* |
447 | | * Let callers be aware of the constant return value; this can help |
448 | | * gcc with -Wuninitialized analysis. We restrict this trick to gcc, though, |
449 | | * because other compilers may be confused by this. |
450 | | */ |
451 | | #if defined(__GNUC__) |
452 | | static inline int const_error(void) |
453 | 301 | { |
454 | 301 | return -1; |
455 | 301 | } Line | Count | Source | 453 | 301 | { | 454 | 301 | return -1; | 455 | 301 | } |
Unexecuted instantiation: patch-delta.c:const_error Unexecuted instantiation: promisor-remote.c:const_error Unexecuted instantiation: remote.c:const_error Unexecuted instantiation: repo-settings.c:const_error Unexecuted instantiation: repository.c:const_error Unexecuted instantiation: revision.c:const_error Unexecuted instantiation: run-command.c:const_error Unexecuted instantiation: setup.c:const_error Unexecuted instantiation: sparse-index.c:const_error Unexecuted instantiation: submodule-config.c:const_error Unexecuted instantiation: submodule.c:const_error Unexecuted instantiation: tag.c:const_error Unexecuted instantiation: tempfile.c:const_error Unexecuted instantiation: trace2.c:const_error Unexecuted instantiation: tr2_cfg.c:const_error Unexecuted instantiation: tr2_dst.c:const_error Unexecuted instantiation: tr2_sysenv.c:const_error Unexecuted instantiation: tr2_tgt_event.c:const_error Unexecuted instantiation: tr2_tgt_normal.c:const_error Unexecuted instantiation: tr2_tgt_perf.c:const_error Unexecuted instantiation: transport.c:const_error Unexecuted instantiation: tree-walk.c:const_error Unexecuted instantiation: tree.c:const_error Unexecuted instantiation: urlmatch.c:const_error Unexecuted instantiation: usage.c:const_error Unexecuted instantiation: worktree.c:const_error Unexecuted instantiation: wrapper.c:const_error Unexecuted instantiation: wt-status.c:const_error Unexecuted instantiation: procinfo.c:const_error Unexecuted instantiation: fopen.c:const_error Unexecuted instantiation: strlcpy.c:const_error Unexecuted instantiation: qsort_s.c:const_error Unexecuted instantiation: advice.c:const_error Unexecuted instantiation: bisect.c:const_error Unexecuted instantiation: bloom.c:const_error Unexecuted instantiation: branch.c:const_error Unexecuted instantiation: bundle-uri.c:const_error Unexecuted instantiation: bundle.c:const_error Unexecuted instantiation: cache-tree.c:const_error Unexecuted instantiation: color.c:const_error Unexecuted instantiation: column.c:const_error Unexecuted instantiation: combine-diff.c:const_error Unexecuted instantiation: commit-graph.c:const_error Unexecuted instantiation: commit-reach.c:const_error Unexecuted instantiation: commit.c:const_error Unexecuted instantiation: config.c:const_error Unexecuted instantiation: connect.c:const_error Unexecuted instantiation: connected.c:const_error Unexecuted instantiation: convert.c:const_error Unexecuted instantiation: copy.c:const_error Unexecuted instantiation: diff-lib.c:const_error Unexecuted instantiation: diff.c:const_error Unexecuted instantiation: dir.c:const_error Unexecuted instantiation: editor.c:const_error Unexecuted instantiation: environment.c:const_error Unexecuted instantiation: ewah_io.c:const_error Unexecuted instantiation: exec-cmd.c:const_error Unexecuted instantiation: fetch-object-info.c:const_error Unexecuted instantiation: fetch-pack.c:const_error Unexecuted instantiation: fsck.c:const_error Unexecuted instantiation: fsmonitor.c:const_error Unexecuted instantiation: fsmonitor-ipc.c:const_error Unexecuted instantiation: fsmonitor-settings.c:const_error Unexecuted instantiation: git-zlib.c:const_error Unexecuted instantiation: gpg-interface.c:const_error Unexecuted instantiation: graph.c:const_error Unexecuted instantiation: grep.c:const_error Unexecuted instantiation: hook.c:const_error Unexecuted instantiation: ident.c:const_error Unexecuted instantiation: list-objects-filter-options.c:const_error Unexecuted instantiation: lockfile.c:const_error Unexecuted instantiation: log-tree.c:const_error Unexecuted instantiation: mailmap.c:const_error Unexecuted instantiation: merge-ll.c:const_error Unexecuted instantiation: merge-ort.c:const_error Unexecuted instantiation: midx.c:const_error Unexecuted instantiation: notes.c:const_error Unexecuted instantiation: object-file-convert.c:const_error Unexecuted instantiation: object-file.c:const_error Unexecuted instantiation: object-name.c:const_error Unexecuted instantiation: object.c:const_error Unexecuted instantiation: odb.c:const_error Unexecuted instantiation: source-files.c:const_error Unexecuted instantiation: source-inmemory.c:const_error Unexecuted instantiation: source-loose.c:const_error Unexecuted instantiation: source-packed.c:const_error Unexecuted instantiation: transaction.c:const_error Unexecuted instantiation: pack-bitmap.c:const_error Unexecuted instantiation: pack-check.c:const_error Unexecuted instantiation: pack-mtimes.c:const_error Unexecuted instantiation: pack-revindex.c:const_error Unexecuted instantiation: pager.c:const_error Unexecuted instantiation: parse-options-cb.c:const_error Unexecuted instantiation: parse-options.c:const_error Unexecuted instantiation: patch-ids.c:const_error Unexecuted instantiation: path.c:const_error Unexecuted instantiation: pkt-line.c:const_error Unexecuted instantiation: pretty.c:const_error Unexecuted instantiation: protocol.c:const_error Unexecuted instantiation: pseudo-merge.c:const_error Unexecuted instantiation: quote.c:const_error Unexecuted instantiation: range-diff.c:const_error Unexecuted instantiation: read-cache.c:const_error Unexecuted instantiation: refs.c:const_error Unexecuted instantiation: files-backend.c:const_error Unexecuted instantiation: reftable-backend.c:const_error Unexecuted instantiation: iterator.c:const_error Unexecuted instantiation: packed-backend.c:const_error Unexecuted instantiation: resolve-undo.c:const_error Unexecuted instantiation: send-pack.c:const_error Unexecuted instantiation: sequencer.c:const_error Unexecuted instantiation: sideband.c:const_error Unexecuted instantiation: split-index.c:const_error Unexecuted instantiation: sub-process.c:const_error Unexecuted instantiation: trailer.c:const_error Unexecuted instantiation: transport-helper.c:const_error Unexecuted instantiation: unpack-trees.c:const_error Unexecuted instantiation: userdiff.c:const_error Unexecuted instantiation: xdiff-interface.c:const_error Unexecuted instantiation: system.c:const_error Unexecuted instantiation: ipc-unix-socket.c:const_error Unexecuted instantiation: sha1.c:const_error Unexecuted instantiation: ubc_check.c:const_error Unexecuted instantiation: fsm-ipc-unix.c:const_error Unexecuted instantiation: fsm-settings-unix.c:const_error Unexecuted instantiation: fsm-path-utils-linux.c:const_error Unexecuted instantiation: alias.c:const_error Unexecuted instantiation: apply.c:const_error Unexecuted instantiation: attr.c:const_error Unexecuted instantiation: base85.c:const_error Unexecuted instantiation: chunk-format.c:const_error Unexecuted instantiation: entry.c:const_error Unexecuted instantiation: list-objects-filter.c:const_error Unexecuted instantiation: loose.c:const_error Unexecuted instantiation: merge-ort-wrappers.c:const_error Unexecuted instantiation: merge.c:const_error Unexecuted instantiation: notes-utils.c:const_error Unexecuted instantiation: pack-bitmap-write.c:const_error Unexecuted instantiation: parallel-checkout.c:const_error Unexecuted instantiation: preload-index.c:const_error Unexecuted instantiation: rebase-interactive.c:const_error Unexecuted instantiation: rerere.c:const_error Unexecuted instantiation: reset.c:const_error |
456 | 301 | #define error(...) (error(__VA_ARGS__), const_error()) |
457 | 0 | #define error_errno(...) (error_errno(__VA_ARGS__), const_error()) |
458 | | #endif |
459 | | |
460 | | typedef void (*report_fn)(const char *, va_list params); |
461 | | |
462 | | void set_die_routine(NORETURN_PTR report_fn routine); |
463 | | report_fn get_die_message_routine(void); |
464 | | void set_error_routine(report_fn routine); |
465 | | report_fn get_error_routine(void); |
466 | | void set_warn_routine(report_fn routine); |
467 | | report_fn get_warn_routine(void); |
468 | | void set_die_is_recursing_routine(int (*routine)(void)); |
469 | | |
470 | | /* |
471 | | * Check that an out-parameter is "at least as const as" a matching |
472 | | * in-parameter. For example, skip_prefix() will return "out" that is a subset |
473 | | * of "str". So: |
474 | | * |
475 | | * const str, const out: ok |
476 | | * non-const str, const out: ok |
477 | | * non-const str, non-const out: ok |
478 | | * const str, non-const out: compile error |
479 | | * |
480 | | * See the skip_prefix macro below for an example of use. |
481 | | */ |
482 | | #define CONST_OUTPARAM(in, out) \ |
483 | 0 | ((const char **)(0 ? ((*(out) = (in)),(out)) : (out))) |
484 | | |
485 | | /* |
486 | | * If the string "str" begins with the string found in "prefix", return true. |
487 | | * The "out" parameter is set to "str + strlen(prefix)" (i.e., to the point in |
488 | | * the string right after the prefix). |
489 | | * |
490 | | * Otherwise, return false and leave "out" untouched. |
491 | | * |
492 | | * Examples: |
493 | | * |
494 | | * [extract branch name, fail if not a branch] |
495 | | * if (!skip_prefix(ref, "refs/heads/", &branch) |
496 | | * return -1; |
497 | | * |
498 | | * [skip prefix if present, otherwise use whole string] |
499 | | * skip_prefix(name, "refs/heads/", &name); |
500 | | */ |
501 | | #define skip_prefix(str, prefix, out) \ |
502 | 0 | skip_prefix_impl((str), (prefix), CONST_OUTPARAM((str), (out))) |
503 | | static inline bool skip_prefix_impl(const char *str, const char *prefix, |
504 | | const char **out) |
505 | 0 | { |
506 | 0 | do { |
507 | 0 | if (!*prefix) { |
508 | 0 | *out = str; |
509 | 0 | return true; |
510 | 0 | } |
511 | 0 | } while (*str++ == *prefix++); |
512 | 0 | return false; |
513 | 0 | } Unexecuted instantiation: promisor-remote.c:skip_prefix_impl Unexecuted instantiation: remote.c:skip_prefix_impl Unexecuted instantiation: revision.c:skip_prefix_impl Unexecuted instantiation: setup.c:skip_prefix_impl Unexecuted instantiation: strbuf.c:skip_prefix_impl Unexecuted instantiation: submodule-config.c:skip_prefix_impl Unexecuted instantiation: submodule.c:skip_prefix_impl Unexecuted instantiation: trace2.c:skip_prefix_impl Unexecuted instantiation: tr2_dst.c:skip_prefix_impl Unexecuted instantiation: urlmatch.c:skip_prefix_impl Unexecuted instantiation: utf8.c:skip_prefix_impl Unexecuted instantiation: worktree.c:skip_prefix_impl Unexecuted instantiation: wt-status.c:skip_prefix_impl Unexecuted instantiation: procinfo.c:skip_prefix_impl Unexecuted instantiation: fopen.c:skip_prefix_impl Unexecuted instantiation: strlcpy.c:skip_prefix_impl Unexecuted instantiation: qsort_s.c:skip_prefix_impl Unexecuted instantiation: advice.c:skip_prefix_impl Unexecuted instantiation: branch.c:skip_prefix_impl Unexecuted instantiation: bundle-uri.c:skip_prefix_impl Unexecuted instantiation: bundle.c:skip_prefix_impl Unexecuted instantiation: column.c:skip_prefix_impl Unexecuted instantiation: commit.c:skip_prefix_impl Unexecuted instantiation: config.c:skip_prefix_impl Unexecuted instantiation: connect.c:skip_prefix_impl Unexecuted instantiation: convert.c:skip_prefix_impl Unexecuted instantiation: date.c:skip_prefix_impl Unexecuted instantiation: diff.c:skip_prefix_impl Unexecuted instantiation: environment.c:skip_prefix_impl Unexecuted instantiation: fetch-pack.c:skip_prefix_impl Unexecuted instantiation: fsck.c:skip_prefix_impl Unexecuted instantiation: gpg-interface.c:skip_prefix_impl Unexecuted instantiation: grep.c:skip_prefix_impl Unexecuted instantiation: ident.c:skip_prefix_impl Unexecuted instantiation: list-objects-filter-options.c:skip_prefix_impl Unexecuted instantiation: lockfile.c:skip_prefix_impl Unexecuted instantiation: log-tree.c:skip_prefix_impl Unexecuted instantiation: merge-ll.c:skip_prefix_impl Unexecuted instantiation: merge-ort.c:skip_prefix_impl Unexecuted instantiation: notes.c:skip_prefix_impl Unexecuted instantiation: object-name.c:skip_prefix_impl Unexecuted instantiation: pack-write.c:skip_prefix_impl Unexecuted instantiation: pager.c:skip_prefix_impl Unexecuted instantiation: parse-options.c:skip_prefix_impl Unexecuted instantiation: path.c:skip_prefix_impl Unexecuted instantiation: pretty.c:skip_prefix_impl Unexecuted instantiation: protocol.c:skip_prefix_impl Unexecuted instantiation: range-diff.c:skip_prefix_impl Unexecuted instantiation: read-cache.c:skip_prefix_impl Unexecuted instantiation: refs.c:skip_prefix_impl Unexecuted instantiation: files-backend.c:skip_prefix_impl Unexecuted instantiation: packed-backend.c:skip_prefix_impl Unexecuted instantiation: repack.c:skip_prefix_impl Unexecuted instantiation: send-pack.c:skip_prefix_impl Unexecuted instantiation: sequencer.c:skip_prefix_impl Unexecuted instantiation: sideband.c:skip_prefix_impl Unexecuted instantiation: sub-process.c:skip_prefix_impl Unexecuted instantiation: trailer.c:skip_prefix_impl Unexecuted instantiation: transport-helper.c:skip_prefix_impl Unexecuted instantiation: unpack-trees.c:skip_prefix_impl Unexecuted instantiation: ws.c:skip_prefix_impl Unexecuted instantiation: system.c:skip_prefix_impl Unexecuted instantiation: sha1.c:skip_prefix_impl Unexecuted instantiation: ubc_check.c:skip_prefix_impl Unexecuted instantiation: fsm-ipc-unix.c:skip_prefix_impl Unexecuted instantiation: fsm-settings-unix.c:skip_prefix_impl Unexecuted instantiation: fsm-path-utils-linux.c:skip_prefix_impl Unexecuted instantiation: apply.c:skip_prefix_impl Unexecuted instantiation: rerere.c:skip_prefix_impl |
514 | | |
515 | | /* |
516 | | * Like skip_prefix, but promises never to read past "len" bytes of the input |
517 | | * buffer, and returns the remaining number of bytes in "out" via "outlen". |
518 | | */ |
519 | | static inline bool skip_prefix_mem(const char *buf, size_t len, |
520 | | const char *prefix, |
521 | | const char **out, size_t *outlen) |
522 | 0 | { |
523 | 0 | size_t prefix_len = strlen(prefix); |
524 | 0 | if (prefix_len <= len && !memcmp(buf, prefix, prefix_len)) { |
525 | 0 | *out = buf + prefix_len; |
526 | 0 | *outlen = len - prefix_len; |
527 | 0 | return true; |
528 | 0 | } |
529 | 0 | return false; |
530 | 0 | } Unexecuted instantiation: procinfo.c:skip_prefix_mem Unexecuted instantiation: fopen.c:skip_prefix_mem Unexecuted instantiation: strlcpy.c:skip_prefix_mem Unexecuted instantiation: qsort_s.c:skip_prefix_mem Unexecuted instantiation: color.c:skip_prefix_mem Unexecuted instantiation: config.c:skip_prefix_mem Unexecuted instantiation: system.c:skip_prefix_mem Unexecuted instantiation: sha1.c:skip_prefix_mem Unexecuted instantiation: ubc_check.c:skip_prefix_mem Unexecuted instantiation: fsm-ipc-unix.c:skip_prefix_mem Unexecuted instantiation: fsm-settings-unix.c:skip_prefix_mem Unexecuted instantiation: fsm-path-utils-linux.c:skip_prefix_mem |
531 | | |
532 | | /* |
533 | | * If buf ends with suffix, return true and subtract the length of the suffix |
534 | | * from *len. Otherwise, return false and leave *len untouched. |
535 | | */ |
536 | | static inline bool strip_suffix_mem(const char *buf, size_t *len, |
537 | | const char *suffix) |
538 | 0 | { |
539 | 0 | size_t suflen = strlen(suffix); |
540 | 0 | if (*len < suflen || memcmp(buf + (*len - suflen), suffix, suflen)) |
541 | 0 | return false; |
542 | 0 | *len -= suflen; |
543 | 0 | return true; |
544 | 0 | } Unexecuted instantiation: packfile.c:strip_suffix_mem Unexecuted instantiation: promisor-remote.c:strip_suffix_mem Unexecuted instantiation: remote.c:strip_suffix_mem Unexecuted instantiation: repo-settings.c:strip_suffix_mem Unexecuted instantiation: repository.c:strip_suffix_mem Unexecuted instantiation: revision.c:strip_suffix_mem Unexecuted instantiation: run-command.c:strip_suffix_mem Unexecuted instantiation: setup.c:strip_suffix_mem Unexecuted instantiation: shallow.c:strip_suffix_mem Unexecuted instantiation: sparse-index.c:strip_suffix_mem Unexecuted instantiation: strbuf.c:strip_suffix_mem Unexecuted instantiation: strvec.c:strip_suffix_mem Unexecuted instantiation: submodule-config.c:strip_suffix_mem Unexecuted instantiation: submodule.c:strip_suffix_mem Unexecuted instantiation: symlinks.c:strip_suffix_mem Unexecuted instantiation: tag.c:strip_suffix_mem Unexecuted instantiation: tempfile.c:strip_suffix_mem Unexecuted instantiation: trace.c:strip_suffix_mem Unexecuted instantiation: trace2.c:strip_suffix_mem Unexecuted instantiation: tr2_cfg.c:strip_suffix_mem Unexecuted instantiation: tr2_cmd_name.c:strip_suffix_mem Unexecuted instantiation: tr2_dst.c:strip_suffix_mem Unexecuted instantiation: tr2_sid.c:strip_suffix_mem Unexecuted instantiation: tr2_sysenv.c:strip_suffix_mem Unexecuted instantiation: tr2_tgt_event.c:strip_suffix_mem Unexecuted instantiation: tr2_tgt_normal.c:strip_suffix_mem Unexecuted instantiation: tr2_tgt_perf.c:strip_suffix_mem Unexecuted instantiation: tr2_tls.c:strip_suffix_mem Unexecuted instantiation: tr2_tmr.c:strip_suffix_mem Unexecuted instantiation: transport.c:strip_suffix_mem Unexecuted instantiation: tree-diff.c:strip_suffix_mem Unexecuted instantiation: tree-walk.c:strip_suffix_mem Unexecuted instantiation: tree.c:strip_suffix_mem Unexecuted instantiation: url.c:strip_suffix_mem Unexecuted instantiation: urlmatch.c:strip_suffix_mem Unexecuted instantiation: usage.c:strip_suffix_mem Unexecuted instantiation: utf8.c:strip_suffix_mem Unexecuted instantiation: version.c:strip_suffix_mem Unexecuted instantiation: worktree.c:strip_suffix_mem Unexecuted instantiation: wrapper.c:strip_suffix_mem Unexecuted instantiation: wt-status.c:strip_suffix_mem Unexecuted instantiation: procinfo.c:strip_suffix_mem Unexecuted instantiation: fopen.c:strip_suffix_mem Unexecuted instantiation: strlcpy.c:strip_suffix_mem Unexecuted instantiation: qsort_s.c:strip_suffix_mem Unexecuted instantiation: abspath.c:strip_suffix_mem Unexecuted instantiation: advice.c:strip_suffix_mem Unexecuted instantiation: bisect.c:strip_suffix_mem Unexecuted instantiation: bloom.c:strip_suffix_mem Unexecuted instantiation: branch.c:strip_suffix_mem Unexecuted instantiation: bundle-uri.c:strip_suffix_mem Unexecuted instantiation: bundle.c:strip_suffix_mem Unexecuted instantiation: cache-tree.c:strip_suffix_mem Unexecuted instantiation: chdir-notify.c:strip_suffix_mem Unexecuted instantiation: color.c:strip_suffix_mem Unexecuted instantiation: combine-diff.c:strip_suffix_mem Unexecuted instantiation: commit-graph.c:strip_suffix_mem Unexecuted instantiation: commit-reach.c:strip_suffix_mem Unexecuted instantiation: commit.c:strip_suffix_mem Unexecuted instantiation: config.c:strip_suffix_mem Unexecuted instantiation: connect.c:strip_suffix_mem Unexecuted instantiation: connected.c:strip_suffix_mem Unexecuted instantiation: convert.c:strip_suffix_mem Unexecuted instantiation: copy.c:strip_suffix_mem Unexecuted instantiation: date.c:strip_suffix_mem Unexecuted instantiation: diff-merges.c:strip_suffix_mem Unexecuted instantiation: diff-lib.c:strip_suffix_mem Unexecuted instantiation: diff.c:strip_suffix_mem Unexecuted instantiation: diffcore-order.c:strip_suffix_mem Unexecuted instantiation: diffcore-pickaxe.c:strip_suffix_mem Unexecuted instantiation: diffcore-rename.c:strip_suffix_mem Unexecuted instantiation: diffcore-rotate.c:strip_suffix_mem Unexecuted instantiation: dir.c:strip_suffix_mem Unexecuted instantiation: editor.c:strip_suffix_mem Unexecuted instantiation: environment.c:strip_suffix_mem Unexecuted instantiation: ewah_io.c:strip_suffix_mem Unexecuted instantiation: exec-cmd.c:strip_suffix_mem Unexecuted instantiation: fetch-object-info.c:strip_suffix_mem Unexecuted instantiation: fetch-pack.c:strip_suffix_mem Unexecuted instantiation: fsck.c:strip_suffix_mem Unexecuted instantiation: fsmonitor.c:strip_suffix_mem Unexecuted instantiation: fsmonitor-ipc.c:strip_suffix_mem Unexecuted instantiation: fsmonitor-settings.c:strip_suffix_mem Unexecuted instantiation: gpg-interface.c:strip_suffix_mem Unexecuted instantiation: graph.c:strip_suffix_mem Unexecuted instantiation: grep.c:strip_suffix_mem Unexecuted instantiation: hex.c:strip_suffix_mem Unexecuted instantiation: hook.c:strip_suffix_mem Unexecuted instantiation: ident.c:strip_suffix_mem Unexecuted instantiation: json-writer.c:strip_suffix_mem Unexecuted instantiation: line-log.c:strip_suffix_mem Unexecuted instantiation: list-objects-filter-options.c:strip_suffix_mem Unexecuted instantiation: list-objects.c:strip_suffix_mem Unexecuted instantiation: lockfile.c:strip_suffix_mem Unexecuted instantiation: log-tree.c:strip_suffix_mem Unexecuted instantiation: mailmap.c:strip_suffix_mem Unexecuted instantiation: merge-ll.c:strip_suffix_mem Unexecuted instantiation: merge-ort.c:strip_suffix_mem Unexecuted instantiation: midx.c:strip_suffix_mem Unexecuted instantiation: name-hash.c:strip_suffix_mem Unexecuted instantiation: notes-cache.c:strip_suffix_mem Unexecuted instantiation: notes.c:strip_suffix_mem Unexecuted instantiation: object-file-convert.c:strip_suffix_mem Unexecuted instantiation: object-file.c:strip_suffix_mem Unexecuted instantiation: object-name.c:strip_suffix_mem Unexecuted instantiation: odb.c:strip_suffix_mem Unexecuted instantiation: source-files.c:strip_suffix_mem Unexecuted instantiation: source-loose.c:strip_suffix_mem Unexecuted instantiation: source-packed.c:strip_suffix_mem Unexecuted instantiation: oidset.c:strip_suffix_mem Unexecuted instantiation: pack-bitmap.c:strip_suffix_mem Unexecuted instantiation: pack-mtimes.c:strip_suffix_mem Unexecuted instantiation: pack-revindex.c:strip_suffix_mem Unexecuted instantiation: pack-write.c:strip_suffix_mem Unexecuted instantiation: parse-options-cb.c:strip_suffix_mem Unexecuted instantiation: parse-options.c:strip_suffix_mem Unexecuted instantiation: patch-ids.c:strip_suffix_mem Unexecuted instantiation: path.c:strip_suffix_mem Unexecuted instantiation: pathspec.c:strip_suffix_mem Unexecuted instantiation: pkt-line.c:strip_suffix_mem Unexecuted instantiation: pretty.c:strip_suffix_mem Unexecuted instantiation: progress.c:strip_suffix_mem Unexecuted instantiation: pseudo-merge.c:strip_suffix_mem Unexecuted instantiation: quote.c:strip_suffix_mem Unexecuted instantiation: range-diff.c:strip_suffix_mem Unexecuted instantiation: read-cache.c:strip_suffix_mem Unexecuted instantiation: reflog-walk.c:strip_suffix_mem Unexecuted instantiation: refs.c:strip_suffix_mem Unexecuted instantiation: debug.c:strip_suffix_mem Unexecuted instantiation: files-backend.c:strip_suffix_mem Unexecuted instantiation: reftable-backend.c:strip_suffix_mem Unexecuted instantiation: iterator.c:strip_suffix_mem Unexecuted instantiation: packed-backend.c:strip_suffix_mem Unexecuted instantiation: ref-cache.c:strip_suffix_mem Unexecuted instantiation: refspec.c:strip_suffix_mem Unexecuted instantiation: repack.c:strip_suffix_mem Unexecuted instantiation: repack-geometry.c:strip_suffix_mem Unexecuted instantiation: replace-object.c:strip_suffix_mem Unexecuted instantiation: resolve-undo.c:strip_suffix_mem Unexecuted instantiation: send-pack.c:strip_suffix_mem Unexecuted instantiation: sequencer.c:strip_suffix_mem Unexecuted instantiation: sideband.c:strip_suffix_mem Unexecuted instantiation: split-index.c:strip_suffix_mem Unexecuted instantiation: sub-process.c:strip_suffix_mem Unexecuted instantiation: tmp-objdir.c:strip_suffix_mem Unexecuted instantiation: trailer.c:strip_suffix_mem Unexecuted instantiation: transport-helper.c:strip_suffix_mem Unexecuted instantiation: unpack-trees.c:strip_suffix_mem Unexecuted instantiation: userdiff.c:strip_suffix_mem Unexecuted instantiation: ws.c:strip_suffix_mem Unexecuted instantiation: xdiff-interface.c:strip_suffix_mem Unexecuted instantiation: system.c:strip_suffix_mem Unexecuted instantiation: ipc-unix-socket.c:strip_suffix_mem Unexecuted instantiation: sha1.c:strip_suffix_mem Unexecuted instantiation: ubc_check.c:strip_suffix_mem Unexecuted instantiation: fsm-ipc-unix.c:strip_suffix_mem Unexecuted instantiation: fsm-settings-unix.c:strip_suffix_mem Unexecuted instantiation: fsm-path-utils-linux.c:strip_suffix_mem Unexecuted instantiation: alias.c:strip_suffix_mem Unexecuted instantiation: apply.c:strip_suffix_mem Unexecuted instantiation: attr.c:strip_suffix_mem Unexecuted instantiation: dir-iterator.c:strip_suffix_mem Unexecuted instantiation: entry.c:strip_suffix_mem Unexecuted instantiation: list-objects-filter.c:strip_suffix_mem Unexecuted instantiation: loose.c:strip_suffix_mem Unexecuted instantiation: match-trees.c:strip_suffix_mem Unexecuted instantiation: merge-ort-wrappers.c:strip_suffix_mem Unexecuted instantiation: merge.c:strip_suffix_mem Unexecuted instantiation: default.c:strip_suffix_mem Unexecuted instantiation: skipping.c:strip_suffix_mem Unexecuted instantiation: notes-utils.c:strip_suffix_mem Unexecuted instantiation: pack-bitmap-write.c:strip_suffix_mem Unexecuted instantiation: parallel-checkout.c:strip_suffix_mem Unexecuted instantiation: preload-index.c:strip_suffix_mem Unexecuted instantiation: rebase-interactive.c:strip_suffix_mem Unexecuted instantiation: rerere.c:strip_suffix_mem Unexecuted instantiation: reset.c:strip_suffix_mem Unexecuted instantiation: unix-socket.c:strip_suffix_mem Unexecuted instantiation: unix-stream-server.c:strip_suffix_mem |
545 | | |
546 | | /* |
547 | | * If str ends with suffix, return true and set *len to the size of the string |
548 | | * without the suffix. Otherwise, return false and set *len to the size of the |
549 | | * string. |
550 | | * |
551 | | * Note that we do _not_ NUL-terminate str to the new length. |
552 | | */ |
553 | | static inline bool strip_suffix(const char *str, const char *suffix, |
554 | | size_t *len) |
555 | 0 | { |
556 | 0 | *len = strlen(str); |
557 | 0 | return strip_suffix_mem(str, len, suffix); |
558 | 0 | } Unexecuted instantiation: packfile.c:strip_suffix Unexecuted instantiation: promisor-remote.c:strip_suffix Unexecuted instantiation: remote.c:strip_suffix Unexecuted instantiation: repo-settings.c:strip_suffix Unexecuted instantiation: repository.c:strip_suffix Unexecuted instantiation: revision.c:strip_suffix Unexecuted instantiation: run-command.c:strip_suffix Unexecuted instantiation: setup.c:strip_suffix Unexecuted instantiation: shallow.c:strip_suffix Unexecuted instantiation: sparse-index.c:strip_suffix Unexecuted instantiation: strbuf.c:strip_suffix Unexecuted instantiation: strvec.c:strip_suffix Unexecuted instantiation: submodule-config.c:strip_suffix Unexecuted instantiation: submodule.c:strip_suffix Unexecuted instantiation: symlinks.c:strip_suffix Unexecuted instantiation: tag.c:strip_suffix Unexecuted instantiation: tempfile.c:strip_suffix Unexecuted instantiation: trace.c:strip_suffix Unexecuted instantiation: trace2.c:strip_suffix Unexecuted instantiation: tr2_cfg.c:strip_suffix Unexecuted instantiation: tr2_cmd_name.c:strip_suffix Unexecuted instantiation: tr2_dst.c:strip_suffix Unexecuted instantiation: tr2_sid.c:strip_suffix Unexecuted instantiation: tr2_sysenv.c:strip_suffix Unexecuted instantiation: tr2_tgt_event.c:strip_suffix Unexecuted instantiation: tr2_tgt_normal.c:strip_suffix Unexecuted instantiation: tr2_tgt_perf.c:strip_suffix Unexecuted instantiation: tr2_tls.c:strip_suffix Unexecuted instantiation: tr2_tmr.c:strip_suffix Unexecuted instantiation: transport.c:strip_suffix Unexecuted instantiation: tree-diff.c:strip_suffix Unexecuted instantiation: tree-walk.c:strip_suffix Unexecuted instantiation: tree.c:strip_suffix Unexecuted instantiation: url.c:strip_suffix Unexecuted instantiation: urlmatch.c:strip_suffix Unexecuted instantiation: usage.c:strip_suffix Unexecuted instantiation: utf8.c:strip_suffix Unexecuted instantiation: version.c:strip_suffix Unexecuted instantiation: worktree.c:strip_suffix Unexecuted instantiation: wrapper.c:strip_suffix Unexecuted instantiation: wt-status.c:strip_suffix Unexecuted instantiation: procinfo.c:strip_suffix Unexecuted instantiation: fopen.c:strip_suffix Unexecuted instantiation: strlcpy.c:strip_suffix Unexecuted instantiation: qsort_s.c:strip_suffix Unexecuted instantiation: abspath.c:strip_suffix Unexecuted instantiation: advice.c:strip_suffix Unexecuted instantiation: bisect.c:strip_suffix Unexecuted instantiation: bloom.c:strip_suffix Unexecuted instantiation: branch.c:strip_suffix Unexecuted instantiation: bundle-uri.c:strip_suffix Unexecuted instantiation: bundle.c:strip_suffix Unexecuted instantiation: cache-tree.c:strip_suffix Unexecuted instantiation: chdir-notify.c:strip_suffix Unexecuted instantiation: color.c:strip_suffix Unexecuted instantiation: combine-diff.c:strip_suffix Unexecuted instantiation: commit-graph.c:strip_suffix Unexecuted instantiation: commit-reach.c:strip_suffix Unexecuted instantiation: commit.c:strip_suffix Unexecuted instantiation: config.c:strip_suffix Unexecuted instantiation: connect.c:strip_suffix Unexecuted instantiation: connected.c:strip_suffix Unexecuted instantiation: convert.c:strip_suffix Unexecuted instantiation: copy.c:strip_suffix Unexecuted instantiation: date.c:strip_suffix Unexecuted instantiation: diff-merges.c:strip_suffix Unexecuted instantiation: diff-lib.c:strip_suffix Unexecuted instantiation: diff.c:strip_suffix Unexecuted instantiation: diffcore-order.c:strip_suffix Unexecuted instantiation: diffcore-pickaxe.c:strip_suffix Unexecuted instantiation: diffcore-rename.c:strip_suffix Unexecuted instantiation: diffcore-rotate.c:strip_suffix Unexecuted instantiation: dir.c:strip_suffix Unexecuted instantiation: editor.c:strip_suffix Unexecuted instantiation: environment.c:strip_suffix Unexecuted instantiation: ewah_io.c:strip_suffix Unexecuted instantiation: exec-cmd.c:strip_suffix Unexecuted instantiation: fetch-object-info.c:strip_suffix Unexecuted instantiation: fetch-pack.c:strip_suffix Unexecuted instantiation: fsck.c:strip_suffix Unexecuted instantiation: fsmonitor.c:strip_suffix Unexecuted instantiation: fsmonitor-ipc.c:strip_suffix Unexecuted instantiation: fsmonitor-settings.c:strip_suffix Unexecuted instantiation: gpg-interface.c:strip_suffix Unexecuted instantiation: graph.c:strip_suffix Unexecuted instantiation: grep.c:strip_suffix Unexecuted instantiation: hex.c:strip_suffix Unexecuted instantiation: hook.c:strip_suffix Unexecuted instantiation: ident.c:strip_suffix Unexecuted instantiation: json-writer.c:strip_suffix Unexecuted instantiation: line-log.c:strip_suffix Unexecuted instantiation: list-objects-filter-options.c:strip_suffix Unexecuted instantiation: list-objects.c:strip_suffix Unexecuted instantiation: lockfile.c:strip_suffix Unexecuted instantiation: log-tree.c:strip_suffix Unexecuted instantiation: mailmap.c:strip_suffix Unexecuted instantiation: merge-ll.c:strip_suffix Unexecuted instantiation: merge-ort.c:strip_suffix Unexecuted instantiation: midx.c:strip_suffix Unexecuted instantiation: name-hash.c:strip_suffix Unexecuted instantiation: notes-cache.c:strip_suffix Unexecuted instantiation: notes.c:strip_suffix Unexecuted instantiation: object-file-convert.c:strip_suffix Unexecuted instantiation: object-file.c:strip_suffix Unexecuted instantiation: object-name.c:strip_suffix Unexecuted instantiation: odb.c:strip_suffix Unexecuted instantiation: source-files.c:strip_suffix Unexecuted instantiation: source-loose.c:strip_suffix Unexecuted instantiation: source-packed.c:strip_suffix Unexecuted instantiation: oidset.c:strip_suffix Unexecuted instantiation: pack-bitmap.c:strip_suffix Unexecuted instantiation: pack-mtimes.c:strip_suffix Unexecuted instantiation: pack-revindex.c:strip_suffix Unexecuted instantiation: pack-write.c:strip_suffix Unexecuted instantiation: parse-options-cb.c:strip_suffix Unexecuted instantiation: parse-options.c:strip_suffix Unexecuted instantiation: patch-ids.c:strip_suffix Unexecuted instantiation: path.c:strip_suffix Unexecuted instantiation: pathspec.c:strip_suffix Unexecuted instantiation: pkt-line.c:strip_suffix Unexecuted instantiation: pretty.c:strip_suffix Unexecuted instantiation: progress.c:strip_suffix Unexecuted instantiation: pseudo-merge.c:strip_suffix Unexecuted instantiation: quote.c:strip_suffix Unexecuted instantiation: range-diff.c:strip_suffix Unexecuted instantiation: read-cache.c:strip_suffix Unexecuted instantiation: reflog-walk.c:strip_suffix Unexecuted instantiation: refs.c:strip_suffix Unexecuted instantiation: debug.c:strip_suffix Unexecuted instantiation: files-backend.c:strip_suffix Unexecuted instantiation: reftable-backend.c:strip_suffix Unexecuted instantiation: iterator.c:strip_suffix Unexecuted instantiation: packed-backend.c:strip_suffix Unexecuted instantiation: ref-cache.c:strip_suffix Unexecuted instantiation: refspec.c:strip_suffix Unexecuted instantiation: repack.c:strip_suffix Unexecuted instantiation: repack-geometry.c:strip_suffix Unexecuted instantiation: replace-object.c:strip_suffix Unexecuted instantiation: resolve-undo.c:strip_suffix Unexecuted instantiation: send-pack.c:strip_suffix Unexecuted instantiation: sequencer.c:strip_suffix Unexecuted instantiation: sideband.c:strip_suffix Unexecuted instantiation: split-index.c:strip_suffix Unexecuted instantiation: sub-process.c:strip_suffix Unexecuted instantiation: tmp-objdir.c:strip_suffix Unexecuted instantiation: trailer.c:strip_suffix Unexecuted instantiation: transport-helper.c:strip_suffix Unexecuted instantiation: unpack-trees.c:strip_suffix Unexecuted instantiation: userdiff.c:strip_suffix Unexecuted instantiation: ws.c:strip_suffix Unexecuted instantiation: xdiff-interface.c:strip_suffix Unexecuted instantiation: system.c:strip_suffix Unexecuted instantiation: ipc-unix-socket.c:strip_suffix Unexecuted instantiation: sha1.c:strip_suffix Unexecuted instantiation: ubc_check.c:strip_suffix Unexecuted instantiation: fsm-ipc-unix.c:strip_suffix Unexecuted instantiation: fsm-settings-unix.c:strip_suffix Unexecuted instantiation: fsm-path-utils-linux.c:strip_suffix Unexecuted instantiation: alias.c:strip_suffix Unexecuted instantiation: apply.c:strip_suffix Unexecuted instantiation: attr.c:strip_suffix Unexecuted instantiation: dir-iterator.c:strip_suffix Unexecuted instantiation: entry.c:strip_suffix Unexecuted instantiation: list-objects-filter.c:strip_suffix Unexecuted instantiation: loose.c:strip_suffix Unexecuted instantiation: match-trees.c:strip_suffix Unexecuted instantiation: merge-ort-wrappers.c:strip_suffix Unexecuted instantiation: merge.c:strip_suffix Unexecuted instantiation: default.c:strip_suffix Unexecuted instantiation: skipping.c:strip_suffix Unexecuted instantiation: notes-utils.c:strip_suffix Unexecuted instantiation: pack-bitmap-write.c:strip_suffix Unexecuted instantiation: parallel-checkout.c:strip_suffix Unexecuted instantiation: preload-index.c:strip_suffix Unexecuted instantiation: rebase-interactive.c:strip_suffix Unexecuted instantiation: rerere.c:strip_suffix Unexecuted instantiation: reset.c:strip_suffix Unexecuted instantiation: unix-socket.c:strip_suffix Unexecuted instantiation: unix-stream-server.c:strip_suffix |
559 | | |
560 | 0 | #define SWAP(a, b) do { \ |
561 | 0 | void *_swap_a_ptr = &(a); \ |
562 | 0 | void *_swap_b_ptr = &(b); \ |
563 | 0 | unsigned char _swap_buffer[sizeof(a)]; \ |
564 | 0 | memcpy(_swap_buffer, _swap_a_ptr, sizeof(a)); \ |
565 | 0 | memcpy(_swap_a_ptr, _swap_b_ptr, sizeof(a) + \ |
566 | 0 | BUILD_ASSERT_OR_ZERO(sizeof(a) == sizeof(b))); \ |
567 | 0 | memcpy(_swap_b_ptr, _swap_buffer, sizeof(a)); \ |
568 | 0 | } while (0) |
569 | | |
570 | | #ifdef NO_MMAP |
571 | | |
572 | | /* This value must be multiple of (pagesize * 2) */ |
573 | | #define DEFAULT_PACKED_GIT_WINDOW_SIZE (1 * 1024 * 1024) |
574 | | |
575 | | #else /* NO_MMAP */ |
576 | | |
577 | | /* This value must be multiple of (pagesize * 2) */ |
578 | | #define DEFAULT_PACKED_GIT_WINDOW_SIZE \ |
579 | 0 | (sizeof(void*) >= 8 \ |
580 | 0 | ? 1 * 1024 * 1024 * 1024 \ |
581 | 0 | : 32 * 1024 * 1024) |
582 | | |
583 | | #endif /* NO_MMAP */ |
584 | | |
585 | | #ifdef NO_ST_BLOCKS_IN_STRUCT_STAT |
586 | | #define on_disk_bytes(st) ((st).st_size) |
587 | | #else |
588 | | #define on_disk_bytes(st) ((st).st_blocks * 512) |
589 | | #endif |
590 | | |
591 | | #define DEFAULT_PACKED_GIT_LIMIT \ |
592 | 0 | ((1024L * 1024L) * (size_t)(sizeof(void*) >= 8 ? (32 * 1024L * 1024L) : 256)) |
593 | | |
594 | | #ifdef _MSC_VER |
595 | | /* |
596 | | * When traversing into too-deep trees, Visual C-compiled Git seems to |
597 | | * run into some internal stack overflow detection in the |
598 | | * `RtlpAllocateHeap()` function that is called from within |
599 | | * `git_inflate_init()`'s call tree. The following value seems to be |
600 | | * low enough to avoid that by letting Git exit with an error before |
601 | | * the stack overflow can occur. |
602 | | */ |
603 | | #define DEFAULT_MAX_ALLOWED_TREE_DEPTH 512 |
604 | | #elif defined(GIT_WINDOWS_NATIVE) && defined(__clang__) && defined(__aarch64__) |
605 | | /* |
606 | | * Similar to Visual C, it seems that on Windows/ARM64 the clang-based |
607 | | * builds have a smaller stack space available. When running out of |
608 | | * that stack space, a `STATUS_STACK_OVERFLOW` is produced. When the |
609 | | * Git command was run from an MSYS2 Bash, this unfortunately results |
610 | | * in an exit code 127. Let's prevent that by lowering the maximal |
611 | | * tree depth; This value seems to be low enough. |
612 | | */ |
613 | | #define DEFAULT_MAX_ALLOWED_TREE_DEPTH 1280 |
614 | | #else |
615 | 0 | #define DEFAULT_MAX_ALLOWED_TREE_DEPTH 2048 |
616 | | #endif |
617 | | |
618 | | int git_open_cloexec(const char *name, int flags); |
619 | 0 | #define git_open(name) git_open_cloexec(name, O_RDONLY) |
620 | | |
621 | | |
622 | | /* |
623 | | * Help Clang; GCC generates the same instructions for both variants on |
624 | | * x64 and aarch64. |
625 | | */ |
626 | | #ifdef __clang__ |
627 | 268 | #define st_add_overflow __builtin_add_overflow |
628 | | #else |
629 | | static inline bool st_add_overflow(size_t a, size_t b, size_t *out) |
630 | | { |
631 | | if (unsigned_add_overflows(a, b)) |
632 | | return true; |
633 | | *out = a + b; |
634 | | return false; |
635 | | } |
636 | | #endif |
637 | | |
638 | | static inline size_t st_add(size_t a, size_t b) |
639 | 268 | { |
640 | 268 | size_t result; |
641 | 268 | if (st_add_overflow(a, b, &result)) |
642 | 0 | die("size_t overflow: %"PRIuMAX" + %"PRIuMAX, |
643 | 0 | (uintmax_t)a, (uintmax_t)b); |
644 | 268 | return result; |
645 | 268 | } Line | Count | Source | 639 | 268 | { | 640 | 268 | size_t result; | 641 | 268 | if (st_add_overflow(a, b, &result)) | 642 | 0 | die("size_t overflow: %"PRIuMAX" + %"PRIuMAX, | 643 | 0 | (uintmax_t)a, (uintmax_t)b); | 644 | 268 | return result; | 645 | 268 | } |
Unexecuted instantiation: promisor-remote.c:st_add Unexecuted instantiation: remote.c:st_add Unexecuted instantiation: repository.c:st_add Unexecuted instantiation: revision.c:st_add Unexecuted instantiation: sparse-index.c:st_add Unexecuted instantiation: strbuf.c:st_add Unexecuted instantiation: strmap.c:st_add Unexecuted instantiation: submodule-config.c:st_add Unexecuted instantiation: submodule.c:st_add Unexecuted instantiation: tree-diff.c:st_add Unexecuted instantiation: tree-walk.c:st_add Unexecuted instantiation: tree.c:st_add Unexecuted instantiation: utf8.c:st_add Unexecuted instantiation: procinfo.c:st_add Unexecuted instantiation: fopen.c:st_add Unexecuted instantiation: strlcpy.c:st_add Unexecuted instantiation: qsort_s.c:st_add Unexecuted instantiation: bloom.c:st_add Unexecuted instantiation: branch.c:st_add Unexecuted instantiation: cache-tree.c:st_add Unexecuted instantiation: combine-diff.c:st_add Unexecuted instantiation: commit-graph.c:st_add Unexecuted instantiation: commit.c:st_add Unexecuted instantiation: diff-lib.c:st_add Unexecuted instantiation: diff.c:st_add Unexecuted instantiation: diffcore-delta.c:st_add Unexecuted instantiation: dir.c:st_add Unexecuted instantiation: fsck.c:st_add Unexecuted instantiation: hashmap.c:st_add Unexecuted instantiation: line-log.c:st_add Unexecuted instantiation: list-objects.c:st_add Unexecuted instantiation: log-tree.c:st_add Unexecuted instantiation: mem-pool.c:st_add Unexecuted instantiation: merge-ort.c:st_add Unexecuted instantiation: name-hash.c:st_add Unexecuted instantiation: notes.c:st_add Unexecuted instantiation: object-file.c:st_add Unexecuted instantiation: object-name.c:st_add Unexecuted instantiation: pack-bitmap.c:st_add Unexecuted instantiation: pack-mtimes.c:st_add Unexecuted instantiation: parse-options-cb.c:st_add Unexecuted instantiation: path.c:st_add Unexecuted instantiation: read-cache.c:st_add Unexecuted instantiation: refs.c:st_add Unexecuted instantiation: files-backend.c:st_add Unexecuted instantiation: ref-cache.c:st_add Unexecuted instantiation: sequencer.c:st_add Unexecuted instantiation: unpack-trees.c:st_add Unexecuted instantiation: system.c:st_add Unexecuted instantiation: sha1.c:st_add Unexecuted instantiation: ubc_check.c:st_add Unexecuted instantiation: fsm-ipc-unix.c:st_add Unexecuted instantiation: fsm-settings-unix.c:st_add Unexecuted instantiation: fsm-path-utils-linux.c:st_add Unexecuted instantiation: apply.c:st_add Unexecuted instantiation: attr.c:st_add Unexecuted instantiation: match-trees.c:st_add Unexecuted instantiation: merge.c:st_add Unexecuted instantiation: pack-bitmap-write.c:st_add Unexecuted instantiation: rerere.c:st_add Unexecuted instantiation: reset.c:st_add |
646 | 0 | #define st_add3(a,b,c) st_add(st_add((a),(b)),(c)) |
647 | 0 | #define st_add4(a,b,c,d) st_add(st_add3((a),(b),(c)),(d)) |
648 | | |
649 | | static inline size_t st_mult(size_t a, size_t b) |
650 | 268 | { |
651 | 268 | if (unsigned_mult_overflows(a, b)) |
652 | 0 | die("size_t overflow: %"PRIuMAX" * %"PRIuMAX, |
653 | 0 | (uintmax_t)a, (uintmax_t)b); |
654 | 268 | return a * b; |
655 | 268 | } Unexecuted instantiation: fuzz-pack-idx.c:st_mult Line | Count | Source | 650 | 268 | { | 651 | 268 | if (unsigned_mult_overflows(a, b)) | 652 | 0 | die("size_t overflow: %"PRIuMAX" * %"PRIuMAX, | 653 | 0 | (uintmax_t)a, (uintmax_t)b); | 654 | 268 | return a * b; | 655 | 268 | } |
Unexecuted instantiation: packfile-list.c:st_mult Unexecuted instantiation: promisor-remote.c:st_mult Unexecuted instantiation: remote.c:st_mult Unexecuted instantiation: repo-settings.c:st_mult Unexecuted instantiation: repository.c:st_mult Unexecuted instantiation: revision.c:st_mult Unexecuted instantiation: run-command.c:st_mult Unexecuted instantiation: setup.c:st_mult Unexecuted instantiation: shallow.c:st_mult Unexecuted instantiation: sigchain.c:st_mult Unexecuted instantiation: sparse-index.c:st_mult Unexecuted instantiation: strbuf.c:st_mult Unexecuted instantiation: string-list.c:st_mult Unexecuted instantiation: strvec.c:st_mult Unexecuted instantiation: submodule-config.c:st_mult Unexecuted instantiation: submodule.c:st_mult Unexecuted instantiation: tag.c:st_mult Unexecuted instantiation: trace2.c:st_mult Unexecuted instantiation: tr2_tls.c:st_mult Unexecuted instantiation: transport.c:st_mult Unexecuted instantiation: tree-diff.c:st_mult Unexecuted instantiation: tree-walk.c:st_mult Unexecuted instantiation: tree.c:st_mult Unexecuted instantiation: utf8.c:st_mult Unexecuted instantiation: worktree.c:st_mult Unexecuted instantiation: wt-status.c:st_mult Unexecuted instantiation: procinfo.c:st_mult Unexecuted instantiation: fopen.c:st_mult Unexecuted instantiation: strlcpy.c:st_mult Unexecuted instantiation: qsort_s.c:st_mult Unexecuted instantiation: alloc.c:st_mult Unexecuted instantiation: bisect.c:st_mult Unexecuted instantiation: bloom.c:st_mult Unexecuted instantiation: branch.c:st_mult Unexecuted instantiation: bundle-uri.c:st_mult Unexecuted instantiation: bundle.c:st_mult Unexecuted instantiation: cache-tree.c:st_mult Unexecuted instantiation: column.c:st_mult Unexecuted instantiation: combine-diff.c:st_mult Unexecuted instantiation: commit-graph.c:st_mult Unexecuted instantiation: commit-reach.c:st_mult Unexecuted instantiation: commit.c:st_mult Unexecuted instantiation: config.c:st_mult Unexecuted instantiation: connected.c:st_mult Unexecuted instantiation: convert.c:st_mult Unexecuted instantiation: diff-merges.c:st_mult Unexecuted instantiation: diff-lib.c:st_mult Unexecuted instantiation: diff.c:st_mult Unexecuted instantiation: diffcore-delta.c:st_mult Unexecuted instantiation: diffcore-order.c:st_mult Unexecuted instantiation: diffcore-pickaxe.c:st_mult Unexecuted instantiation: diffcore-rename.c:st_mult Unexecuted instantiation: dir.c:st_mult Unexecuted instantiation: bitmap.c:st_mult Unexecuted instantiation: ewah_bitmap.c:st_mult Unexecuted instantiation: ewah_io.c:st_mult Unexecuted instantiation: fetch-object-info.c:st_mult Unexecuted instantiation: fetch-pack.c:st_mult Unexecuted instantiation: fsck.c:st_mult Unexecuted instantiation: graph.c:st_mult Unexecuted instantiation: grep.c:st_mult Unexecuted instantiation: hashmap.c:st_mult Unexecuted instantiation: kwset.c:st_mult Unexecuted instantiation: line-log.c:st_mult Unexecuted instantiation: list-objects-filter-options.c:st_mult Unexecuted instantiation: list-objects.c:st_mult Unexecuted instantiation: log-tree.c:st_mult Unexecuted instantiation: mailmap.c:st_mult Unexecuted instantiation: mem-pool.c:st_mult Unexecuted instantiation: merge-ort.c:st_mult Unexecuted instantiation: midx.c:st_mult Unexecuted instantiation: notes-cache.c:st_mult Unexecuted instantiation: notes.c:st_mult Unexecuted instantiation: object-file-convert.c:st_mult Unexecuted instantiation: object-file.c:st_mult Unexecuted instantiation: object-name.c:st_mult Unexecuted instantiation: object.c:st_mult Unexecuted instantiation: odb.c:st_mult Unexecuted instantiation: source.c:st_mult Unexecuted instantiation: source-files.c:st_mult Unexecuted instantiation: source-inmemory.c:st_mult Unexecuted instantiation: source-loose.c:st_mult Unexecuted instantiation: source-packed.c:st_mult Unexecuted instantiation: streaming.c:st_mult Unexecuted instantiation: transaction.c:st_mult Unexecuted instantiation: oid-array.c:st_mult Unexecuted instantiation: oidset.c:st_mult Unexecuted instantiation: pack-bitmap.c:st_mult Unexecuted instantiation: pack-check.c:st_mult Unexecuted instantiation: pack-mtimes.c:st_mult Unexecuted instantiation: pack-objects.c:st_mult Unexecuted instantiation: pack-revindex.c:st_mult Unexecuted instantiation: pack-write.c:st_mult Unexecuted instantiation: parse-options-cb.c:st_mult Unexecuted instantiation: parse-options.c:st_mult Unexecuted instantiation: path.c:st_mult Unexecuted instantiation: pathspec.c:st_mult Unexecuted instantiation: pretty.c:st_mult Unexecuted instantiation: prio-queue.c:st_mult Unexecuted instantiation: pseudo-merge.c:st_mult Unexecuted instantiation: range-diff.c:st_mult Unexecuted instantiation: read-cache.c:st_mult Unexecuted instantiation: reflog-walk.c:st_mult Unexecuted instantiation: refs.c:st_mult Unexecuted instantiation: files-backend.c:st_mult Unexecuted instantiation: reftable-backend.c:st_mult Unexecuted instantiation: packed-backend.c:st_mult Unexecuted instantiation: ref-cache.c:st_mult Unexecuted instantiation: refspec.c:st_mult Unexecuted instantiation: repack.c:st_mult Unexecuted instantiation: repack-geometry.c:st_mult Unexecuted instantiation: replace-object.c:st_mult Unexecuted instantiation: send-pack.c:st_mult Unexecuted instantiation: sequencer.c:st_mult Unexecuted instantiation: split-index.c:st_mult Unexecuted instantiation: stable-qsort.c:st_mult Unexecuted instantiation: tmp-objdir.c:st_mult Unexecuted instantiation: trailer.c:st_mult Unexecuted instantiation: transport-helper.c:st_mult Unexecuted instantiation: unpack-trees.c:st_mult Unexecuted instantiation: userdiff.c:st_mult Unexecuted instantiation: xdiff-interface.c:st_mult Unexecuted instantiation: system.c:st_mult Unexecuted instantiation: sha1.c:st_mult Unexecuted instantiation: ubc_check.c:st_mult Unexecuted instantiation: fsm-ipc-unix.c:st_mult Unexecuted instantiation: fsm-settings-unix.c:st_mult Unexecuted instantiation: fsm-path-utils-linux.c:st_mult Unexecuted instantiation: alias.c:st_mult Unexecuted instantiation: apply.c:st_mult Unexecuted instantiation: attr.c:st_mult Unexecuted instantiation: chunk-format.c:st_mult Unexecuted instantiation: diff-delta.c:st_mult Unexecuted instantiation: dir-iterator.c:st_mult Unexecuted instantiation: entry.c:st_mult Unexecuted instantiation: linear-assignment.c:st_mult Unexecuted instantiation: list-objects-filter.c:st_mult Unexecuted instantiation: loose.c:st_mult Unexecuted instantiation: match-trees.c:st_mult Unexecuted instantiation: pack-bitmap-write.c:st_mult Unexecuted instantiation: parallel-checkout.c:st_mult Unexecuted instantiation: rebase-interactive.c:st_mult Unexecuted instantiation: rerere.c:st_mult |
656 | | |
657 | | static inline size_t st_sub(size_t a, size_t b) |
658 | 0 | { |
659 | 0 | if (a < b) |
660 | 0 | die("size_t underflow: %"PRIuMAX" - %"PRIuMAX, |
661 | 0 | (uintmax_t)a, (uintmax_t)b); |
662 | 0 | return a - b; |
663 | 0 | } Unexecuted instantiation: procinfo.c:st_sub Unexecuted instantiation: fopen.c:st_sub Unexecuted instantiation: strlcpy.c:st_sub Unexecuted instantiation: qsort_s.c:st_sub Unexecuted instantiation: pack-bitmap.c:st_sub Unexecuted instantiation: system.c:st_sub Unexecuted instantiation: sha1.c:st_sub Unexecuted instantiation: ubc_check.c:st_sub Unexecuted instantiation: fsm-ipc-unix.c:st_sub Unexecuted instantiation: fsm-settings-unix.c:st_sub Unexecuted instantiation: fsm-path-utils-linux.c:st_sub Unexecuted instantiation: apply.c:st_sub |
664 | | |
665 | | static inline size_t st_left_shift(size_t a, unsigned shift) |
666 | 0 | { |
667 | 0 | if (unsigned_left_shift_overflows(a, shift)) |
668 | 0 | die("size_t overflow: %"PRIuMAX" << %u", |
669 | 0 | (uintmax_t)a, shift); |
670 | 0 | return a << shift; |
671 | 0 | } Unexecuted instantiation: packfile.c:st_left_shift Unexecuted instantiation: patch-delta.c:st_left_shift Unexecuted instantiation: procinfo.c:st_left_shift Unexecuted instantiation: fopen.c:st_left_shift Unexecuted instantiation: strlcpy.c:st_left_shift Unexecuted instantiation: qsort_s.c:st_left_shift Unexecuted instantiation: diff.c:st_left_shift Unexecuted instantiation: system.c:st_left_shift Unexecuted instantiation: sha1.c:st_left_shift Unexecuted instantiation: ubc_check.c:st_left_shift Unexecuted instantiation: fsm-ipc-unix.c:st_left_shift Unexecuted instantiation: fsm-settings-unix.c:st_left_shift Unexecuted instantiation: fsm-path-utils-linux.c:st_left_shift Unexecuted instantiation: apply.c:st_left_shift Unexecuted instantiation: diff-delta.c:st_left_shift |
672 | | |
673 | | static inline unsigned long cast_size_t_to_ulong(size_t a) |
674 | 0 | { |
675 | 0 | if (a != (unsigned long)a) |
676 | 0 | die("object too large to read on this platform: %" |
677 | 0 | PRIuMAX" is cut off to %lu", |
678 | 0 | (uintmax_t)a, (unsigned long)a); |
679 | 0 | return (unsigned long)a; |
680 | 0 | } Unexecuted instantiation: tree-walk.c:cast_size_t_to_ulong Unexecuted instantiation: procinfo.c:cast_size_t_to_ulong Unexecuted instantiation: fopen.c:cast_size_t_to_ulong Unexecuted instantiation: strlcpy.c:cast_size_t_to_ulong Unexecuted instantiation: qsort_s.c:cast_size_t_to_ulong Unexecuted instantiation: combine-diff.c:cast_size_t_to_ulong Unexecuted instantiation: commit.c:cast_size_t_to_ulong Unexecuted instantiation: diff.c:cast_size_t_to_ulong Unexecuted instantiation: grep.c:cast_size_t_to_ulong Unexecuted instantiation: pack-bitmap.c:cast_size_t_to_ulong Unexecuted instantiation: read-cache.c:cast_size_t_to_ulong Unexecuted instantiation: system.c:cast_size_t_to_ulong Unexecuted instantiation: sha1.c:cast_size_t_to_ulong Unexecuted instantiation: ubc_check.c:cast_size_t_to_ulong Unexecuted instantiation: fsm-ipc-unix.c:cast_size_t_to_ulong Unexecuted instantiation: fsm-settings-unix.c:cast_size_t_to_ulong Unexecuted instantiation: fsm-path-utils-linux.c:cast_size_t_to_ulong |
681 | | |
682 | | static inline uint32_t cast_size_t_to_uint32_t(size_t a) |
683 | 0 | { |
684 | 0 | if (a != (uint32_t)a) |
685 | 0 | die("object too large to read on this platform: %" |
686 | 0 | PRIuMAX" is cut off to %u", |
687 | 0 | (uintmax_t)a, (uint32_t)a); |
688 | 0 | return (uint32_t)a; |
689 | 0 | } Unexecuted instantiation: procinfo.c:cast_size_t_to_uint32_t Unexecuted instantiation: fopen.c:cast_size_t_to_uint32_t Unexecuted instantiation: strlcpy.c:cast_size_t_to_uint32_t Unexecuted instantiation: qsort_s.c:cast_size_t_to_uint32_t Unexecuted instantiation: pack-bitmap.c:cast_size_t_to_uint32_t Unexecuted instantiation: system.c:cast_size_t_to_uint32_t Unexecuted instantiation: sha1.c:cast_size_t_to_uint32_t Unexecuted instantiation: ubc_check.c:cast_size_t_to_uint32_t Unexecuted instantiation: fsm-ipc-unix.c:cast_size_t_to_uint32_t Unexecuted instantiation: fsm-settings-unix.c:cast_size_t_to_uint32_t Unexecuted instantiation: fsm-path-utils-linux.c:cast_size_t_to_uint32_t |
690 | | |
691 | | static inline int cast_size_t_to_int(size_t a) |
692 | 0 | { |
693 | 0 | if (a > INT_MAX) |
694 | 0 | die("number too large to represent as int on this platform: %"PRIuMAX, |
695 | 0 | (uintmax_t)a); |
696 | 0 | return (int)a; |
697 | 0 | } Unexecuted instantiation: utf8.c:cast_size_t_to_int Unexecuted instantiation: procinfo.c:cast_size_t_to_int Unexecuted instantiation: fopen.c:cast_size_t_to_int Unexecuted instantiation: strlcpy.c:cast_size_t_to_int Unexecuted instantiation: qsort_s.c:cast_size_t_to_int Unexecuted instantiation: pretty.c:cast_size_t_to_int Unexecuted instantiation: refs.c:cast_size_t_to_int Unexecuted instantiation: system.c:cast_size_t_to_int Unexecuted instantiation: sha1.c:cast_size_t_to_int Unexecuted instantiation: ubc_check.c:cast_size_t_to_int Unexecuted instantiation: fsm-ipc-unix.c:cast_size_t_to_int Unexecuted instantiation: fsm-settings-unix.c:cast_size_t_to_int Unexecuted instantiation: fsm-path-utils-linux.c:cast_size_t_to_int |
698 | | |
699 | | static inline uint64_t u64_mult(uint64_t a, uint64_t b) |
700 | 0 | { |
701 | 0 | if (unsigned_mult_overflows(a, b)) |
702 | 0 | die("uint64_t overflow: %"PRIuMAX" * %"PRIuMAX, |
703 | 0 | (uintmax_t)a, (uintmax_t)b); |
704 | 0 | return a * b; |
705 | 0 | } Unexecuted instantiation: procinfo.c:u64_mult Unexecuted instantiation: fopen.c:u64_mult Unexecuted instantiation: strlcpy.c:u64_mult Unexecuted instantiation: qsort_s.c:u64_mult Unexecuted instantiation: system.c:u64_mult Unexecuted instantiation: sha1.c:u64_mult Unexecuted instantiation: ubc_check.c:u64_mult Unexecuted instantiation: fsm-ipc-unix.c:u64_mult Unexecuted instantiation: fsm-settings-unix.c:u64_mult Unexecuted instantiation: fsm-path-utils-linux.c:u64_mult |
706 | | |
707 | | static inline uint64_t u64_add(uint64_t a, uint64_t b) |
708 | 0 | { |
709 | 0 | if (unsigned_add_overflows(a, b)) |
710 | 0 | die("uint64_t overflow: %"PRIuMAX" + %"PRIuMAX, |
711 | 0 | (uintmax_t)a, (uintmax_t)b); |
712 | 0 | return a + b; |
713 | 0 | } Unexecuted instantiation: procinfo.c:u64_add Unexecuted instantiation: fopen.c:u64_add Unexecuted instantiation: strlcpy.c:u64_add Unexecuted instantiation: qsort_s.c:u64_add Unexecuted instantiation: system.c:u64_add Unexecuted instantiation: sha1.c:u64_add Unexecuted instantiation: ubc_check.c:u64_add Unexecuted instantiation: fsm-ipc-unix.c:u64_add Unexecuted instantiation: fsm-settings-unix.c:u64_add Unexecuted instantiation: fsm-path-utils-linux.c:u64_add |
714 | | |
715 | | /* |
716 | | * Limit size of IO chunks, because huge chunks only cause pain. OS X |
717 | | * 64-bit is buggy, returning EINVAL if len >= INT_MAX; and even in |
718 | | * the absence of bugs, large chunks can result in bad latencies when |
719 | | * you decide to kill the process. |
720 | | * |
721 | | * We pick 8 MiB as our default, but if the platform defines SSIZE_MAX |
722 | | * that is smaller than that, clip it to SSIZE_MAX, as a call to |
723 | | * read(2) or write(2) larger than that is allowed to fail. As the last |
724 | | * resort, we allow a port to pass via CFLAGS e.g. "-DMAX_IO_SIZE=value" |
725 | | * to override this, if the definition of SSIZE_MAX given by the platform |
726 | | * is broken. |
727 | | */ |
728 | | #ifndef MAX_IO_SIZE |
729 | 301 | # define MAX_IO_SIZE_DEFAULT (8*1024*1024) |
730 | | # if defined(SSIZE_MAX) && (SSIZE_MAX < MAX_IO_SIZE_DEFAULT) |
731 | | # define MAX_IO_SIZE SSIZE_MAX |
732 | | # else |
733 | 301 | # define MAX_IO_SIZE MAX_IO_SIZE_DEFAULT |
734 | | # endif |
735 | | #endif |
736 | | |
737 | | /* |
738 | | * Default buffer size for buffered I/O in index-pack, unpack-objects, |
739 | | * and the hashfile layer in csum-file. |
740 | | */ |
741 | 0 | #define DEFAULT_IO_BUFFER_SIZE (128 * 1024) |
742 | | |
743 | | #ifdef HAVE_ALLOCA_H |
744 | | # include <alloca.h> |
745 | 0 | # define xalloca(size) (alloca(size)) |
746 | 0 | # define xalloca_free(p) do {} while (0) |
747 | | #else |
748 | | # define xalloca(size) (xmalloc(size)) |
749 | | # define xalloca_free(p) (free(p)) |
750 | | #endif |
751 | | |
752 | | /* |
753 | | * FREE_AND_NULL(ptr) is like free(ptr) followed by ptr = NULL. Note |
754 | | * that ptr is used twice, so don't pass e.g. ptr++. |
755 | | */ |
756 | 0 | #define FREE_AND_NULL(p) do { free(p); (p) = NULL; } while (0) |
757 | | |
758 | 0 | #define ALLOC_ARRAY(x, alloc) (x) = xmalloc(st_mult(sizeof(*(x)), (alloc))) |
759 | 0 | #define CALLOC_ARRAY(x, alloc) (x) = xcalloc((alloc), sizeof(*(x))) |
760 | 0 | #define REALLOC_ARRAY(x, alloc) (x) = xrealloc((x), st_mult(sizeof(*(x)), (alloc))) |
761 | 0 | #define MEMZERO_ARRAY(x, alloc) memset((x), 0x0, st_mult(sizeof(*(x)), (alloc))) |
762 | | |
763 | 0 | #define COPY_ARRAY(dst, src, n) copy_array((dst), (src), (n), sizeof(*(dst)) + \ |
764 | 0 | BARF_UNLESS_COPYABLE((dst), (src))) |
765 | | static inline void copy_array(void *dst, const void *src, size_t n, size_t size) |
766 | 0 | { |
767 | 0 | if (n) |
768 | 0 | memcpy(dst, src, st_mult(size, n)); |
769 | 0 | } Unexecuted instantiation: packfile.c:copy_array Unexecuted instantiation: transport.c:copy_array Unexecuted instantiation: procinfo.c:copy_array Unexecuted instantiation: fopen.c:copy_array Unexecuted instantiation: strlcpy.c:copy_array Unexecuted instantiation: qsort_s.c:copy_array Unexecuted instantiation: commit-graph.c:copy_array Unexecuted instantiation: commit-reach.c:copy_array Unexecuted instantiation: bitmap.c:copy_array Unexecuted instantiation: graph.c:copy_array Unexecuted instantiation: kwset.c:copy_array Unexecuted instantiation: line-log.c:copy_array Unexecuted instantiation: merge-ort.c:copy_array Unexecuted instantiation: pack-revindex.c:copy_array Unexecuted instantiation: parse-options-cb.c:copy_array Unexecuted instantiation: parse-options.c:copy_array Unexecuted instantiation: pathspec.c:copy_array Unexecuted instantiation: pretty.c:copy_array Unexecuted instantiation: sequencer.c:copy_array Unexecuted instantiation: split-index.c:copy_array Unexecuted instantiation: system.c:copy_array Unexecuted instantiation: sha1.c:copy_array Unexecuted instantiation: ubc_check.c:copy_array Unexecuted instantiation: fsm-ipc-unix.c:copy_array Unexecuted instantiation: fsm-settings-unix.c:copy_array Unexecuted instantiation: fsm-path-utils-linux.c:copy_array Unexecuted instantiation: apply.c:copy_array Unexecuted instantiation: attr.c:copy_array |
770 | | |
771 | 0 | #define MOVE_ARRAY(dst, src, n) move_array((dst), (src), (n), sizeof(*(dst)) + \ |
772 | 0 | BARF_UNLESS_COPYABLE((dst), (src))) |
773 | | static inline void move_array(void *dst, const void *src, size_t n, size_t size) |
774 | 0 | { |
775 | 0 | if (n) |
776 | 0 | memmove(dst, src, st_mult(size, n)); |
777 | 0 | } Unexecuted instantiation: shallow.c:move_array Unexecuted instantiation: string-list.c:move_array Unexecuted instantiation: procinfo.c:move_array Unexecuted instantiation: fopen.c:move_array Unexecuted instantiation: strlcpy.c:move_array Unexecuted instantiation: qsort_s.c:move_array Unexecuted instantiation: cache-tree.c:move_array Unexecuted instantiation: dir.c:move_array Unexecuted instantiation: parse-options.c:move_array Unexecuted instantiation: read-cache.c:move_array Unexecuted instantiation: sequencer.c:move_array Unexecuted instantiation: system.c:move_array Unexecuted instantiation: sha1.c:move_array Unexecuted instantiation: ubc_check.c:move_array Unexecuted instantiation: fsm-ipc-unix.c:move_array Unexecuted instantiation: fsm-settings-unix.c:move_array Unexecuted instantiation: fsm-path-utils-linux.c:move_array Unexecuted instantiation: apply.c:move_array |
778 | | |
779 | 0 | #define DUP_ARRAY(dst, src, n) do { \ |
780 | 0 | size_t dup_array_n_ = (n); \ |
781 | 0 | COPY_ARRAY(ALLOC_ARRAY((dst), dup_array_n_), (src), dup_array_n_); \ |
782 | 0 | } while (0) |
783 | | |
784 | | /* |
785 | | * These functions help you allocate structs with flex arrays, and copy |
786 | | * the data directly into the array. For example, if you had: |
787 | | * |
788 | | * struct foo { |
789 | | * int bar; |
790 | | * char name[FLEX_ARRAY]; |
791 | | * }; |
792 | | * |
793 | | * you can do: |
794 | | * |
795 | | * struct foo *f; |
796 | | * FLEX_ALLOC_MEM(f, name, src, len); |
797 | | * |
798 | | * to allocate a "foo" with the contents of "src" in the "name" field. |
799 | | * The resulting struct is automatically zero'd, and the flex-array field |
800 | | * is NUL-terminated (whether the incoming src buffer was or not). |
801 | | * |
802 | | * The FLEXPTR_* variants operate on structs that don't use flex-arrays, |
803 | | * but do want to store a pointer to some extra data in the same allocated |
804 | | * block. For example, if you have: |
805 | | * |
806 | | * struct foo { |
807 | | * char *name; |
808 | | * int bar; |
809 | | * }; |
810 | | * |
811 | | * you can do: |
812 | | * |
813 | | * struct foo *f; |
814 | | * FLEXPTR_ALLOC_STR(f, name, src); |
815 | | * |
816 | | * and "name" will point to a block of memory after the struct, which will be |
817 | | * freed along with the struct (but the pointer can be repointed anywhere). |
818 | | * |
819 | | * The *_STR variants accept a string parameter rather than a ptr/len |
820 | | * combination. |
821 | | * |
822 | | * Note that these macros will evaluate the first parameter multiple |
823 | | * times, and it must be assignable as an lvalue. |
824 | | */ |
825 | 0 | #define FLEX_ALLOC_MEM(x, flexname, buf, len) do { \ |
826 | 0 | size_t flex_array_len_ = (len); \ |
827 | 0 | (x) = xcalloc(1, st_add3(sizeof(*(x)), flex_array_len_, 1)); \ |
828 | 0 | memcpy((void *)(x)->flexname, (buf), flex_array_len_); \ |
829 | 0 | } while (0) |
830 | 0 | #define FLEXPTR_ALLOC_MEM(x, ptrname, buf, len) do { \ |
831 | 0 | size_t flex_array_len_ = (len); \ |
832 | 0 | (x) = xcalloc(1, st_add3(sizeof(*(x)), flex_array_len_, 1)); \ |
833 | 0 | memcpy((x) + 1, (buf), flex_array_len_); \ |
834 | 0 | (x)->ptrname = (void *)((x)+1); \ |
835 | 0 | } while(0) |
836 | | #define FLEX_ALLOC_STR(x, flexname, str) \ |
837 | 0 | FLEX_ALLOC_MEM((x), flexname, (str), strlen(str)) |
838 | | #define FLEXPTR_ALLOC_STR(x, ptrname, str) \ |
839 | 0 | FLEXPTR_ALLOC_MEM((x), ptrname, (str), strlen(str)) |
840 | | |
841 | 0 | #define alloc_nr(x) (((x)+16)*3/2) |
842 | | |
843 | | /** |
844 | | * Dynamically growing an array using realloc() is error prone and boring. |
845 | | * |
846 | | * Define your array with: |
847 | | * |
848 | | * - a pointer (`item`) that points at the array, initialized to `NULL` |
849 | | * (although please name the variable based on its contents, not on its |
850 | | * type); |
851 | | * |
852 | | * - an integer variable (`alloc`) that keeps track of how big the current |
853 | | * allocation is, initialized to `0`; |
854 | | * |
855 | | * - another integer variable (`nr`) to keep track of how many elements the |
856 | | * array currently has, initialized to `0`. |
857 | | * |
858 | | * Then before adding `n`th element to the item, call `ALLOC_GROW(item, n, |
859 | | * alloc)`. This ensures that the array can hold at least `n` elements by |
860 | | * calling `realloc(3)` and adjusting `alloc` variable. |
861 | | * |
862 | | * ------------ |
863 | | * sometype *item; |
864 | | * size_t nr; |
865 | | * size_t alloc |
866 | | * |
867 | | * for (i = 0; i < nr; i++) |
868 | | * if (we like item[i] already) |
869 | | * return; |
870 | | * |
871 | | * // we did not like any existing one, so add one |
872 | | * ALLOC_GROW(item, nr + 1, alloc); |
873 | | * item[nr++] = value you like; |
874 | | * ------------ |
875 | | * |
876 | | * You are responsible for updating the `nr` variable. |
877 | | * |
878 | | * If you need to specify the number of elements to allocate explicitly |
879 | | * then use the macro `REALLOC_ARRAY(item, alloc)` instead of `ALLOC_GROW`. |
880 | | * |
881 | | * Consider using ALLOC_GROW_BY instead of ALLOC_GROW as it has some |
882 | | * added niceties. |
883 | | * |
884 | | * DO NOT USE any expression with side-effect for 'x', 'nr', or 'alloc'. |
885 | | */ |
886 | | #define ALLOC_GROW(x, nr, alloc) \ |
887 | 0 | do { \ |
888 | 0 | if ((nr) > alloc) { \ |
889 | 0 | if (alloc_nr(alloc) < (nr)) \ |
890 | 0 | alloc = (nr); \ |
891 | 0 | else \ |
892 | 0 | alloc = alloc_nr(alloc); \ |
893 | 0 | REALLOC_ARRAY(x, alloc); \ |
894 | 0 | } \ |
895 | 0 | } while (0) |
896 | | |
897 | | /* |
898 | | * Similar to ALLOC_GROW but handles updating of the nr value and |
899 | | * zeroing the bytes of the newly-grown array elements. |
900 | | * |
901 | | * DO NOT USE any expression with side-effect for any of the |
902 | | * arguments. |
903 | | */ |
904 | | #define ALLOC_GROW_BY(x, nr, increase, alloc) \ |
905 | 0 | do { \ |
906 | 0 | if (increase) { \ |
907 | 0 | size_t new_nr = nr + (increase); \ |
908 | 0 | if (new_nr < nr) \ |
909 | 0 | BUG("negative growth in ALLOC_GROW_BY"); \ |
910 | 0 | ALLOC_GROW(x, new_nr, alloc); \ |
911 | 0 | memset((x) + nr, 0, sizeof(*(x)) * (increase)); \ |
912 | 0 | nr = new_nr; \ |
913 | 0 | } \ |
914 | 0 | } while (0) |
915 | | |
916 | | static inline char *xstrdup_or_null(const char *str) |
917 | 0 | { |
918 | 0 | return str ? xstrdup(str) : NULL; |
919 | 0 | } Unexecuted instantiation: remote.c:xstrdup_or_null Unexecuted instantiation: repository.c:xstrdup_or_null Unexecuted instantiation: setup.c:xstrdup_or_null Unexecuted instantiation: shallow.c:xstrdup_or_null Unexecuted instantiation: worktree.c:xstrdup_or_null Unexecuted instantiation: procinfo.c:xstrdup_or_null Unexecuted instantiation: fopen.c:xstrdup_or_null Unexecuted instantiation: strlcpy.c:xstrdup_or_null Unexecuted instantiation: qsort_s.c:xstrdup_or_null Unexecuted instantiation: config.c:xstrdup_or_null Unexecuted instantiation: diff.c:xstrdup_or_null Unexecuted instantiation: grep.c:xstrdup_or_null Unexecuted instantiation: hook.c:xstrdup_or_null Unexecuted instantiation: list-objects-filter-options.c:xstrdup_or_null Unexecuted instantiation: mailmap.c:xstrdup_or_null Unexecuted instantiation: notes.c:xstrdup_or_null Unexecuted instantiation: odb.c:xstrdup_or_null Unexecuted instantiation: pathspec.c:xstrdup_or_null Unexecuted instantiation: refs.c:xstrdup_or_null Unexecuted instantiation: reftable-backend.c:xstrdup_or_null Unexecuted instantiation: iterator.c:xstrdup_or_null Unexecuted instantiation: packed-backend.c:xstrdup_or_null Unexecuted instantiation: ref-cache.c:xstrdup_or_null Unexecuted instantiation: send-pack.c:xstrdup_or_null Unexecuted instantiation: trailer.c:xstrdup_or_null Unexecuted instantiation: transport-helper.c:xstrdup_or_null Unexecuted instantiation: unpack-trees.c:xstrdup_or_null Unexecuted instantiation: system.c:xstrdup_or_null Unexecuted instantiation: sha1.c:xstrdup_or_null Unexecuted instantiation: ubc_check.c:xstrdup_or_null Unexecuted instantiation: fsm-ipc-unix.c:xstrdup_or_null Unexecuted instantiation: fsm-settings-unix.c:xstrdup_or_null Unexecuted instantiation: fsm-path-utils-linux.c:xstrdup_or_null Unexecuted instantiation: apply.c:xstrdup_or_null |
920 | | |
921 | | static inline size_t xsize_t(off_t len) |
922 | 0 | { |
923 | 0 | if (len < 0 || (uintmax_t) len > SIZE_MAX) |
924 | 0 | die("Cannot handle files this big"); |
925 | 0 | return (size_t) len; |
926 | 0 | } Unexecuted instantiation: packfile.c:xsize_t Unexecuted instantiation: worktree.c:xsize_t Unexecuted instantiation: procinfo.c:xsize_t Unexecuted instantiation: fopen.c:xsize_t Unexecuted instantiation: strlcpy.c:xsize_t Unexecuted instantiation: qsort_s.c:xsize_t Unexecuted instantiation: combine-diff.c:xsize_t Unexecuted instantiation: commit-graph.c:xsize_t Unexecuted instantiation: config.c:xsize_t Unexecuted instantiation: diff.c:xsize_t Unexecuted instantiation: dir.c:xsize_t Unexecuted instantiation: grep.c:xsize_t Unexecuted instantiation: midx.c:xsize_t Unexecuted instantiation: object-file.c:xsize_t Unexecuted instantiation: source-loose.c:xsize_t Unexecuted instantiation: pack-bitmap.c:xsize_t Unexecuted instantiation: pack-mtimes.c:xsize_t Unexecuted instantiation: pack-revindex.c:xsize_t Unexecuted instantiation: read-cache.c:xsize_t Unexecuted instantiation: packed-backend.c:xsize_t Unexecuted instantiation: xdiff-interface.c:xsize_t Unexecuted instantiation: system.c:xsize_t Unexecuted instantiation: sha1.c:xsize_t Unexecuted instantiation: ubc_check.c:xsize_t Unexecuted instantiation: fsm-ipc-unix.c:xsize_t Unexecuted instantiation: fsm-settings-unix.c:xsize_t Unexecuted instantiation: fsm-path-utils-linux.c:xsize_t |
927 | | |
928 | | /* |
929 | | * Like skip_prefix, but compare case-insensitively. Note that the comparison |
930 | | * is done via tolower(), so it is strictly ASCII (no multi-byte characters or |
931 | | * locale-specific conversions). |
932 | | */ |
933 | | #define skip_iprefix(str, prefix, out) \ |
934 | 0 | skip_iprefix_impl((str), (prefix), CONST_OUTPARAM((str), (out))) |
935 | | static inline bool skip_iprefix_impl(const char *str, const char *prefix, |
936 | | const char **out) |
937 | 0 | { |
938 | 0 | do { |
939 | 0 | if (!*prefix) { |
940 | 0 | *out = str; |
941 | 0 | return true; |
942 | 0 | } |
943 | 0 | } while (tolower(*str++) == tolower(*prefix++)); |
944 | 0 | return false; |
945 | 0 | } Unexecuted instantiation: utf8.c:skip_iprefix_impl Unexecuted instantiation: procinfo.c:skip_iprefix_impl Unexecuted instantiation: fopen.c:skip_iprefix_impl Unexecuted instantiation: strlcpy.c:skip_iprefix_impl Unexecuted instantiation: qsort_s.c:skip_iprefix_impl Unexecuted instantiation: convert.c:skip_iprefix_impl Unexecuted instantiation: read-cache.c:skip_iprefix_impl Unexecuted instantiation: system.c:skip_iprefix_impl Unexecuted instantiation: sha1.c:skip_iprefix_impl Unexecuted instantiation: ubc_check.c:skip_iprefix_impl Unexecuted instantiation: fsm-ipc-unix.c:skip_iprefix_impl Unexecuted instantiation: fsm-settings-unix.c:skip_iprefix_impl Unexecuted instantiation: fsm-path-utils-linux.c:skip_iprefix_impl |
946 | | |
947 | | /* |
948 | | * Like skip_prefix_mem, but compare case-insensitively. Note that the |
949 | | * comparison is done via tolower(), so it is strictly ASCII (no multi-byte |
950 | | * characters or locale-specific conversions). |
951 | | */ |
952 | | static inline bool skip_iprefix_mem(const char *buf, size_t len, |
953 | | const char *prefix, |
954 | | const char **out, size_t *outlen) |
955 | 0 | { |
956 | 0 | do { |
957 | 0 | if (!*prefix) { |
958 | 0 | *out = buf; |
959 | 0 | *outlen = len; |
960 | 0 | return true; |
961 | 0 | } |
962 | 0 | } while (len-- > 0 && tolower(*buf++) == tolower(*prefix++)); |
963 | 0 | return false; |
964 | 0 | } Unexecuted instantiation: procinfo.c:skip_iprefix_mem Unexecuted instantiation: fopen.c:skip_iprefix_mem Unexecuted instantiation: strlcpy.c:skip_iprefix_mem Unexecuted instantiation: qsort_s.c:skip_iprefix_mem Unexecuted instantiation: system.c:skip_iprefix_mem Unexecuted instantiation: sha1.c:skip_iprefix_mem Unexecuted instantiation: ubc_check.c:skip_iprefix_mem Unexecuted instantiation: fsm-ipc-unix.c:skip_iprefix_mem Unexecuted instantiation: fsm-settings-unix.c:skip_iprefix_mem Unexecuted instantiation: fsm-path-utils-linux.c:skip_iprefix_mem |
965 | | |
966 | | static inline int strtoul_ui(char const *s, int base, unsigned int *result) |
967 | 0 | { |
968 | 0 | unsigned long ul; |
969 | 0 | char *p; |
970 | 0 |
|
971 | 0 | errno = 0; |
972 | 0 | /* negative values would be accepted by strtoul */ |
973 | 0 | if (strchr(s, '-')) |
974 | 0 | return -1; |
975 | 0 | ul = strtoul(s, &p, base); |
976 | 0 | if (errno || *p || p == s || (unsigned int) ul != ul) |
977 | 0 | return -1; |
978 | 0 | *result = ul; |
979 | 0 | return 0; |
980 | 0 | } Unexecuted instantiation: procinfo.c:strtoul_ui Unexecuted instantiation: fopen.c:strtoul_ui Unexecuted instantiation: strlcpy.c:strtoul_ui Unexecuted instantiation: qsort_s.c:strtoul_ui Unexecuted instantiation: system.c:strtoul_ui Unexecuted instantiation: sha1.c:strtoul_ui Unexecuted instantiation: ubc_check.c:strtoul_ui Unexecuted instantiation: fsm-ipc-unix.c:strtoul_ui Unexecuted instantiation: fsm-settings-unix.c:strtoul_ui Unexecuted instantiation: fsm-path-utils-linux.c:strtoul_ui |
981 | | |
982 | | static inline int strtol_i(char const *s, int base, int *result) |
983 | 0 | { |
984 | 0 | long ul; |
985 | 0 | char *p; |
986 | 0 |
|
987 | 0 | errno = 0; |
988 | 0 | ul = strtol(s, &p, base); |
989 | 0 | if (errno || *p || p == s || (int) ul != ul) |
990 | 0 | return -1; |
991 | 0 | *result = ul; |
992 | 0 | return 0; |
993 | 0 | } Unexecuted instantiation: revision.c:strtol_i Unexecuted instantiation: procinfo.c:strtol_i Unexecuted instantiation: fopen.c:strtol_i Unexecuted instantiation: strlcpy.c:strtol_i Unexecuted instantiation: qsort_s.c:strtol_i Unexecuted instantiation: merge-ll.c:strtol_i Unexecuted instantiation: sub-process.c:strtol_i Unexecuted instantiation: system.c:strtol_i Unexecuted instantiation: sha1.c:strtol_i Unexecuted instantiation: ubc_check.c:strtol_i Unexecuted instantiation: fsm-ipc-unix.c:strtol_i Unexecuted instantiation: fsm-settings-unix.c:strtol_i Unexecuted instantiation: fsm-path-utils-linux.c:strtol_i Unexecuted instantiation: apply.c:strtol_i Unexecuted instantiation: parallel-checkout.c:strtol_i |
994 | | |
995 | | #ifndef REG_STARTEND |
996 | | #error "Git requires REG_STARTEND support. Compile with NO_REGEX=NeedsStartEnd" |
997 | | #endif |
998 | | |
999 | | static inline int regexec_buf(const regex_t *preg, const char *buf, size_t size, |
1000 | | size_t nmatch, regmatch_t pmatch[], int eflags) |
1001 | 0 | { |
1002 | 0 | assert(nmatch > 0 && pmatch); |
1003 | 0 | pmatch[0].rm_so = 0; |
1004 | 0 | pmatch[0].rm_eo = size; |
1005 | 0 | return regexec(preg, buf, nmatch, pmatch, eflags | REG_STARTEND); |
1006 | 0 | } Unexecuted instantiation: procinfo.c:regexec_buf Unexecuted instantiation: fopen.c:regexec_buf Unexecuted instantiation: strlcpy.c:regexec_buf Unexecuted instantiation: qsort_s.c:regexec_buf Unexecuted instantiation: diff.c:regexec_buf Unexecuted instantiation: diffcore-pickaxe.c:regexec_buf Unexecuted instantiation: grep.c:regexec_buf Unexecuted instantiation: xdiff-interface.c:regexec_buf Unexecuted instantiation: xdiffi.c:regexec_buf Unexecuted instantiation: system.c:regexec_buf Unexecuted instantiation: sha1.c:regexec_buf Unexecuted instantiation: ubc_check.c:regexec_buf Unexecuted instantiation: fsm-ipc-unix.c:regexec_buf Unexecuted instantiation: fsm-settings-unix.c:regexec_buf Unexecuted instantiation: fsm-path-utils-linux.c:regexec_buf |
1007 | | |
1008 | | #ifdef USE_ENHANCED_BASIC_REGULAR_EXPRESSIONS |
1009 | | int git_regcomp(regex_t *preg, const char *pattern, int cflags); |
1010 | | #define regcomp git_regcomp |
1011 | | #endif |
1012 | | |
1013 | | #ifndef DIR_HAS_BSD_GROUP_SEMANTICS |
1014 | 0 | # define FORCE_DIR_SET_GID S_ISGID |
1015 | | #else |
1016 | | # define FORCE_DIR_SET_GID 0 |
1017 | | #endif |
1018 | | |
1019 | | #ifdef UNRELIABLE_FSTAT |
1020 | | #define fstat_is_reliable() 0 |
1021 | | #else |
1022 | 0 | #define fstat_is_reliable() 1 |
1023 | | #endif |
1024 | | |
1025 | | /* usage.c: only to be used for testing BUG() implementation (see test-tool) */ |
1026 | | extern int BUG_exit_code; |
1027 | | |
1028 | | /* usage.c: if bug() is called we should have a BUG_if_bug() afterwards */ |
1029 | | extern int bug_called_must_BUG; |
1030 | | |
1031 | | __attribute__((format (printf, 3, 4))) NORETURN |
1032 | | void BUG_fl(const char *file, int line, const char *fmt, ...); |
1033 | 0 | #define BUG(...) BUG_fl(__FILE__, __LINE__, __VA_ARGS__) |
1034 | | /* ASSERT: like assert(), but won't be compiled out with NDEBUG */ |
1035 | 0 | #define ASSERT(a) if (!(a)) BUG("Assertion `" #a "' failed.") |
1036 | | __attribute__((format (printf, 3, 4))) |
1037 | | void bug_fl(const char *file, int line, const char *fmt, ...); |
1038 | 0 | #define bug(...) bug_fl(__FILE__, __LINE__, __VA_ARGS__) |
1039 | 0 | #define BUG_if_bug(...) do { \ |
1040 | 0 | if (bug_called_must_BUG) \ |
1041 | 0 | BUG_fl(__FILE__, __LINE__, __VA_ARGS__); \ |
1042 | 0 | } while (0) |
1043 | | |
1044 | | #ifndef FSYNC_METHOD_DEFAULT |
1045 | | #ifdef __APPLE__ |
1046 | | #define FSYNC_METHOD_DEFAULT FSYNC_METHOD_WRITEOUT_ONLY |
1047 | | #else |
1048 | | #define FSYNC_METHOD_DEFAULT FSYNC_METHOD_FSYNC |
1049 | | #endif |
1050 | | #endif |
1051 | | |
1052 | | #ifndef SHELL_PATH |
1053 | | # define SHELL_PATH "/bin/sh" |
1054 | | #endif |
1055 | | |
1056 | | /* |
1057 | | * Our code often opens a path to an optional file, to work on its |
1058 | | * contents when we can successfully open it. We can ignore a failure |
1059 | | * to open if such an optional file does not exist, but we do want to |
1060 | | * report a failure in opening for other reasons (e.g. we got an I/O |
1061 | | * error, or the file is there, but we lack the permission to open). |
1062 | | * |
1063 | | * Call this function after seeing an error from open() or fopen() to |
1064 | | * see if the errno indicates a missing file that we can safely ignore. |
1065 | | */ |
1066 | | static inline int is_missing_file_error(int errno_) |
1067 | 0 | { |
1068 | 0 | return (errno_ == ENOENT || errno_ == ENOTDIR); |
1069 | 0 | } Unexecuted instantiation: setup.c:is_missing_file_error Unexecuted instantiation: wrapper.c:is_missing_file_error Unexecuted instantiation: procinfo.c:is_missing_file_error Unexecuted instantiation: fopen.c:is_missing_file_error Unexecuted instantiation: strlcpy.c:is_missing_file_error Unexecuted instantiation: qsort_s.c:is_missing_file_error Unexecuted instantiation: diff-lib.c:is_missing_file_error Unexecuted instantiation: dir.c:is_missing_file_error Unexecuted instantiation: object-name.c:is_missing_file_error Unexecuted instantiation: system.c:is_missing_file_error Unexecuted instantiation: sha1.c:is_missing_file_error Unexecuted instantiation: ubc_check.c:is_missing_file_error Unexecuted instantiation: fsm-ipc-unix.c:is_missing_file_error Unexecuted instantiation: fsm-settings-unix.c:is_missing_file_error Unexecuted instantiation: fsm-path-utils-linux.c:is_missing_file_error Unexecuted instantiation: apply.c:is_missing_file_error |
1070 | | |
1071 | | int cmd_main(int, const char **); |
1072 | | |
1073 | | /* |
1074 | | * Intercept all calls to exit() and route them to trace2 to |
1075 | | * optionally emit a message before calling the real exit(). |
1076 | | */ |
1077 | | int common_exit(const char *file, int line, int code); |
1078 | 0 | #define exit(code) exit(common_exit(__FILE__, __LINE__, (code))) |
1079 | | |
1080 | | /* |
1081 | | * This include must come after system headers, since it introduces macros that |
1082 | | * replace system names. |
1083 | | */ |
1084 | | #include "banned.h" |
1085 | | |
1086 | | /* |
1087 | | * container_of - Get the address of an object containing a field. |
1088 | | * |
1089 | | * @ptr: pointer to the field. |
1090 | | * @type: type of the object. |
1091 | | * @member: name of the field within the object. |
1092 | | */ |
1093 | | #define container_of(ptr, type, member) \ |
1094 | 0 | ((type *) ((char *)(ptr) - offsetof(type, member))) |
1095 | | |
1096 | | /* |
1097 | | * helper function for `container_of_or_null' to avoid multiple |
1098 | | * evaluation of @ptr |
1099 | | */ |
1100 | | static inline void *container_of_or_null_offset(void *ptr, size_t offset) |
1101 | 0 | { |
1102 | 0 | return ptr ? (char *)ptr - offset : NULL; |
1103 | 0 | } Unexecuted instantiation: fuzz-pack-idx.c:container_of_or_null_offset Unexecuted instantiation: packfile.c:container_of_or_null_offset Unexecuted instantiation: packfile-list.c:container_of_or_null_offset Unexecuted instantiation: promisor-remote.c:container_of_or_null_offset Unexecuted instantiation: remote.c:container_of_or_null_offset Unexecuted instantiation: repo-settings.c:container_of_or_null_offset Unexecuted instantiation: repository.c:container_of_or_null_offset Unexecuted instantiation: revision.c:container_of_or_null_offset Unexecuted instantiation: run-command.c:container_of_or_null_offset Unexecuted instantiation: setup.c:container_of_or_null_offset Unexecuted instantiation: shallow.c:container_of_or_null_offset Unexecuted instantiation: sparse-index.c:container_of_or_null_offset Unexecuted instantiation: statinfo.c:container_of_or_null_offset Unexecuted instantiation: strmap.c:container_of_or_null_offset Unexecuted instantiation: submodule-config.c:container_of_or_null_offset Unexecuted instantiation: submodule.c:container_of_or_null_offset Unexecuted instantiation: symlinks.c:container_of_or_null_offset Unexecuted instantiation: tag.c:container_of_or_null_offset Unexecuted instantiation: trace.c:container_of_or_null_offset Unexecuted instantiation: trace2.c:container_of_or_null_offset Unexecuted instantiation: tr2_cfg.c:container_of_or_null_offset Unexecuted instantiation: tr2_sysenv.c:container_of_or_null_offset Unexecuted instantiation: tr2_tgt_event.c:container_of_or_null_offset Unexecuted instantiation: tr2_tgt_normal.c:container_of_or_null_offset Unexecuted instantiation: tr2_tgt_perf.c:container_of_or_null_offset Unexecuted instantiation: transport.c:container_of_or_null_offset Unexecuted instantiation: tree-diff.c:container_of_or_null_offset Unexecuted instantiation: tree-walk.c:container_of_or_null_offset Unexecuted instantiation: tree.c:container_of_or_null_offset Unexecuted instantiation: urlmatch.c:container_of_or_null_offset Unexecuted instantiation: worktree.c:container_of_or_null_offset Unexecuted instantiation: wt-status.c:container_of_or_null_offset Unexecuted instantiation: procinfo.c:container_of_or_null_offset Unexecuted instantiation: fopen.c:container_of_or_null_offset Unexecuted instantiation: strlcpy.c:container_of_or_null_offset Unexecuted instantiation: qsort_s.c:container_of_or_null_offset Unexecuted instantiation: advice.c:container_of_or_null_offset Unexecuted instantiation: alloc.c:container_of_or_null_offset Unexecuted instantiation: bisect.c:container_of_or_null_offset Unexecuted instantiation: bloom.c:container_of_or_null_offset Unexecuted instantiation: branch.c:container_of_or_null_offset Unexecuted instantiation: bundle-uri.c:container_of_or_null_offset Unexecuted instantiation: bundle.c:container_of_or_null_offset Unexecuted instantiation: cache-tree.c:container_of_or_null_offset Unexecuted instantiation: color.c:container_of_or_null_offset Unexecuted instantiation: column.c:container_of_or_null_offset Unexecuted instantiation: combine-diff.c:container_of_or_null_offset Unexecuted instantiation: commit-graph.c:container_of_or_null_offset Unexecuted instantiation: commit-reach.c:container_of_or_null_offset Unexecuted instantiation: commit.c:container_of_or_null_offset Unexecuted instantiation: config.c:container_of_or_null_offset Unexecuted instantiation: connect.c:container_of_or_null_offset Unexecuted instantiation: connected.c:container_of_or_null_offset Unexecuted instantiation: convert.c:container_of_or_null_offset Unexecuted instantiation: diff-lib.c:container_of_or_null_offset Unexecuted instantiation: diff.c:container_of_or_null_offset Unexecuted instantiation: diffcore-break.c:container_of_or_null_offset Unexecuted instantiation: diffcore-rename.c:container_of_or_null_offset Unexecuted instantiation: dir.c:container_of_or_null_offset Unexecuted instantiation: editor.c:container_of_or_null_offset Unexecuted instantiation: environment.c:container_of_or_null_offset Unexecuted instantiation: fetch-object-info.c:container_of_or_null_offset Unexecuted instantiation: fetch-pack.c:container_of_or_null_offset Unexecuted instantiation: fsck.c:container_of_or_null_offset Unexecuted instantiation: fsmonitor.c:container_of_or_null_offset Unexecuted instantiation: fsmonitor-ipc.c:container_of_or_null_offset Unexecuted instantiation: fsmonitor-settings.c:container_of_or_null_offset Unexecuted instantiation: gpg-interface.c:container_of_or_null_offset Unexecuted instantiation: graph.c:container_of_or_null_offset Unexecuted instantiation: grep.c:container_of_or_null_offset Unexecuted instantiation: hash-lookup.c:container_of_or_null_offset Unexecuted instantiation: hashmap.c:container_of_or_null_offset Unexecuted instantiation: hex.c:container_of_or_null_offset Unexecuted instantiation: hook.c:container_of_or_null_offset Unexecuted instantiation: ident.c:container_of_or_null_offset Unexecuted instantiation: line-log.c:container_of_or_null_offset Unexecuted instantiation: list-objects-filter-options.c:container_of_or_null_offset Unexecuted instantiation: list-objects.c:container_of_or_null_offset Unexecuted instantiation: lockfile.c:container_of_or_null_offset Unexecuted instantiation: log-tree.c:container_of_or_null_offset Unexecuted instantiation: mailmap.c:container_of_or_null_offset Unexecuted instantiation: merge-ll.c:container_of_or_null_offset Unexecuted instantiation: merge-ort.c:container_of_or_null_offset Unexecuted instantiation: midx.c:container_of_or_null_offset Unexecuted instantiation: name-hash.c:container_of_or_null_offset Unexecuted instantiation: notes-cache.c:container_of_or_null_offset Unexecuted instantiation: notes.c:container_of_or_null_offset Unexecuted instantiation: object-file-convert.c:container_of_or_null_offset Unexecuted instantiation: object-file.c:container_of_or_null_offset Unexecuted instantiation: object-name.c:container_of_or_null_offset Unexecuted instantiation: object.c:container_of_or_null_offset Unexecuted instantiation: odb.c:container_of_or_null_offset Unexecuted instantiation: source.c:container_of_or_null_offset Unexecuted instantiation: source-files.c:container_of_or_null_offset Unexecuted instantiation: source-inmemory.c:container_of_or_null_offset Unexecuted instantiation: source-loose.c:container_of_or_null_offset Unexecuted instantiation: source-packed.c:container_of_or_null_offset Unexecuted instantiation: streaming.c:container_of_or_null_offset Unexecuted instantiation: transaction.c:container_of_or_null_offset Unexecuted instantiation: oid-array.c:container_of_or_null_offset Unexecuted instantiation: oidmap.c:container_of_or_null_offset Unexecuted instantiation: pack-bitmap.c:container_of_or_null_offset Unexecuted instantiation: pack-check.c:container_of_or_null_offset Unexecuted instantiation: pack-mtimes.c:container_of_or_null_offset Unexecuted instantiation: pack-objects.c:container_of_or_null_offset Unexecuted instantiation: pack-revindex.c:container_of_or_null_offset Unexecuted instantiation: pack-write.c:container_of_or_null_offset Unexecuted instantiation: pager.c:container_of_or_null_offset Unexecuted instantiation: parse-options-cb.c:container_of_or_null_offset Unexecuted instantiation: parse-options.c:container_of_or_null_offset Unexecuted instantiation: patch-ids.c:container_of_or_null_offset Unexecuted instantiation: path.c:container_of_or_null_offset Unexecuted instantiation: pathspec.c:container_of_or_null_offset Unexecuted instantiation: pretty.c:container_of_or_null_offset Unexecuted instantiation: progress.c:container_of_or_null_offset Unexecuted instantiation: protocol.c:container_of_or_null_offset Unexecuted instantiation: pseudo-merge.c:container_of_or_null_offset Unexecuted instantiation: range-diff.c:container_of_or_null_offset Unexecuted instantiation: read-cache.c:container_of_or_null_offset Unexecuted instantiation: reflog-walk.c:container_of_or_null_offset Unexecuted instantiation: refs.c:container_of_or_null_offset Unexecuted instantiation: debug.c:container_of_or_null_offset Unexecuted instantiation: files-backend.c:container_of_or_null_offset Unexecuted instantiation: reftable-backend.c:container_of_or_null_offset Unexecuted instantiation: iterator.c:container_of_or_null_offset Unexecuted instantiation: packed-backend.c:container_of_or_null_offset Unexecuted instantiation: ref-cache.c:container_of_or_null_offset Unexecuted instantiation: refspec.c:container_of_or_null_offset Unexecuted instantiation: repack.c:container_of_or_null_offset Unexecuted instantiation: repack-geometry.c:container_of_or_null_offset Unexecuted instantiation: replace-object.c:container_of_or_null_offset Unexecuted instantiation: resolve-undo.c:container_of_or_null_offset Unexecuted instantiation: send-pack.c:container_of_or_null_offset Unexecuted instantiation: sequencer.c:container_of_or_null_offset Unexecuted instantiation: sideband.c:container_of_or_null_offset Unexecuted instantiation: split-index.c:container_of_or_null_offset Unexecuted instantiation: sub-process.c:container_of_or_null_offset Unexecuted instantiation: tmp-objdir.c:container_of_or_null_offset Unexecuted instantiation: trailer.c:container_of_or_null_offset Unexecuted instantiation: transport-helper.c:container_of_or_null_offset Unexecuted instantiation: unpack-trees.c:container_of_or_null_offset Unexecuted instantiation: userdiff.c:container_of_or_null_offset Unexecuted instantiation: xdiff-interface.c:container_of_or_null_offset Unexecuted instantiation: system.c:container_of_or_null_offset Unexecuted instantiation: sha1.c:container_of_or_null_offset Unexecuted instantiation: ubc_check.c:container_of_or_null_offset Unexecuted instantiation: fsm-ipc-unix.c:container_of_or_null_offset Unexecuted instantiation: fsm-settings-unix.c:container_of_or_null_offset Unexecuted instantiation: fsm-path-utils-linux.c:container_of_or_null_offset Unexecuted instantiation: alias.c:container_of_or_null_offset Unexecuted instantiation: apply.c:container_of_or_null_offset Unexecuted instantiation: attr.c:container_of_or_null_offset Unexecuted instantiation: chunk-format.c:container_of_or_null_offset Unexecuted instantiation: dir-iterator.c:container_of_or_null_offset Unexecuted instantiation: entry.c:container_of_or_null_offset Unexecuted instantiation: fetch-negotiator.c:container_of_or_null_offset Unexecuted instantiation: list-objects-filter.c:container_of_or_null_offset Unexecuted instantiation: loose.c:container_of_or_null_offset Unexecuted instantiation: match-trees.c:container_of_or_null_offset Unexecuted instantiation: merge-ort-wrappers.c:container_of_or_null_offset Unexecuted instantiation: merge.c:container_of_or_null_offset Unexecuted instantiation: default.c:container_of_or_null_offset Unexecuted instantiation: skipping.c:container_of_or_null_offset Unexecuted instantiation: notes-utils.c:container_of_or_null_offset Unexecuted instantiation: pack-bitmap-write.c:container_of_or_null_offset Unexecuted instantiation: parallel-checkout.c:container_of_or_null_offset Unexecuted instantiation: preload-index.c:container_of_or_null_offset Unexecuted instantiation: rebase-interactive.c:container_of_or_null_offset Unexecuted instantiation: rerere.c:container_of_or_null_offset Unexecuted instantiation: reset.c:container_of_or_null_offset |
1104 | | |
1105 | | /* |
1106 | | * like `container_of', but allows returned value to be NULL |
1107 | | */ |
1108 | | #define container_of_or_null(ptr, type, member) \ |
1109 | 0 | (type *)container_of_or_null_offset(ptr, offsetof(type, member)) |
1110 | | |
1111 | | /* |
1112 | | * like offsetof(), but takes a pointer to a variable of type which |
1113 | | * contains @member, instead of a specified type. |
1114 | | * @ptr is subject to multiple evaluation since we can't rely on __typeof__ |
1115 | | * everywhere. |
1116 | | */ |
1117 | | #if defined(__GNUC__) /* clang sets this, too */ |
1118 | 0 | #define OFFSETOF_VAR(ptr, member) offsetof(__typeof__(*ptr), member) |
1119 | | #else /* !__GNUC__ */ |
1120 | | #define OFFSETOF_VAR(ptr, member) \ |
1121 | | ((uintptr_t)&(ptr)->member - (uintptr_t)(ptr)) |
1122 | | #endif /* !__GNUC__ */ |
1123 | | |
1124 | | /* |
1125 | | * Prevent an overly clever compiler from optimizing an expression |
1126 | | * out, triggering a false positive when building with the |
1127 | | * -Wunreachable-code option. false_but_the_compiler_does_not_know_it_ |
1128 | | * is defined in a compilation unit separate from where the macro is |
1129 | | * used, initialized to 0, and never modified. |
1130 | | */ |
1131 | 0 | #define NOT_CONSTANT(expr) ((expr) || false_but_the_compiler_does_not_know_it_) |
1132 | | extern int false_but_the_compiler_does_not_know_it_; |
1133 | | |
1134 | | #ifdef CHECK_ASSERTION_SIDE_EFFECTS |
1135 | | #undef assert |
1136 | | extern int not_supposed_to_survive; |
1137 | | #define assert(expr) ((void)(not_supposed_to_survive || (expr))) |
1138 | | #endif /* CHECK_ASSERTION_SIDE_EFFECTS */ |
1139 | | |
1140 | | #endif |
1141 | | |
1142 | | #ifdef DISABLE_SIGN_COMPARE_WARNINGS |
1143 | | DISABLE_WARNING(-Wsign-compare) |
1144 | | #endif |