Fix some Windows warnings This fixes a number of warnings with the Windows 64-bit build including a test failure in test_repo_message__message where an invalid pointer to a git_buf was being used.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
diff --git a/src/index.c b/src/index.c
index 42eb5fd..aa1aebf 100644
--- a/src/index.c
+++ b/src/index.c
@@ -90,7 +90,7 @@ struct entry_long {
struct entry_srch_key {
const char *path;
- int path_len;
+ size_t path_len;
int stage;
};
@@ -110,7 +110,8 @@ static int index_srch(const void *key, const void *array_member)
{
const struct entry_srch_key *srch_key = key;
const git_index_entry *entry = array_member;
- int cmp, len1, len2, len;
+ int cmp;
+ size_t len1, len2, len;
len1 = srch_key->path_len;
len2 = strlen(entry->path);
@@ -134,7 +135,8 @@ static int index_isrch(const void *key, const void *array_member)
{
const struct entry_srch_key *srch_key = key;
const git_index_entry *entry = array_member;
- int cmp, len1, len2, len;
+ int cmp;
+ size_t len1, len2, len;
len1 = srch_key->path_len;
len2 = strlen(entry->path);
@@ -599,9 +601,7 @@ const git_index_entry *git_index_get_bypath(
assert(index);
- git_vector_sort(&index->entries);
-
- if (git_index__find(&pos, index, path, strlen(path), stage) < 0) {
+ if (git_index__find(&pos, index, path, 0, stage) < 0) {
giterr_set(GITERR_INDEX, "Index does not contain %s", path);
return NULL;
}
@@ -837,8 +837,7 @@ static int index_insert(git_index *index, git_index_entry *entry, int replace)
/* look if an entry with this path already exists */
if (!git_index__find(
- &position, index, entry->path, strlen(entry->path),
- GIT_IDXENTRY_STAGE(entry))) {
+ &position, index, entry->path, 0, GIT_IDXENTRY_STAGE(entry))) {
existing = (git_index_entry **)&index->entries.contents[position];
/* update filemode to existing values if stat is not trusted */
entry->mode = index_merge_mode(index, *existing, entry->mode);
@@ -950,9 +949,7 @@ int git_index_remove(git_index *index, const char *path, int stage)
int error;
git_index_entry *entry;
- git_vector_sort(&index->entries);
-
- if (git_index__find(&position, index, path, strlen(path), stage) < 0) {
+ if (git_index__find(&position, index, path, 0, stage) < 0) {
giterr_set(GITERR_INDEX, "Index does not contain %s at stage %d",
path, stage);
return GIT_ENOTFOUND;
@@ -1009,18 +1006,20 @@ int git_index_remove_directory(git_index *index, const char *dir, int stage)
}
int git_index__find(
- size_t *at_pos, git_index *index, const char *path, int path_len, int stage)
+ size_t *out, git_index *index, const char *path, size_t path_len, int stage)
{
struct entry_srch_key srch_key;
assert(path);
+ git_vector_sort(&index->entries);
+
srch_key.path = path;
- srch_key.path_len = path_len;
+ srch_key.path_len = !path_len ? strlen(path) : path_len;
srch_key.stage = stage;
return git_vector_bsearch2(
- at_pos, &index->entries, index->entries_search, &srch_key);
+ out, &index->entries, index->entries_search, &srch_key);
}
int git_index_find(size_t *at_pos, git_index *index, const char *path)
@@ -2234,7 +2233,7 @@ int git_index_add_all(
/* skip ignored items that are not already in the index */
if ((flags & GIT_INDEX_ADD_FORCE) == 0 &&
git_iterator_current_is_ignored(wditer) &&
- git_index__find(&existing, index, wd->path, strlen(wd->path), 0) < 0)
+ git_index__find(&existing, index, wd->path, 0, 0) < 0)
continue;
/* issue notification callback if requested */
diff --git a/src/index.h b/src/index.h
index 3dea4aa..f88d110 100644
--- a/src/index.h
+++ b/src/index.h
@@ -56,7 +56,7 @@ extern int git_index_entry__cmp(const void *a, const void *b);
extern int git_index_entry__cmp_icase(const void *a, const void *b);
extern int git_index__find(
- size_t *at_pos, git_index *index, const char *path, int path_len, int stage);
+ size_t *at_pos, git_index *index, const char *path, size_t path_len, int stage);
extern void git_index__set_ignore_case(git_index *index, bool ignore_case);
diff --git a/src/pathspec.c b/src/pathspec.c
index bee3205..4714884 100644
--- a/src/pathspec.c
+++ b/src/pathspec.c
@@ -445,7 +445,7 @@ static int pathspec_match_from_iterator(
/* check if path is ignored and untracked */
if (index != NULL &&
git_iterator_current_is_ignored(iter) &&
- git_index__find(NULL, index, entry->path, strlen(entry->path), GIT_INDEX_STAGE_ANY) < 0)
+ git_index__find(NULL, index, entry->path, 0, GIT_INDEX_STAGE_ANY) < 0)
continue;
/* mark the matched pattern as used */
diff --git a/src/repository.c b/src/repository.c
index 2c1b602..44d0f0b 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -1716,7 +1716,7 @@ cleanup:
return error;
}
-int git_repository_message(git_buf *out, git_repository *repo)
+int git_repository_message(git_buf *out, git_repository *repo)
{
git_buf path = GIT_BUF_INIT;
struct stat st;
@@ -1731,10 +1731,10 @@ int git_repository_message(git_buf *out, git_repository *repo)
if (errno == ENOENT)
error = GIT_ENOTFOUND;
giterr_set(GITERR_OS, "Could not access message file");
+ } else {
+ error = git_futils_readbuffer(out, git_buf_cstr(&path));
}
- error = git_futils_readbuffer(out, git_buf_cstr(&path));
-
git_buf_free(&path);
return error;
diff --git a/tests/repo/head.c b/tests/repo/head.c
index 8ea9a0f..127176d 100644
--- a/tests/repo/head.c
+++ b/tests/repo/head.c
@@ -200,7 +200,7 @@ static void test_reflog(git_repository *repo, size_t idx,
const char *email, const char *message)
{
git_reflog *log;
- git_reflog_entry *entry;
+ const git_reflog_entry *entry;
cl_git_pass(git_reflog_read(&log, repo, "HEAD"));
entry = git_reflog_entry_byindex(log, idx);
diff --git a/tests/repo/message.c b/tests/repo/message.c
index 57e8e5f..8757459 100644
--- a/tests/repo/message.c
+++ b/tests/repo/message.c
@@ -4,38 +4,36 @@
#include "posix.h"
static git_repository *_repo;
-static git_buf _path;
-static git_buf _actual;
void test_repo_message__initialize(void)
{
- _repo = cl_git_sandbox_init("testrepo.git");
- git_buf_init(&_actual, 0);
+ _repo = cl_git_sandbox_init("testrepo.git");
}
void test_repo_message__cleanup(void)
{
- cl_git_sandbox_cleanup();
- git_buf_free(&_path);
- git_buf_free(&_actual);
+ cl_git_sandbox_cleanup();
}
void test_repo_message__none(void)
{
- cl_assert_equal_i(GIT_ENOTFOUND, git_repository_message(&_actual, _repo));
+ git_buf actual = GIT_BUF_INIT;
+ cl_assert_equal_i(GIT_ENOTFOUND, git_repository_message(&actual, _repo));
}
void test_repo_message__message(void)
{
+ git_buf path = GIT_BUF_INIT, actual = GIT_BUF_INIT;
const char expected[] = "Test\n\nThis is a test of the emergency broadcast system\n";
- cl_git_pass(git_buf_joinpath(&_path, git_repository_path(_repo), "MERGE_MSG"));
- cl_git_mkfile(git_buf_cstr(&_path), expected);
+ cl_git_pass(git_buf_joinpath(&path, git_repository_path(_repo), "MERGE_MSG"));
+ cl_git_mkfile(git_buf_cstr(&path), expected);
- cl_git_pass(git_repository_message(&_actual, _repo));
- cl_assert_equal_s(expected, _actual);
- git_buf_free(&_actual);
+ cl_git_pass(git_repository_message(&actual, _repo));
+ cl_assert_equal_s(expected, git_buf_cstr(&actual));
+ git_buf_free(&actual);
- cl_git_pass(p_unlink(git_buf_cstr(&_path)));
- cl_assert_equal_i(GIT_ENOTFOUND, git_repository_message(&_actual, _repo));
+ cl_git_pass(p_unlink(git_buf_cstr(&path)));
+ cl_assert_equal_i(GIT_ENOTFOUND, git_repository_message(&actual, _repo));
+ git_buf_free(&path);
}