rugged 0.27.7 → 0.27.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rugged/version.rb +1 -1
- data/vendor/libgit2/CMakeLists.txt +6 -2
- data/vendor/libgit2/cmake/Modules/CheckPrototypeDefinition.c.in +29 -0
- data/vendor/libgit2/cmake/Modules/CheckPrototypeDefinition.cmake +96 -0
- data/vendor/libgit2/cmake/Modules/FindIconv.cmake +11 -6
- data/vendor/libgit2/deps/http-parser/CMakeLists.txt +0 -2
- data/vendor/libgit2/include/git2.h +0 -1
- data/vendor/libgit2/include/git2/attr.h +7 -18
- data/vendor/libgit2/include/git2/blame.h +22 -39
- data/vendor/libgit2/include/git2/blob.h +1 -1
- data/vendor/libgit2/include/git2/branch.h +1 -1
- data/vendor/libgit2/include/git2/buffer.h +2 -14
- data/vendor/libgit2/include/git2/checkout.h +12 -13
- data/vendor/libgit2/include/git2/cherrypick.h +4 -6
- data/vendor/libgit2/include/git2/clone.h +6 -8
- data/vendor/libgit2/include/git2/commit.h +0 -28
- data/vendor/libgit2/include/git2/common.h +0 -27
- data/vendor/libgit2/include/git2/config.h +0 -1
- data/vendor/libgit2/include/git2/describe.h +7 -30
- data/vendor/libgit2/include/git2/diff.h +22 -32
- data/vendor/libgit2/include/git2/errors.h +0 -1
- data/vendor/libgit2/include/git2/ignore.h +2 -2
- data/vendor/libgit2/include/git2/merge.h +8 -10
- data/vendor/libgit2/include/git2/proxy.h +5 -9
- data/vendor/libgit2/include/git2/rebase.h +4 -7
- data/vendor/libgit2/include/git2/refs.h +1 -1
- data/vendor/libgit2/include/git2/refspec.h +0 -17
- data/vendor/libgit2/include/git2/remote.h +10 -12
- data/vendor/libgit2/include/git2/repository.h +5 -7
- data/vendor/libgit2/include/git2/revert.h +3 -5
- data/vendor/libgit2/include/git2/stash.h +8 -11
- data/vendor/libgit2/include/git2/status.h +3 -7
- data/vendor/libgit2/include/git2/submodule.h +7 -8
- data/vendor/libgit2/include/git2/sys/index.h +0 -3
- data/vendor/libgit2/include/git2/sys/mempack.h +35 -35
- data/vendor/libgit2/include/git2/sys/merge.h +1 -6
- data/vendor/libgit2/include/git2/transaction.h +0 -1
- data/vendor/libgit2/include/git2/types.h +5 -8
- data/vendor/libgit2/include/git2/version.h +2 -2
- data/vendor/libgit2/include/git2/worktree.h +11 -46
- data/vendor/libgit2/src/CMakeLists.txt +28 -91
- data/vendor/libgit2/src/annotated_commit.c +4 -4
- data/vendor/libgit2/src/apply.c +6 -5
- data/vendor/libgit2/src/attr.c +4 -4
- data/vendor/libgit2/src/attr_file.c +5 -5
- data/vendor/libgit2/src/attrcache.c +2 -2
- data/vendor/libgit2/src/blame.c +4 -11
- data/vendor/libgit2/src/blame.h +0 -1
- data/vendor/libgit2/src/blame_git.c +5 -8
- data/vendor/libgit2/src/blob.c +5 -5
- data/vendor/libgit2/src/branch.c +20 -20
- data/vendor/libgit2/src/buffer.c +4 -9
- data/vendor/libgit2/src/buffer.h +1 -1
- data/vendor/libgit2/src/checkout.c +24 -33
- data/vendor/libgit2/src/cherrypick.c +3 -3
- data/vendor/libgit2/src/clone.c +13 -13
- data/vendor/libgit2/src/commit.c +5 -18
- data/vendor/libgit2/src/commit_list.c +9 -3
- data/vendor/libgit2/src/common.h +1 -3
- data/vendor/libgit2/src/config.c +15 -6
- data/vendor/libgit2/src/config_file.c +249 -193
- data/vendor/libgit2/src/config_parse.c +66 -89
- data/vendor/libgit2/src/config_parse.h +2 -2
- data/vendor/libgit2/src/crlf.c +3 -9
- data/vendor/libgit2/src/diff.c +2 -2
- data/vendor/libgit2/src/diff_driver.c +3 -3
- data/vendor/libgit2/src/diff_file.c +3 -3
- data/vendor/libgit2/src/diff_generate.c +3 -4
- data/vendor/libgit2/src/diff_print.c +8 -8
- data/vendor/libgit2/src/diff_tform.c +4 -2
- data/vendor/libgit2/src/diff_xdiff.c +0 -12
- data/vendor/libgit2/src/features.h.in +0 -2
- data/vendor/libgit2/src/fetch.c +2 -2
- data/vendor/libgit2/src/fetchhead.c +5 -5
- data/vendor/libgit2/src/filebuf.c +4 -4
- data/vendor/libgit2/src/fileops.c +10 -10
- data/vendor/libgit2/src/filter.c +9 -3
- data/vendor/libgit2/src/global.c +12 -17
- data/vendor/libgit2/src/hash.h +0 -2
- data/vendor/libgit2/src/ignore.c +5 -5
- data/vendor/libgit2/src/index.c +40 -80
- data/vendor/libgit2/src/index.h +0 -10
- data/vendor/libgit2/src/indexer.c +9 -9
- data/vendor/libgit2/src/iterator.c +8 -8
- data/vendor/libgit2/src/khash.h +1 -3
- data/vendor/libgit2/src/merge.c +7 -7
- data/vendor/libgit2/src/netops.c +5 -5
- data/vendor/libgit2/src/notes.c +2 -2
- data/vendor/libgit2/src/odb.c +9 -9
- data/vendor/libgit2/src/odb_loose.c +22 -18
- data/vendor/libgit2/src/odb_pack.c +3 -3
- data/vendor/libgit2/src/pack-objects.c +3 -3
- data/vendor/libgit2/src/pack.c +5 -5
- data/vendor/libgit2/src/pack.h +1 -1
- data/vendor/libgit2/src/parse.c +7 -4
- data/vendor/libgit2/src/patch.c +1 -1
- data/vendor/libgit2/src/patch_generate.c +2 -2
- data/vendor/libgit2/src/patch_parse.c +4 -24
- data/vendor/libgit2/src/path.c +140 -39
- data/vendor/libgit2/src/path.h +84 -2
- data/vendor/libgit2/src/pathspec.c +1 -1
- data/vendor/libgit2/src/push.c +2 -2
- data/vendor/libgit2/src/rebase.c +23 -20
- data/vendor/libgit2/src/refdb_fs.c +34 -65
- data/vendor/libgit2/src/refs.c +16 -13
- data/vendor/libgit2/src/refspec.c +5 -30
- data/vendor/libgit2/src/refspec.h +1 -1
- data/vendor/libgit2/src/remote.c +43 -43
- data/vendor/libgit2/src/repository.c +56 -56
- data/vendor/libgit2/src/reset.c +1 -1
- data/vendor/libgit2/src/revert.c +3 -3
- data/vendor/libgit2/src/revparse.c +7 -6
- data/vendor/libgit2/src/revwalk.c +20 -48
- data/vendor/libgit2/src/revwalk.h +1 -2
- data/vendor/libgit2/src/settings.c +1 -25
- data/vendor/libgit2/src/signature.c +4 -2
- data/vendor/libgit2/src/stash.c +34 -80
- data/vendor/libgit2/src/status.c +1 -1
- data/vendor/libgit2/src/streams/curl.c +1 -1
- data/vendor/libgit2/src/streams/openssl.c +34 -132
- data/vendor/libgit2/src/streams/openssl.h +107 -0
- data/vendor/libgit2/src/streams/tls.c +0 -3
- data/vendor/libgit2/src/submodule.c +83 -118
- data/vendor/libgit2/src/sysdir.c +4 -4
- data/vendor/libgit2/src/tag.c +12 -12
- data/vendor/libgit2/src/trace.h +1 -1
- data/vendor/libgit2/src/trailer.c +6 -6
- data/vendor/libgit2/src/transport.c +2 -2
- data/vendor/libgit2/src/transports/auth.c +1 -1
- data/vendor/libgit2/src/transports/auth_negotiate.c +2 -2
- data/vendor/libgit2/src/transports/git.c +1 -1
- data/vendor/libgit2/src/transports/http.c +15 -12
- data/vendor/libgit2/src/transports/local.c +7 -7
- data/vendor/libgit2/src/transports/smart.c +15 -20
- data/vendor/libgit2/src/transports/smart.h +5 -5
- data/vendor/libgit2/src/transports/smart_pkt.c +131 -123
- data/vendor/libgit2/src/transports/smart_protocol.c +38 -48
- data/vendor/libgit2/src/transports/ssh.c +1 -1
- data/vendor/libgit2/src/transports/winhttp.c +26 -21
- data/vendor/libgit2/src/tree-cache.c +2 -2
- data/vendor/libgit2/src/tree.c +69 -23
- data/vendor/libgit2/src/tree.h +12 -0
- data/vendor/libgit2/src/util.c +99 -52
- data/vendor/libgit2/src/util.h +138 -14
- data/vendor/libgit2/src/vector.c +13 -8
- data/vendor/libgit2/src/win32/findfile.c +2 -2
- data/vendor/libgit2/src/win32/posix_w32.c +1 -1
- data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.c +0 -94
- data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.h +75 -28
- data/vendor/libgit2/src/worktree.c +44 -65
- data/vendor/libgit2/src/worktree.h +0 -2
- data/vendor/libgit2/src/xdiff/xdiffi.c +1 -3
- metadata +5 -17
- data/vendor/libgit2/cmake/Modules/FindmbedTLS.cmake +0 -93
- data/vendor/libgit2/include/git2/mailmap.h +0 -115
- data/vendor/libgit2/include/git2/sys/alloc.h +0 -101
- data/vendor/libgit2/include/git2/sys/path.h +0 -55
- data/vendor/libgit2/src/alloc.c +0 -47
- data/vendor/libgit2/src/alloc.h +0 -40
- data/vendor/libgit2/src/hash/hash_mbedtls.c +0 -38
- data/vendor/libgit2/src/hash/hash_mbedtls.h +0 -20
- data/vendor/libgit2/src/mailmap.c +0 -485
- data/vendor/libgit2/src/mailmap.h +0 -35
- data/vendor/libgit2/src/stdalloc.c +0 -120
- data/vendor/libgit2/src/stdalloc.h +0 -17
- data/vendor/libgit2/src/streams/mbedtls.c +0 -463
- data/vendor/libgit2/src/streams/mbedtls.h +0 -20
data/vendor/libgit2/src/tree.h
CHANGED
@@ -39,9 +39,21 @@ GIT_INLINE(bool) git_tree_entry__is_tree(const struct git_tree_entry *e)
|
|
39
39
|
return (S_ISDIR(e->attr) && !S_ISGITLINK(e->attr));
|
40
40
|
}
|
41
41
|
|
42
|
+
extern int git_tree_entry_icmp(const git_tree_entry *e1, const git_tree_entry *e2);
|
43
|
+
|
42
44
|
void git_tree__free(void *tree);
|
43
45
|
int git_tree__parse(void *tree, git_odb_object *obj);
|
44
46
|
|
47
|
+
/**
|
48
|
+
* Lookup the first position in the tree with a given prefix.
|
49
|
+
*
|
50
|
+
* @param tree a previously loaded tree.
|
51
|
+
* @param prefix the beginning of a path to find in the tree.
|
52
|
+
* @return index of the first item at or after the given prefix.
|
53
|
+
*/
|
54
|
+
int git_tree__prefix_position(const git_tree *tree, const char *prefix);
|
55
|
+
|
56
|
+
|
45
57
|
/**
|
46
58
|
* Write a tree to the given repository
|
47
59
|
*/
|
data/vendor/libgit2/src/util.c
CHANGED
@@ -68,12 +68,6 @@ int git_strarray_copy(git_strarray *tgt, const git_strarray *src)
|
|
68
68
|
return 0;
|
69
69
|
}
|
70
70
|
|
71
|
-
int git__strtol64(int64_t *result, const char *nptr, const char **endptr, int base)
|
72
|
-
{
|
73
|
-
|
74
|
-
return git__strntol64(result, nptr, (size_t)-1, endptr, base);
|
75
|
-
}
|
76
|
-
|
77
71
|
int git__strntol64(int64_t *result, const char *nptr, size_t nptr_len, const char **endptr, int base)
|
78
72
|
{
|
79
73
|
const char *p;
|
@@ -89,35 +83,55 @@ int git__strntol64(int64_t *result, const char *nptr, size_t nptr_len, const cha
|
|
89
83
|
/*
|
90
84
|
* White space
|
91
85
|
*/
|
92
|
-
while (git__isspace(*p))
|
93
|
-
p
|
86
|
+
while (nptr_len && git__isspace(*p))
|
87
|
+
p++, nptr_len--;
|
88
|
+
|
89
|
+
if (!nptr_len)
|
90
|
+
goto Return;
|
94
91
|
|
95
92
|
/*
|
96
93
|
* Sign
|
97
94
|
*/
|
98
|
-
if (*p == '-' || *p == '+')
|
99
|
-
if (*p
|
95
|
+
if (*p == '-' || *p == '+') {
|
96
|
+
if (*p == '-')
|
100
97
|
neg = 1;
|
98
|
+
p++;
|
99
|
+
nptr_len--;
|
100
|
+
}
|
101
|
+
|
102
|
+
if (!nptr_len)
|
103
|
+
goto Return;
|
101
104
|
|
102
105
|
/*
|
103
|
-
*
|
106
|
+
* Automatically detect the base if none was given to us.
|
107
|
+
* Right now, we assume that a number starting with '0x'
|
108
|
+
* is hexadecimal and a number starting with '0' is
|
109
|
+
* octal.
|
104
110
|
*/
|
105
111
|
if (base == 0) {
|
106
112
|
if (*p != '0')
|
107
113
|
base = 10;
|
108
|
-
else
|
114
|
+
else if (nptr_len > 2 && (p[1] == 'x' || p[1] == 'X'))
|
115
|
+
base = 16;
|
116
|
+
else
|
109
117
|
base = 8;
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
}
|
114
|
-
}
|
115
|
-
} else if (base == 16 && *p == '0') {
|
116
|
-
if (p[1] == 'x' || p[1] == 'X')
|
117
|
-
p += 2;
|
118
|
-
} else if (base < 0 || 36 < base)
|
118
|
+
}
|
119
|
+
|
120
|
+
if (base < 0 || 36 < base)
|
119
121
|
goto Return;
|
120
122
|
|
123
|
+
/*
|
124
|
+
* Skip prefix of '0x'-prefixed hexadecimal numbers. There is no
|
125
|
+
* need to do the same for '0'-prefixed octal numbers as a
|
126
|
+
* leading '0' does not have any impact. Also, if we skip a
|
127
|
+
* leading '0' in such a string, then we may end up with no
|
128
|
+
* digits left and produce an error later on which isn't one.
|
129
|
+
*/
|
130
|
+
if (base == 16 && nptr_len > 2 && p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) {
|
131
|
+
p += 2;
|
132
|
+
nptr_len -= 2;
|
133
|
+
}
|
134
|
+
|
121
135
|
/*
|
122
136
|
* Non-empty sequence of digits
|
123
137
|
*/
|
@@ -132,10 +146,20 @@ int git__strntol64(int64_t *result, const char *nptr, size_t nptr_len, const cha
|
|
132
146
|
v = c - 'A' + 10;
|
133
147
|
if (v >= base)
|
134
148
|
break;
|
135
|
-
|
136
|
-
if (
|
149
|
+
v = neg ? -v : v;
|
150
|
+
if (n > INT64_MAX / base || n < INT64_MIN / base) {
|
151
|
+
ovfl = 1;
|
152
|
+
/* Keep on iterating until the end of this number */
|
153
|
+
continue;
|
154
|
+
}
|
155
|
+
nn = n * base;
|
156
|
+
if ((v > 0 && nn > INT64_MAX - v) ||
|
157
|
+
(v < 0 && nn < INT64_MIN - v)) {
|
137
158
|
ovfl = 1;
|
138
|
-
|
159
|
+
/* Keep on iterating until the end of this number */
|
160
|
+
continue;
|
161
|
+
}
|
162
|
+
n = nn + v;
|
139
163
|
}
|
140
164
|
|
141
165
|
Return:
|
@@ -156,28 +180,26 @@ Return:
|
|
156
180
|
return 0;
|
157
181
|
}
|
158
182
|
|
159
|
-
int git__strtol32(int32_t *result, const char *nptr, const char **endptr, int base)
|
160
|
-
{
|
161
|
-
|
162
|
-
return git__strntol32(result, nptr, (size_t)-1, endptr, base);
|
163
|
-
}
|
164
|
-
|
165
183
|
int git__strntol32(int32_t *result, const char *nptr, size_t nptr_len, const char **endptr, int base)
|
166
184
|
{
|
167
|
-
|
185
|
+
const char *tmp_endptr;
|
168
186
|
int32_t tmp_int;
|
169
187
|
int64_t tmp_long;
|
188
|
+
int error;
|
170
189
|
|
171
|
-
if ((error = git__strntol64(&tmp_long, nptr, nptr_len,
|
190
|
+
if ((error = git__strntol64(&tmp_long, nptr, nptr_len, &tmp_endptr, base)) < 0)
|
172
191
|
return error;
|
173
192
|
|
174
193
|
tmp_int = tmp_long & 0xFFFFFFFF;
|
175
194
|
if (tmp_int != tmp_long) {
|
176
|
-
|
195
|
+
int len = tmp_endptr - nptr;
|
196
|
+
giterr_set(GITERR_INVALID, "failed to convert: '%.*s' is too large", len, nptr);
|
177
197
|
return -1;
|
178
198
|
}
|
179
199
|
|
180
200
|
*result = tmp_int;
|
201
|
+
if (endptr)
|
202
|
+
*endptr = tmp_endptr;
|
181
203
|
|
182
204
|
return error;
|
183
205
|
}
|
@@ -355,6 +377,47 @@ size_t git__linenlen(const char *buffer, size_t buffer_len)
|
|
355
377
|
return nl ? (size_t)(nl - buffer) + 1 : buffer_len;
|
356
378
|
}
|
357
379
|
|
380
|
+
/*
|
381
|
+
* Adapted Not So Naive algorithm from http://www-igm.univ-mlv.fr/~lecroq/string/
|
382
|
+
*/
|
383
|
+
const void * git__memmem(const void *haystack, size_t haystacklen,
|
384
|
+
const void *needle, size_t needlelen)
|
385
|
+
{
|
386
|
+
const char *h, *n;
|
387
|
+
size_t j, k, l;
|
388
|
+
|
389
|
+
if (needlelen > haystacklen || !haystacklen || !needlelen)
|
390
|
+
return NULL;
|
391
|
+
|
392
|
+
h = (const char *) haystack,
|
393
|
+
n = (const char *) needle;
|
394
|
+
|
395
|
+
if (needlelen == 1)
|
396
|
+
return memchr(haystack, *n, haystacklen);
|
397
|
+
|
398
|
+
if (n[0] == n[1]) {
|
399
|
+
k = 2;
|
400
|
+
l = 1;
|
401
|
+
} else {
|
402
|
+
k = 1;
|
403
|
+
l = 2;
|
404
|
+
}
|
405
|
+
|
406
|
+
j = 0;
|
407
|
+
while (j <= haystacklen - needlelen) {
|
408
|
+
if (n[1] != h[j + 1]) {
|
409
|
+
j += k;
|
410
|
+
} else {
|
411
|
+
if (memcmp(n + 2, h + j + 2, needlelen - 2) == 0 &&
|
412
|
+
n[0] == h[j])
|
413
|
+
return h + j;
|
414
|
+
j += l;
|
415
|
+
}
|
416
|
+
}
|
417
|
+
|
418
|
+
return NULL;
|
419
|
+
}
|
420
|
+
|
358
421
|
void git__hexdump(const char *buffer, size_t len)
|
359
422
|
{
|
360
423
|
static const size_t LINE_WIDTH = 16;
|
@@ -647,7 +710,7 @@ size_t git__unescape(char *str)
|
|
647
710
|
return (pos - str);
|
648
711
|
}
|
649
712
|
|
650
|
-
#if defined(HAVE_QSORT_S) ||
|
713
|
+
#if defined(HAVE_QSORT_S) || defined(HAVE_QSORT_R_BSD)
|
651
714
|
typedef struct {
|
652
715
|
git__sort_r_cmp cmp;
|
653
716
|
void *payload;
|
@@ -664,10 +727,10 @@ static int GIT_STDLIB_CALL git__qsort_r_glue_cmp(
|
|
664
727
|
void git__qsort_r(
|
665
728
|
void *els, size_t nel, size_t elsize, git__sort_r_cmp cmp, void *payload)
|
666
729
|
{
|
667
|
-
#if defined(
|
730
|
+
#if defined(HAVE_QSORT_R_BSD)
|
668
731
|
git__qsort_r_glue glue = { cmp, payload };
|
669
732
|
qsort_r(els, nel, elsize, &glue, git__qsort_r_glue_cmp);
|
670
|
-
#elif defined(
|
733
|
+
#elif defined(HAVE_QSORT_R_GNU)
|
671
734
|
qsort_r(els, nel, elsize, cmp, payload);
|
672
735
|
#elif defined(HAVE_QSORT_S)
|
673
736
|
git__qsort_r_glue glue = { cmp, payload };
|
@@ -806,22 +869,6 @@ double git_time_monotonic(void)
|
|
806
869
|
return git__timer();
|
807
870
|
}
|
808
871
|
|
809
|
-
size_t git__utf8_valid_buf_length(const uint8_t *str, size_t str_len)
|
810
|
-
{
|
811
|
-
size_t offset = 0;
|
812
|
-
|
813
|
-
while (offset < str_len) {
|
814
|
-
int length = git__utf8_charlen(str + offset, str_len - offset);
|
815
|
-
|
816
|
-
if (length < 0)
|
817
|
-
break;
|
818
|
-
|
819
|
-
offset += length;
|
820
|
-
}
|
821
|
-
|
822
|
-
return offset;
|
823
|
-
}
|
824
|
-
|
825
872
|
#ifdef GIT_WIN32
|
826
873
|
int git__getenv(git_buf *out, const char *name)
|
827
874
|
{
|
data/vendor/libgit2/src/util.h
CHANGED
@@ -41,6 +41,141 @@
|
|
41
41
|
*/
|
42
42
|
#define CONST_STRLEN(x) ((sizeof(x)/sizeof(x[0])) - 1)
|
43
43
|
|
44
|
+
#if defined(GIT_MSVC_CRTDBG)
|
45
|
+
|
46
|
+
/* Enable MSVC CRTDBG memory leak reporting.
|
47
|
+
*
|
48
|
+
* We DO NOT use the "_CRTDBG_MAP_ALLOC" macro described in the MSVC
|
49
|
+
* documentation because all allocs/frees in libgit2 already go through
|
50
|
+
* the "git__" routines defined in this file. Simply using the normal
|
51
|
+
* reporting mechanism causes all leaks to be attributed to a routine
|
52
|
+
* here in util.h (ie, the actual call to calloc()) rather than the
|
53
|
+
* caller of git__calloc().
|
54
|
+
*
|
55
|
+
* Therefore, we declare a set of "git__crtdbg__" routines to replace
|
56
|
+
* the corresponding "git__" routines and re-define the "git__" symbols
|
57
|
+
* as macros. This allows us to get and report the file:line info of
|
58
|
+
* the real caller.
|
59
|
+
*
|
60
|
+
* We DO NOT replace the "git__free" routine because it needs to remain
|
61
|
+
* a function pointer because it is used as a function argument when
|
62
|
+
* setting up various structure "destructors".
|
63
|
+
*
|
64
|
+
* We also DO NOT use the "_CRTDBG_MAP_ALLOC" macro because it causes
|
65
|
+
* "free" to be remapped to "_free_dbg" and this causes problems for
|
66
|
+
* structures which define a field named "free".
|
67
|
+
*
|
68
|
+
* Finally, CRTDBG must be explicitly enabled and configured at program
|
69
|
+
* startup. See tests/main.c for an example.
|
70
|
+
*/
|
71
|
+
|
72
|
+
#include "win32/w32_crtdbg_stacktrace.h"
|
73
|
+
|
74
|
+
#define git__malloc(len) git__crtdbg__malloc(len, __FILE__, __LINE__)
|
75
|
+
#define git__calloc(nelem, elsize) git__crtdbg__calloc(nelem, elsize, __FILE__, __LINE__)
|
76
|
+
#define git__strdup(str) git__crtdbg__strdup(str, __FILE__, __LINE__)
|
77
|
+
#define git__strndup(str, n) git__crtdbg__strndup(str, n, __FILE__, __LINE__)
|
78
|
+
#define git__substrdup(str, n) git__crtdbg__substrdup(str, n, __FILE__, __LINE__)
|
79
|
+
#define git__realloc(ptr, size) git__crtdbg__realloc(ptr, size, __FILE__, __LINE__)
|
80
|
+
#define git__reallocarray(ptr, nelem, elsize) git__crtdbg__reallocarray(ptr, nelem, elsize, __FILE__, __LINE__)
|
81
|
+
#define git__mallocarray(nelem, elsize) git__crtdbg__mallocarray(nelem, elsize, __FILE__, __LINE__)
|
82
|
+
|
83
|
+
#else
|
84
|
+
|
85
|
+
/*
|
86
|
+
* Custom memory allocation wrappers
|
87
|
+
* that set error code and error message
|
88
|
+
* on allocation failure
|
89
|
+
*/
|
90
|
+
GIT_INLINE(void *) git__malloc(size_t len)
|
91
|
+
{
|
92
|
+
void *ptr = malloc(len);
|
93
|
+
if (!ptr) giterr_set_oom();
|
94
|
+
return ptr;
|
95
|
+
}
|
96
|
+
|
97
|
+
GIT_INLINE(void *) git__calloc(size_t nelem, size_t elsize)
|
98
|
+
{
|
99
|
+
void *ptr = calloc(nelem, elsize);
|
100
|
+
if (!ptr) giterr_set_oom();
|
101
|
+
return ptr;
|
102
|
+
}
|
103
|
+
|
104
|
+
GIT_INLINE(char *) git__strdup(const char *str)
|
105
|
+
{
|
106
|
+
char *ptr = strdup(str);
|
107
|
+
if (!ptr) giterr_set_oom();
|
108
|
+
return ptr;
|
109
|
+
}
|
110
|
+
|
111
|
+
GIT_INLINE(char *) git__strndup(const char *str, size_t n)
|
112
|
+
{
|
113
|
+
size_t length = 0, alloclength;
|
114
|
+
char *ptr;
|
115
|
+
|
116
|
+
length = p_strnlen(str, n);
|
117
|
+
|
118
|
+
if (GIT_ADD_SIZET_OVERFLOW(&alloclength, length, 1) ||
|
119
|
+
!(ptr = git__malloc(alloclength)))
|
120
|
+
return NULL;
|
121
|
+
|
122
|
+
if (length)
|
123
|
+
memcpy(ptr, str, length);
|
124
|
+
|
125
|
+
ptr[length] = '\0';
|
126
|
+
|
127
|
+
return ptr;
|
128
|
+
}
|
129
|
+
|
130
|
+
/* NOTE: This doesn't do null or '\0' checking. Watch those boundaries! */
|
131
|
+
GIT_INLINE(char *) git__substrdup(const char *start, size_t n)
|
132
|
+
{
|
133
|
+
char *ptr;
|
134
|
+
size_t alloclen;
|
135
|
+
|
136
|
+
if (GIT_ADD_SIZET_OVERFLOW(&alloclen, n, 1) ||
|
137
|
+
!(ptr = git__malloc(alloclen)))
|
138
|
+
return NULL;
|
139
|
+
|
140
|
+
memcpy(ptr, start, n);
|
141
|
+
ptr[n] = '\0';
|
142
|
+
return ptr;
|
143
|
+
}
|
144
|
+
|
145
|
+
GIT_INLINE(void *) git__realloc(void *ptr, size_t size)
|
146
|
+
{
|
147
|
+
void *new_ptr = realloc(ptr, size);
|
148
|
+
if (!new_ptr) giterr_set_oom();
|
149
|
+
return new_ptr;
|
150
|
+
}
|
151
|
+
|
152
|
+
/**
|
153
|
+
* Similar to `git__realloc`, except that it is suitable for reallocing an
|
154
|
+
* array to a new number of elements of `nelem`, each of size `elsize`.
|
155
|
+
* The total size calculation is checked for overflow.
|
156
|
+
*/
|
157
|
+
GIT_INLINE(void *) git__reallocarray(void *ptr, size_t nelem, size_t elsize)
|
158
|
+
{
|
159
|
+
size_t newsize;
|
160
|
+
return GIT_MULTIPLY_SIZET_OVERFLOW(&newsize, nelem, elsize) ?
|
161
|
+
NULL : realloc(ptr, newsize);
|
162
|
+
}
|
163
|
+
|
164
|
+
/**
|
165
|
+
* Similar to `git__calloc`, except that it does not zero memory.
|
166
|
+
*/
|
167
|
+
GIT_INLINE(void *) git__mallocarray(size_t nelem, size_t elsize)
|
168
|
+
{
|
169
|
+
return git__reallocarray(NULL, nelem, elsize);
|
170
|
+
}
|
171
|
+
|
172
|
+
#endif /* !MSVC_CTRDBG */
|
173
|
+
|
174
|
+
GIT_INLINE(void) git__free(void *ptr)
|
175
|
+
{
|
176
|
+
free(ptr);
|
177
|
+
}
|
178
|
+
|
44
179
|
#define STRCMP_CASESELECT(IGNORE_CASE, STR1, STR2) \
|
45
180
|
((IGNORE_CASE) ? strcasecmp((STR1), (STR2)) : strcmp((STR1), (STR2)))
|
46
181
|
|
@@ -58,9 +193,7 @@ GIT_INLINE(int) git__signum(int val)
|
|
58
193
|
return ((val > 0) - (val < 0));
|
59
194
|
}
|
60
195
|
|
61
|
-
extern int git__strtol32(int32_t *n, const char *buff, const char **end_buf, int base);
|
62
196
|
extern int git__strntol32(int32_t *n, const char *buff, size_t buff_len, const char **end_buf, int base);
|
63
|
-
extern int git__strtol64(int64_t *n, const char *buff, const char **end_buf, int base);
|
64
197
|
extern int git__strntol64(int64_t *n, const char *buff, size_t buff_len, const char **end_buf, int base);
|
65
198
|
|
66
199
|
|
@@ -113,6 +246,9 @@ GIT_INLINE(const void *) git__memrchr(const void *s, int c, size_t n)
|
|
113
246
|
return NULL;
|
114
247
|
}
|
115
248
|
|
249
|
+
extern const void * git__memmem(const void *haystack, size_t haystacklen,
|
250
|
+
const void *needle, size_t needlelen);
|
251
|
+
|
116
252
|
typedef int (*git__tsort_cmp)(const void *a, const void *b);
|
117
253
|
|
118
254
|
extern void git__tsort(void **dst, size_t size, git__tsort_cmp cmp);
|
@@ -318,16 +454,6 @@ extern size_t git__unescape(char *str);
|
|
318
454
|
*/
|
319
455
|
extern int git__utf8_iterate(const uint8_t *str, int str_len, int32_t *dst);
|
320
456
|
|
321
|
-
/*
|
322
|
-
* Iterate through an UTF-8 string and stops after finding any invalid UTF-8
|
323
|
-
* codepoints.
|
324
|
-
*
|
325
|
-
* @param str string to scan
|
326
|
-
* @param str_len size of the string
|
327
|
-
* @return length in bytes of the string that contains valid data
|
328
|
-
*/
|
329
|
-
extern size_t git__utf8_valid_buf_length(const uint8_t *str, size_t str_len);
|
330
|
-
|
331
457
|
/*
|
332
458
|
* Safely zero-out memory, making sure that the compiler
|
333
459
|
* doesn't optimize away the operation.
|
@@ -418,6 +544,4 @@ GIT_INLINE(double) git__timer(void)
|
|
418
544
|
|
419
545
|
extern int git__getenv(git_buf *out, const char *name);
|
420
546
|
|
421
|
-
#include "alloc.h"
|
422
|
-
|
423
547
|
#endif
|
data/vendor/libgit2/src/vector.c
CHANGED
@@ -32,6 +32,9 @@ GIT_INLINE(int) resize_vector(git_vector *v, size_t new_size)
|
|
32
32
|
{
|
33
33
|
void *new_contents;
|
34
34
|
|
35
|
+
if (new_size == 0)
|
36
|
+
return 0;
|
37
|
+
|
35
38
|
new_contents = git__reallocarray(v->contents, new_size, sizeof(void *));
|
36
39
|
GITERR_CHECK_ALLOC(new_contents);
|
37
40
|
|
@@ -50,22 +53,24 @@ int git_vector_size_hint(git_vector *v, size_t size_hint)
|
|
50
53
|
|
51
54
|
int git_vector_dup(git_vector *v, const git_vector *src, git_vector_cmp cmp)
|
52
55
|
{
|
53
|
-
size_t bytes;
|
54
|
-
|
55
56
|
assert(v && src);
|
56
57
|
|
57
|
-
|
58
|
-
|
59
|
-
v->_alloc_size = src->length;
|
58
|
+
v->_alloc_size = 0;
|
59
|
+
v->contents = NULL;
|
60
60
|
v->_cmp = cmp ? cmp : src->_cmp;
|
61
61
|
v->length = src->length;
|
62
62
|
v->flags = src->flags;
|
63
63
|
if (cmp != src->_cmp)
|
64
64
|
git_vector_set_sorted(v, 0);
|
65
|
-
v->contents = git__malloc(bytes);
|
66
|
-
GITERR_CHECK_ALLOC(v->contents);
|
67
65
|
|
68
|
-
|
66
|
+
if (src->length) {
|
67
|
+
size_t bytes;
|
68
|
+
GITERR_CHECK_ALLOC_MULTIPLY(&bytes, src->length, sizeof(void *));
|
69
|
+
v->contents = git__malloc(bytes);
|
70
|
+
GITERR_CHECK_ALLOC(v->contents);
|
71
|
+
v->_alloc_size = src->length;
|
72
|
+
memcpy(v->contents, src->contents, bytes);
|
73
|
+
}
|
69
74
|
|
70
75
|
return 0;
|
71
76
|
}
|