summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cache.c1
-rw-r--r--src/config_file.c4
-rw-r--r--src/diff_tform.c8
-rw-r--r--src/filter.c5
-rw-r--r--src/fnmatch.c10
-rw-r--r--src/global.c16
-rw-r--r--src/indexer.c2
-rw-r--r--src/iterator.c8
-rw-r--r--src/merge.c4
-rw-r--r--src/netops.c6
-rw-r--r--src/object.c10
-rw-r--r--src/odb.c2
-rw-r--r--src/odb_pack.c2
-rw-r--r--src/pack.c21
-rw-r--r--src/path.c8
-rw-r--r--src/rebase.c2
-rw-r--r--src/remote.c5
-rw-r--r--src/transports/cred.c6
-rw-r--r--src/transports/ssh.c18
-rw-r--r--src/util.c18
-rw-r--r--src/util.h9
21 files changed, 104 insertions, 61 deletions
diff --git a/src/cache.c b/src/cache.c
index 8dc9cbf9c..2f3ad1563 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -68,6 +68,7 @@ int git_cache_init(git_cache *cache)
{
memset(cache, 0, sizeof(*cache));
cache->map = git_oidmap_alloc();
+ GITERR_CHECK_ALLOC(cache->map);
if (git_rwlock_init(&cache->lock)) {
giterr_set(GITERR_OS, "Failed to initialize cache rwlock");
return -1;
diff --git a/src/config_file.c b/src/config_file.c
index d6a62b85c..52a5376bd 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -156,7 +156,7 @@ int git_config_file_normalize_section(char *start, char *end)
if (end && scan >= end)
break;
if (isalnum(*scan))
- *scan = (char)tolower(*scan);
+ *scan = (char)git__tolower(*scan);
else if (*scan != '-' || scan == start)
return GIT_EINVALIDSPEC;
}
@@ -1083,7 +1083,7 @@ static int parse_section_header(struct reader *reader, char **section_out)
goto fail_parse;
}
- name[name_length++] = (char) tolower(c);
+ name[name_length++] = (char)git__tolower(c);
} while ((c = line[pos++]) != ']');
diff --git a/src/diff_tform.c b/src/diff_tform.c
index 7d8463573..03dd9c9f7 100644
--- a/src/diff_tform.c
+++ b/src/diff_tform.c
@@ -676,11 +676,13 @@ static bool is_rename_target(
return false;
/* only consider ADDED, RENAMED, COPIED, and split MODIFIED as
- * targets; maybe include UNTRACKED and IGNORED if requested.
+ * targets; maybe include UNTRACKED if requested.
*/
switch (delta->status) {
case GIT_DELTA_UNMODIFIED:
case GIT_DELTA_DELETED:
+ case GIT_DELTA_IGNORED:
+ case GIT_DELTA_CONFLICTED:
return false;
case GIT_DELTA_MODIFIED:
@@ -707,9 +709,6 @@ static bool is_rename_target(
return false;
break;
- case GIT_DELTA_IGNORED:
- return false;
-
default: /* all other status values should be checked */
break;
}
@@ -735,6 +734,7 @@ static bool is_rename_source(
case GIT_DELTA_UNTRACKED:
case GIT_DELTA_UNREADABLE:
case GIT_DELTA_IGNORED:
+ case GIT_DELTA_CONFLICTED:
return false;
case GIT_DELTA_DELETED:
diff --git a/src/filter.c b/src/filter.c
index c88fdd4ee..3c6a0a9d8 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -887,7 +887,7 @@ int git_filter_list_stream_file(
git_vector filter_streams = GIT_VECTOR_INIT;
git_writestream *stream_start;
ssize_t readlen;
- int fd, error;
+ int fd = -1, error;
if ((error = stream_list_init(
&stream_start, &filter_streams, filters, target)) < 0 ||
@@ -909,9 +909,10 @@ int git_filter_list_stream_file(
else if (readlen < 0)
error = readlen;
- p_close(fd);
done:
+ if (fd >= 0)
+ p_close(fd);
stream_list_free(&filter_streams);
git_buf_free(&abspath);
return error;
diff --git a/src/fnmatch.c b/src/fnmatch.c
index d7899e3e6..a2945b8db 100644
--- a/src/fnmatch.c
+++ b/src/fnmatch.c
@@ -164,8 +164,8 @@ p_fnmatchx(const char *pattern, const char *string, int flags, size_t recurs)
default:
normal:
if (c != *string && !((flags & FNM_CASEFOLD) &&
- (tolower((unsigned char)c) ==
- tolower((unsigned char)*string))))
+ (git__tolower((unsigned char)c) ==
+ git__tolower((unsigned char)*string))))
return (FNM_NOMATCH);
++string;
break;
@@ -190,7 +190,7 @@ rangematch(const char *pattern, char test, int flags, char **newp)
++pattern;
if (flags & FNM_CASEFOLD)
- test = (char)tolower((unsigned char)test);
+ test = (char)git__tolower((unsigned char)test);
/*
* A right bracket shall lose its special meaning and represent
@@ -207,7 +207,7 @@ rangematch(const char *pattern, char test, int flags, char **newp)
if (c == '/' && (flags & FNM_PATHNAME))
return (RANGE_NOMATCH);
if ((flags & FNM_CASEFOLD))
- c = (char)tolower((unsigned char)c);
+ c = (char)git__tolower((unsigned char)c);
if (*pattern == '-'
&& (c2 = *(pattern+1)) != EOS && c2 != ']') {
pattern += 2;
@@ -216,7 +216,7 @@ rangematch(const char *pattern, char test, int flags, char **newp)
if (c2 == EOS)
return (RANGE_ERROR);
if (flags & FNM_CASEFOLD)
- c2 = (char)tolower((unsigned char)c2);
+ c2 = (char)git__tolower((unsigned char)c2);
if (c <= test && test <= c2)
ok = 1;
} else if (c == test)
diff --git a/src/global.c b/src/global.c
index 9f1a0bf10..3f20bfd31 100644
--- a/src/global.c
+++ b/src/global.c
@@ -116,6 +116,20 @@ static void init_ssl(void)
#endif
}
+/**
+ * This function aims to clean-up the SSL context which
+ * we allocated.
+ */
+static void uninit_ssl(void)
+{
+#ifdef GIT_OPENSSL
+ if (git__ssl_ctx) {
+ SSL_CTX_free(git__ssl_ctx);
+ git__ssl_ctx = NULL;
+ }
+#endif
+}
+
int git_openssl_set_locking(void)
{
#ifdef GIT_OPENSSL
@@ -333,6 +347,7 @@ int git_libgit2_shutdown(void)
/* Shut down any subsystems that have global state */
git__shutdown();
+ uninit_ssl();
ptr = pthread_getspecific(_tls_key);
pthread_setspecific(_tls_key, NULL);
@@ -391,6 +406,7 @@ int git_libgit2_shutdown(void)
git__shutdown();
git__global_state_cleanup(&__state);
+ uninit_ssl();
return 0;
}
diff --git a/src/indexer.c b/src/indexer.c
index 1890b0063..512addf48 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -823,7 +823,7 @@ static int resolve_deltas(git_indexer *idx, git_transfer_progress *stats)
progressed = 0;
non_null = 0;
git_vector_foreach(&idx->deltas, i, delta) {
- git_rawobj obj;
+ git_rawobj obj = {NULL};
if (!delta)
continue;
diff --git a/src/iterator.c b/src/iterator.c
index 93303a87d..7807a1636 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -1405,10 +1405,10 @@ GIT_INLINE(bool) workdir_path_is_dotgit(const git_buf *path)
if (path->ptr[len - 1] == '/')
len--;
- if (tolower(path->ptr[len - 1]) != 't' ||
- tolower(path->ptr[len - 2]) != 'i' ||
- tolower(path->ptr[len - 3]) != 'g' ||
- tolower(path->ptr[len - 4]) != '.')
+ if (git__tolower(path->ptr[len - 1]) != 't' ||
+ git__tolower(path->ptr[len - 2]) != 'i' ||
+ git__tolower(path->ptr[len - 3]) != 'g' ||
+ git__tolower(path->ptr[len - 4]) != '.')
return false;
return (len == 4 || path->ptr[len - 5] == '/');
diff --git a/src/merge.c b/src/merge.c
index 28fca0038..517d317de 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -1143,9 +1143,9 @@ static void merge_diff_list_count_candidates(
if (GIT_MERGE_INDEX_ENTRY_EXISTS(entry->ancestor_entry) &&
(!GIT_MERGE_INDEX_ENTRY_EXISTS(entry->our_entry) ||
!GIT_MERGE_INDEX_ENTRY_EXISTS(entry->their_entry)))
- src_count++;
+ (*src_count)++;
else if (!GIT_MERGE_INDEX_ENTRY_EXISTS(entry->ancestor_entry))
- tgt_count++;
+ (*tgt_count)++;
}
}
diff --git a/src/netops.c b/src/netops.c
index 6047cf1ac..5e8075597 100644
--- a/src/netops.c
+++ b/src/netops.c
@@ -84,7 +84,7 @@ void gitno_consume_n(gitno_buffer *buf, size_t cons)
int gitno__match_host(const char *pattern, const char *host)
{
for (;;) {
- char c = tolower(*pattern++);
+ char c = git__tolower(*pattern++);
if (c == '\0')
return *host ? -1 : 0;
@@ -102,7 +102,7 @@ int gitno__match_host(const char *pattern, const char *host)
*/
while(*host) {
- char h = tolower(*host);
+ char h = git__tolower(*host);
if (c == h)
return gitno__match_host(pattern, host++);
if (h == '.')
@@ -112,7 +112,7 @@ int gitno__match_host(const char *pattern, const char *host)
return -1;
}
- if (c != tolower(*host++))
+ if (c != git__tolower(*host++))
return -1;
}
diff --git a/src/object.c b/src/object.c
index 1073559fd..a178e0ed3 100644
--- a/src/object.c
+++ b/src/object.c
@@ -129,10 +129,10 @@ int git_object_lookup_prefix(
if (error < 0)
return error;
- if (len > GIT_OID_HEXSZ)
- len = GIT_OID_HEXSZ;
+ if (len > GIT_OID_RAWSZ)
+ len = GIT_OID_RAWSZ;
- if (len == GIT_OID_HEXSZ) {
+ if (len == GIT_OID_RAWSZ) {
git_cached_obj *cached = NULL;
/* We want to match the full id : we can first look up in the cache,
@@ -172,9 +172,9 @@ int git_object_lookup_prefix(
memcpy(short_oid.id, id->id, (len + 1) / 2);
if (len % 2)
short_oid.id[len / 2] &= 0xF0;
- memset(short_oid.id + (len + 1) / 2, 0, (GIT_OID_HEXSZ - len) / 2);
+ memset(short_oid.id + (len + 1) / 2, 0, (GIT_OID_RAWSZ - len) / 2);
- /* If len < GIT_OID_HEXSZ (a strict short oid was given), we have
+ /* If len < GIT_OID_RAWSZ (a strict short oid was given), we have
* 2 options :
* - We always search in the cache first. If we find that short oid is
* ambiguous, we can stop. But in all the other cases, we must then
diff --git a/src/odb.c b/src/odb.c
index deb9d5c82..7a718f5d6 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -53,7 +53,7 @@ static int load_alternates(git_odb *odb, const char *objects_dir, int alternate_
int git_odb__format_object_header(char *hdr, size_t n, git_off_t obj_len, git_otype obj_type)
{
const char *type_str = git_object_type2string(obj_type);
- int len = p_snprintf(hdr, n, "%s %"PRIuZ, type_str, obj_len);
+ int len = p_snprintf(hdr, n, "%s %lld", type_str, obj_len);
assert(len > 0 && len <= (int)n);
return len+1;
}
diff --git a/src/odb_pack.c b/src/odb_pack.c
index 1757cf920..735158d96 100644
--- a/src/odb_pack.c
+++ b/src/odb_pack.c
@@ -383,7 +383,7 @@ static int pack_backend__read_internal(
git_odb_backend *backend, const git_oid *oid)
{
struct git_pack_entry e;
- git_rawobj raw;
+ git_rawobj raw = {NULL};
int error;
if ((error = pack_entry_find(&e, (struct pack_backend *)backend, oid)) < 0 ||
diff --git a/src/pack.c b/src/pack.c
index 105d67510..cd6526721 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -319,9 +319,9 @@ static int pack_index_check(const char *path, struct git_pack_file *p)
static int pack_index_open(struct git_pack_file *p)
{
- char *idx_name;
int error = 0;
- size_t name_len, base_len;
+ size_t name_len;
+ git_buf idx_name = GIT_BUF_INIT;
if (p->index_version > -1)
return 0;
@@ -329,22 +329,23 @@ static int pack_index_open(struct git_pack_file *p)
name_len = strlen(p->pack_name);
assert(name_len > strlen(".pack")); /* checked by git_pack_file alloc */
- if ((idx_name = git__malloc(name_len)) == NULL)
+ git_buf_grow(&idx_name, name_len);
+ git_buf_put(&idx_name, p->pack_name, name_len - strlen(".pack"));
+ git_buf_puts(&idx_name, ".idx");
+ if (git_buf_oom(&idx_name)) {
+ giterr_set_oom();
return -1;
-
- base_len = name_len - strlen(".pack");
- memcpy(idx_name, p->pack_name, base_len);
- memcpy(idx_name + base_len, ".idx", sizeof(".idx"));
+ }
if ((error = git_mutex_lock(&p->lock)) < 0) {
- git__free(idx_name);
+ git_buf_free(&idx_name);
return error;
}
if (p->index_version == -1)
- error = pack_index_check(idx_name, p);
+ error = pack_index_check(idx_name.ptr, p);
- git__free(idx_name);
+ git_buf_free(&idx_name);
git_mutex_unlock(&p->lock);
diff --git a/src/path.c b/src/path.c
index 81b4d51df..02917607a 100644
--- a/src/path.c
+++ b/src/path.c
@@ -1066,8 +1066,10 @@ int git_path_direach(
git_buf_truncate(path, wd_len); /* restore path */
/* Only set our own error if the callback did not set one already */
- if (error != 0 && !giterr_last()) {
- giterr_set_after_callback(error);
+ if (error != 0) {
+ if (!giterr_last())
+ giterr_set_after_callback(error);
+
break;
}
}
@@ -1471,7 +1473,7 @@ static int32_t next_hfs_char(const char **in, size_t *len)
* the ASCII range, which is perfectly fine, because the
* git folder name can only be composed of ascii characters
*/
- return tolower(codepoint);
+ return git__tolower(codepoint);
}
return 0; /* NULL byte -- end of string */
}
diff --git a/src/rebase.c b/src/rebase.c
index b636e7951..8da7b4f7f 100644
--- a/src/rebase.c
+++ b/src/rebase.c
@@ -512,7 +512,7 @@ static int rebase_ensure_not_dirty(
git_tree *head = NULL;
git_index *index = NULL;
git_diff *diff = NULL;
- int error;
+ int error = 0;
if (check_index) {
if ((error = git_repository_head_tree(&head, repo)) < 0 ||
diff --git a/src/remote.c b/src/remote.c
index b7acbb9c1..63f6d3462 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -869,7 +869,7 @@ int git_remote_download(git_remote *remote, const git_strarray *refspecs, const
{
int error = -1;
size_t i;
- git_vector refs, specs, *to_active;
+ git_vector *to_active, specs = GIT_VECTOR_INIT, refs = GIT_VECTOR_INIT;
const git_remote_callbacks *cbs = NULL;
assert(remote);
@@ -2451,7 +2451,8 @@ char *apply_insteadof(git_config *config, const char *url, int direction)
suffix_length = strlen(SUFFIX_PUSH) + 1;
}
- git_config_iterator_glob_new(&iter, config, regexp);
+ if (git_config_iterator_glob_new(&iter, config, regexp) < 0)
+ return NULL;
match_length = 0;
while (git_config_next(&entry, iter) == 0) {
diff --git a/src/transports/cred.c b/src/transports/cred.c
index 006cd2c52..044b2a262 100644
--- a/src/transports/cred.c
+++ b/src/transports/cred.c
@@ -209,6 +209,12 @@ int git_cred_ssh_key_memory_new(
passphrase,
GIT_CREDTYPE_SSH_MEMORY);
#else
+ GIT_UNUSED(cred);
+ GIT_UNUSED(username);
+ GIT_UNUSED(publickey);
+ GIT_UNUSED(privatekey);
+ GIT_UNUSED(passphrase);
+
giterr_set(GITERR_INVALID,
"This version of libgit2 was not built with ssh memory credentials.");
return -1;
diff --git a/src/transports/ssh.c b/src/transports/ssh.c
index 58f1aeb64..83af137f8 100644
--- a/src/transports/ssh.c
+++ b/src/transports/ssh.c
@@ -177,11 +177,12 @@ static int ssh_stream_write(
static void ssh_stream_free(git_smart_subtransport_stream *stream)
{
ssh_stream *s = (ssh_stream *)stream;
- ssh_subtransport *t = OWNING_SUBTRANSPORT(s);
- int ret;
+ ssh_subtransport *t;
- GIT_UNUSED(ret);
+ if (!stream)
+ return;
+ t = OWNING_SUBTRANSPORT(s);
t->current_stream = NULL;
if (s->channel) {
@@ -293,8 +294,14 @@ static int ssh_agent_auth(LIBSSH2_SESSION *session, git_cred_ssh_key *c) {
if (rc < 0)
goto shutdown;
- if (rc == 1)
+ /* rc is set to 1 whenever the ssh agent ran out of keys to check.
+ * Set the error code to authentication failure rather than erroring
+ * out with an untranslatable error code.
+ */
+ if (rc == 1) {
+ rc = LIBSSH2_ERROR_AUTHENTICATION_FAILED;
goto shutdown;
+ }
rc = libssh2_agent_userauth(agent, c->username, curr);
@@ -615,8 +622,7 @@ static int _git_ssh_setup_conn(
done:
if (error < 0) {
- if (*stream)
- ssh_stream_free(*stream);
+ ssh_stream_free(*stream);
if (session)
libssh2_session_free(session);
diff --git a/src/util.c b/src/util.c
index 6bb7d03ee..c62826420 100644
--- a/src/util.c
+++ b/src/util.c
@@ -171,9 +171,9 @@ int git__strcmp(const char *a, const char *b)
int git__strcasecmp(const char *a, const char *b)
{
- while (*a && *b && tolower(*a) == tolower(*b))
+ while (*a && *b && git__tolower(*a) == git__tolower(*b))
++a, ++b;
- return (tolower(*a) - tolower(*b));
+ return ((unsigned char)git__tolower(*a) - (unsigned char)git__tolower(*b));
}
int git__strcasesort_cmp(const char *a, const char *b)
@@ -182,7 +182,7 @@ int git__strcasesort_cmp(const char *a, const char *b)
while (*a && *b) {
if (*a != *b) {
- if (tolower(*a) != tolower(*b))
+ if (git__tolower(*a) != git__tolower(*b))
break;
/* use case in sort order even if not in equivalence */
if (!cmp)
@@ -193,7 +193,7 @@ int git__strcasesort_cmp(const char *a, const char *b)
}
if (*a || *b)
- return tolower(*a) - tolower(*b);
+ return (unsigned char)git__tolower(*a) - (unsigned char)git__tolower(*b);
return cmp;
}
@@ -212,8 +212,8 @@ int git__strncasecmp(const char *a, const char *b, size_t sz)
int al, bl;
do {
- al = (unsigned char)tolower(*a);
- bl = (unsigned char)tolower(*b);
+ al = (unsigned char)git__tolower(*a);
+ bl = (unsigned char)git__tolower(*b);
++a, ++b;
} while (--sz && al && al == bl);
@@ -225,7 +225,7 @@ void git__strntolower(char *str, size_t len)
size_t i;
for (i = 0; i < len; ++i) {
- str[i] = (char) tolower(str[i]);
+ str[i] = (char)git__tolower(str[i]);
}
}
@@ -255,8 +255,8 @@ int git__prefixncmp_icase(const char *str, size_t str_n, const char *prefix)
int s, p;
while(str_n--) {
- s = (unsigned char)tolower(*str++);
- p = (unsigned char)tolower(*prefix++);
+ s = (unsigned char)git__tolower(*str++);
+ p = (unsigned char)git__tolower(*prefix++);
if (s != p)
return s - p;
diff --git a/src/util.h b/src/util.h
index be6534580..b2abbe6a6 100644
--- a/src/util.h
+++ b/src/util.h
@@ -275,6 +275,15 @@ extern char *git__strsep(char **end, const char *sep);
extern void git__strntolower(char *str, size_t len);
extern void git__strtolower(char *str);
+#ifdef GIT_WIN32
+GIT_INLINE(int) git__tolower(int c)
+{
+ return (c >= 'A' && c <= 'Z') ? (c + 32) : c;
+}
+#else
+# define git__tolower(a) tolower(a)
+#endif
+
GIT_INLINE(const char *) git__next_line(const char *s)
{
while (*s && *s != '\n') s++;