Skip to content

Commit d6b97cb

Browse files
committed
Merge pull request libgit2#2596 from libgit2/cmn/maint-21
Add a few backports to 0.21 maintenance
2 parents 59fbaa4 + 0571362 commit d6b97cb

File tree

18 files changed

+112
-38
lines changed

18 files changed

+112
-38
lines changed

include/git2.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "git2/notes.h"
3333
#include "git2/object.h"
3434
#include "git2/odb.h"
35+
#include "git2/odb_backend.h"
3536
#include "git2/oid.h"
3637
#include "git2/pack.h"
3738
#include "git2/patch.h"

src/cc-compat.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@
3535
# define GIT_TYPEOF(x)
3636
#endif
3737

38+
#if defined(__GNUC__)
39+
# define GIT_ALIGN(x,size) x __attribute__ ((aligned(size)))
40+
#elif defined(_MSC_VER)
41+
# define GIT_ALIGN(x,size) __declspec(align(size)) x
42+
#else
43+
# define GIT_ALIGN(x,size) x
44+
#endif
45+
3846
#define GIT_UNUSED(x) ((void)(x))
3947

4048
/* Define the printf format specifer to use for size_t output */

src/config_file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,7 @@ static int strip_comments(char *line, int in_quotes)
11631163
}
11641164

11651165
/* skip any space at the end */
1166-
if (ptr > line && git__isspace(ptr[-1])) {
1166+
while (ptr > line && git__isspace(ptr[-1])) {
11671167
ptr--;
11681168
}
11691169
ptr[0] = '\0';

src/diff_patch.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ int git_diff_foreach(
274274
return error;
275275

276276
memset(&xo, 0, sizeof(xo));
277+
memset(&patch, 0, sizeof(patch));
277278
diff_output_init(
278279
&xo.output, &diff->opts, file_cb, hunk_cb, data_cb, payload);
279280
git_xdiff_init(&xo, &diff->opts);

src/filter.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct git_filter_list {
3838
};
3939

4040
typedef struct {
41-
const char *filter_name;
41+
char *filter_name;
4242
git_filter *filter;
4343
int priority;
4444
int initialized;
@@ -75,6 +75,7 @@ static void filter_registry_shutdown(void)
7575
fdef->initialized = false;
7676
}
7777

78+
git__free(fdef->filter_name);
7879
git__free(fdef->attrdata);
7980
git__free(fdef);
8081
}
@@ -230,6 +231,8 @@ int git_filter_register(
230231
size_t nattr = 0, nmatch = 0;
231232
git_buf attrs = GIT_BUF_INIT;
232233

234+
assert(name && filter);
235+
233236
if (filter_registry_initialize() < 0)
234237
return -1;
235238

@@ -246,7 +249,9 @@ int git_filter_register(
246249
sizeof(git_filter_def) + 2 * nattr * sizeof(char *), 1);
247250
GITERR_CHECK_ALLOC(fdef);
248251

249-
fdef->filter_name = name;
252+
fdef->filter_name = git__strdup(name);
253+
GITERR_CHECK_ALLOC(fdef->filter_name);
254+
250255
fdef->filter = filter;
251256
fdef->priority = priority;
252257
fdef->nattrs = nattr;
@@ -256,6 +261,7 @@ int git_filter_register(
256261
filter_def_set_attrs(fdef);
257262

258263
if (git_vector_insert(&git__filter_registry->filters, fdef) < 0) {
264+
git__free(fdef->filter_name);
259265
git__free(fdef->attrdata);
260266
git__free(fdef);
261267
return -1;
@@ -270,6 +276,8 @@ int git_filter_unregister(const char *name)
270276
size_t pos;
271277
git_filter_def *fdef;
272278

279+
assert(name);
280+
273281
/* cannot unregister default filters */
274282
if (!strcmp(GIT_FILTER_CRLF, name) || !strcmp(GIT_FILTER_IDENT, name)) {
275283
giterr_set(GITERR_FILTER, "Cannot unregister filter '%s'", name);
@@ -288,6 +296,7 @@ int git_filter_unregister(const char *name)
288296
fdef->initialized = false;
289297
}
290298

299+
git__free(fdef->filter_name);
291300
git__free(fdef->attrdata);
292301
git__free(fdef);
293302

src/global.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ int init_error = 0;
221221

222222
static void cb__free_status(void *st)
223223
{
224+
git_global_st *state = (git_global_st *) st;
225+
git__free(state->error_t.message);
226+
224227
git__free(st);
225228
}
226229

src/index.c

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,35 +1767,42 @@ static size_t read_entry(
17671767
git_index_entry **out, const void *buffer, size_t buffer_size)
17681768
{
17691769
size_t path_length, entry_size;
1770-
uint16_t flags_raw;
17711770
const char *path_ptr;
1772-
const struct entry_short *source = buffer;
1771+
struct entry_short source;
17731772
git_index_entry entry = {{0}};
17741773

17751774
if (INDEX_FOOTER_SIZE + minimal_entry_size > buffer_size)
17761775
return 0;
17771776

1778-
entry.ctime.seconds = (git_time_t)ntohl(source->ctime.seconds);
1779-
entry.ctime.nanoseconds = ntohl(source->ctime.nanoseconds);
1780-
entry.mtime.seconds = (git_time_t)ntohl(source->mtime.seconds);
1781-
entry.mtime.nanoseconds = ntohl(source->mtime.nanoseconds);
1782-
entry.dev = ntohl(source->dev);
1783-
entry.ino = ntohl(source->ino);
1784-
entry.mode = ntohl(source->mode);
1785-
entry.uid = ntohl(source->uid);
1786-
entry.gid = ntohl(source->gid);
1787-
entry.file_size = ntohl(source->file_size);
1788-
git_oid_cpy(&entry.id, &source->oid);
1789-
entry.flags = ntohs(source->flags);
1777+
/* buffer is not guaranteed to be aligned */
1778+
memcpy(&source, buffer, sizeof(struct entry_short));
1779+
1780+
entry.ctime.seconds = (git_time_t)ntohl(source.ctime.seconds);
1781+
entry.ctime.nanoseconds = ntohl(source.ctime.nanoseconds);
1782+
entry.mtime.seconds = (git_time_t)ntohl(source.mtime.seconds);
1783+
entry.mtime.nanoseconds = ntohl(source.mtime.nanoseconds);
1784+
entry.dev = ntohl(source.dev);
1785+
entry.ino = ntohl(source.ino);
1786+
entry.mode = ntohl(source.mode);
1787+
entry.uid = ntohl(source.uid);
1788+
entry.gid = ntohl(source.gid);
1789+
entry.file_size = ntohl(source.file_size);
1790+
git_oid_cpy(&entry.id, &source.oid);
1791+
entry.flags = ntohs(source.flags);
17901792

17911793
if (entry.flags & GIT_IDXENTRY_EXTENDED) {
1792-
const struct entry_long *source_l = (const struct entry_long *)source;
1793-
path_ptr = source_l->path;
1794+
uint16_t flags_raw;
1795+
size_t flags_offset;
17941796

1795-
flags_raw = ntohs(source_l->flags_extended);
1796-
memcpy(&entry.flags_extended, &flags_raw, 2);
1797+
flags_offset = offsetof(struct entry_long, flags_extended);
1798+
memcpy(&flags_raw, (const char *) buffer + flags_offset,
1799+
sizeof(flags_raw));
1800+
flags_raw = ntohs(flags_raw);
1801+
1802+
memcpy(&entry.flags_extended, &flags_raw, sizeof(flags_raw));
1803+
path_ptr = (const char *) buffer + offsetof(struct entry_long, path);
17971804
} else
1798-
path_ptr = source->path;
1805+
path_ptr = (const char *) buffer + offsetof(struct entry_short, path);
17991806

18001807
path_length = entry.flags & GIT_IDXENTRY_NAMEMASK;
18011808

@@ -1846,14 +1853,12 @@ static int read_header(struct index_header *dest, const void *buffer)
18461853

18471854
static size_t read_extension(git_index *index, const char *buffer, size_t buffer_size)
18481855
{
1849-
const struct index_extension *source;
18501856
struct index_extension dest;
18511857
size_t total_size;
18521858

1853-
source = (const struct index_extension *)(buffer);
1854-
1855-
memcpy(dest.signature, source->signature, 4);
1856-
dest.extension_size = ntohl(source->extension_size);
1859+
/* buffer is not guaranteed to be aligned */
1860+
memcpy(&dest, buffer, sizeof(struct index_extension));
1861+
dest.extension_size = ntohl(dest.extension_size);
18571862

18581863
total_size = dest.extension_size + sizeof(struct index_extension);
18591864

src/netops.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ int gitno_connect(gitno_socket *s_out, const char *host, const char *port, int f
460460
hints.ai_socktype = SOCK_STREAM;
461461
hints.ai_family = AF_UNSPEC;
462462

463-
if ((ret = p_getaddrinfo(host, port, &hints, &info)) < 0) {
463+
if ((ret = p_getaddrinfo(host, port, &hints, &info)) != 0) {
464464
giterr_set(GITERR_NET,
465465
"Failed to resolve address for %s: %s", host, p_gai_strerror(ret));
466466
return -1;

src/pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ int git_packfile_unpack(
620620
struct pack_chain_elem *elem = NULL, *stack;
621621
git_pack_cache_entry *cached = NULL;
622622
struct pack_chain_elem small_stack[SMALL_STACK_SIZE];
623-
size_t stack_size, elem_pos;
623+
size_t stack_size = 0, elem_pos;
624624
git_otype base_type;
625625

626626
/*

src/pool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ struct git_pool_page {
77
git_pool_page *next;
88
uint32_t size;
99
uint32_t avail;
10-
char data[GIT_FLEX_ARRAY];
10+
GIT_ALIGN(char data[GIT_FLEX_ARRAY], 8);
1111
};
1212

1313
struct pool_freelist {

0 commit comments

Comments
 (0)