Merge pull request #1933 from libgit2/vmg/gcc-warnings Warnings for Windows x64 (MSVC) and GCC on Linux
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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414
diff --git a/src/array.h b/src/array.h
index d7272d7..1d4e1c2 100644
--- a/src/array.h
+++ b/src/array.h
@@ -57,9 +57,9 @@ GIT_INLINE(void *) git_array_grow(void *_a, size_t item_size)
}
#define git_array_alloc(a) \
- ((a).size >= (a).asize) ? \
+ (((a).size >= (a).asize) ? \
git_array_grow(&(a), sizeof(*(a).ptr)) : \
- ((a).ptr ? &(a).ptr[(a).size++] : NULL)
+ ((a).ptr ? &(a).ptr[(a).size++] : NULL))
#define git_array_last(a) ((a).size ? &(a).ptr[(a).size - 1] : NULL)
diff --git a/src/checkout.c b/src/checkout.c
index 6628037..76edc6a 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -1694,7 +1694,6 @@ done:
static int checkout_create_conflicts(checkout_data *data)
{
- git_vector conflicts = GIT_VECTOR_INIT;
checkout_conflictdata *conflict;
size_t i;
int error = 0;
diff --git a/src/indexer.c b/src/indexer.c
index 07d0073..0873c8c 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -660,7 +660,7 @@ static int inject_object(git_indexer *idx, git_oid *id)
/* And then the compressed object */
git_filebuf_write(&idx->pack_file, buf.ptr, buf.size);
idx->pack->mwf.size += buf.size;
- entry->crc = htonl(crc32(entry->crc, (unsigned char *)buf.ptr, buf.size));
+ entry->crc = htonl(crc32(entry->crc, (unsigned char *)buf.ptr, (uInt)buf.size));
git_buf_free(&buf);
/* Write a fake trailer so the pack functions play ball */
diff --git a/src/pack-objects.c b/src/pack-objects.c
index 2d0f564..9ea7c65 100644
--- a/src/pack-objects.c
+++ b/src/pack-objects.c
@@ -26,7 +26,7 @@ struct unpacked {
git_pobject *object;
void *data;
struct git_delta_index *index;
- unsigned int depth;
+ int depth;
};
struct tree_walk_context {
@@ -659,7 +659,7 @@ static int delta_cacheable(git_packbuilder *pb, unsigned long src_size,
}
static int try_delta(git_packbuilder *pb, struct unpacked *trg,
- struct unpacked *src, unsigned int max_depth,
+ struct unpacked *src, int max_depth,
unsigned long *mem_usage, int *ret)
{
git_pobject *trg_object = trg->object;
diff --git a/src/pack.c b/src/pack.c
index 5df0f50..644b2d4 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -372,7 +372,7 @@ static unsigned char *pack_window_open(
* - each byte afterwards: low seven bits are size continuation,
* with the high bit being "size continues"
*/
-int git_packfile__object_header(unsigned char *hdr, unsigned long size, git_otype type)
+size_t git_packfile__object_header(unsigned char *hdr, size_t size, git_otype type)
{
unsigned char *hdr_base;
unsigned char c;
@@ -392,7 +392,7 @@ int git_packfile__object_header(unsigned char *hdr, unsigned long size, git_otyp
}
*hdr++ = c;
- return (int)(hdr - hdr_base);
+ return (hdr - hdr_base);
}
diff --git a/src/pack.h b/src/pack.h
index ddeefea..28146ab 100644
--- a/src/pack.h
+++ b/src/pack.h
@@ -112,7 +112,7 @@ typedef struct git_packfile_stream {
git_mwindow *mw;
} git_packfile_stream;
-int git_packfile__object_header(unsigned char *hdr, unsigned long size, git_otype type);
+size_t git_packfile__object_header(unsigned char *hdr, size_t size, git_otype type);
int git_packfile_unpack_header(
size_t *size_p,
diff --git a/src/path.c b/src/path.c
index d45751c..750dd3e 100644
--- a/src/path.c
+++ b/src/path.c
@@ -834,7 +834,12 @@ int git_path_direach(
DIR *dir;
path_dirent_data de_data;
struct dirent *de, *de_buf = (struct dirent *)&de_data;
+
+ (void)flags;
+
+#ifdef GIT_USE_ICONV
git_path_iconv_t ic = GIT_PATH_ICONV_INIT;
+#endif
if (git_path_to_dir(path) < 0)
return -1;
@@ -846,8 +851,10 @@ int git_path_direach(
return -1;
}
+#ifdef GIT_USE_ICONV
if ((flags & GIT_PATH_DIR_PRECOMPOSE_UNICODE) != 0)
(void)git_path_iconv_init_precompose(&ic);
+#endif
while (p_readdir_r(dir, de_buf, &de) == 0 && de != NULL) {
char *de_path = de->d_name;
@@ -856,8 +863,12 @@ int git_path_direach(
if (git_path_is_dot_or_dotdot(de_path))
continue;
- if ((error = git_path_iconv(&ic, &de_path, &de_len)) < 0 ||
- (error = git_buf_put(path, de_path, de_len)) < 0)
+#ifdef GIT_USE_ICONV
+ if ((error = git_path_iconv(&ic, &de_path, &de_len)) < 0)
+ break;
+#endif
+
+ if ((error = git_buf_put(path, de_path, de_len)) < 0)
break;
error = fn(arg, path);
@@ -871,7 +882,10 @@ int git_path_direach(
}
closedir(dir);
+
+#ifdef GIT_USE_ICONV
git_path_iconv_clear(&ic);
+#endif
return error;
}
@@ -888,7 +902,12 @@ int git_path_dirload(
size_t path_len;
path_dirent_data de_data;
struct dirent *de, *de_buf = (struct dirent *)&de_data;
+
+ (void)flags;
+
+#ifdef GIT_USE_ICONV
git_path_iconv_t ic = GIT_PATH_ICONV_INIT;
+#endif
assert(path && contents);
@@ -903,8 +922,10 @@ int git_path_dirload(
return -1;
}
+#ifdef GIT_USE_ICONV
if ((flags & GIT_PATH_DIR_PRECOMPOSE_UNICODE) != 0)
(void)git_path_iconv_init_precompose(&ic);
+#endif
path += prefix_len;
path_len -= prefix_len;
@@ -917,8 +938,10 @@ int git_path_dirload(
if (git_path_is_dot_or_dotdot(de_path))
continue;
+#ifdef GIT_USE_ICONV
if ((error = git_path_iconv(&ic, &de_path, &de_len)) < 0)
break;
+#endif
alloc_size = path_len + need_slash + de_len + 1 + alloc_extra;
if ((entry_path = git__calloc(alloc_size, 1)) == NULL) {
@@ -937,7 +960,10 @@ int git_path_dirload(
}
closedir(dir);
+
+#ifdef GIT_USE_ICONV
git_path_iconv_clear(&ic);
+#endif
if (error != 0)
giterr_set(GITERR_OS, "Failed to process directory entry in '%s'", path);
diff --git a/src/path.h b/src/path.h
index 17f4f77..3daafd2 100644
--- a/src/path.h
+++ b/src/path.h
@@ -425,16 +425,6 @@ extern void git_path_iconv_clear(git_path_iconv_t *ic);
*/
extern int git_path_iconv(git_path_iconv_t *ic, char **in, size_t *inlen);
-#else
-
-typedef struct {
- int unused;
-} git_path_iconv_t;
-#define GIT_PATH_ICONV_INIT { 0 }
-#define git_path_iconv_init_precompose(X) 0
-#define git_path_iconv_clear(X) (void)(X)
-#define git_path_iconv(X,Y,Z) 0
-
#endif /* GIT_USE_ICONV */
#endif
diff --git a/src/refs.c b/src/refs.c
index 269c5f5..472a798 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -737,7 +737,10 @@ int git_reference__normalize_name(
int segment_len, segments_count = 0, error = GIT_EINVALIDSPEC;
unsigned int process_flags;
bool normalize = (buf != NULL);
+
+#ifdef GIT_USE_ICONV
git_path_iconv_t ic = GIT_PATH_ICONV_INIT;
+#endif
assert(name);
@@ -750,6 +753,7 @@ int git_reference__normalize_name(
if (normalize)
git_buf_clear(buf);
+#ifdef GIT_USE_ICONV
if ((flags & GIT_REF_FORMAT__PRECOMPOSE_UNICODE) != 0) {
size_t namelen = strlen(current);
if ((error = git_path_iconv_init_precompose(&ic)) < 0 ||
@@ -757,6 +761,7 @@ int git_reference__normalize_name(
goto cleanup;
error = GIT_EINVALIDSPEC;
}
+#endif
while (true) {
segment_len = ensure_segment_validity(current);
@@ -834,7 +839,9 @@ cleanup:
if (error && normalize)
git_buf_free(buf);
+#ifdef GIT_USE_ICONV
git_path_iconv_clear(&ic);
+#endif
return error;
}
diff --git a/tests-clar/checkout/conflict.c b/tests-clar/checkout/conflict.c
index d261f38..66965a8 100644
--- a/tests-clar/checkout/conflict.c
+++ b/tests-clar/checkout/conflict.c
@@ -1071,6 +1071,9 @@ static void collect_progress(
{
git_vector *paths = payload;
+ (void)completed_steps;
+ (void)total_steps;
+
if (path == NULL)
return;
diff --git a/tests-clar/core/iconv.c b/tests-clar/core/iconv.c
index 73bc99a..8aedab2 100644
--- a/tests-clar/core/iconv.c
+++ b/tests-clar/core/iconv.c
@@ -1,22 +1,29 @@
#include "clar_libgit2.h"
#include "path.h"
+#ifdef GIT_USE_ICONV
static git_path_iconv_t ic;
static char *nfc = "\xC3\x85\x73\x74\x72\xC3\xB6\x6D";
static char *nfd = "\x41\xCC\x8A\x73\x74\x72\x6F\xCC\x88\x6D";
+#endif
void test_core_iconv__initialize(void)
{
+#ifdef GIT_USE_ICONV
cl_git_pass(git_path_iconv_init_precompose(&ic));
+#endif
}
void test_core_iconv__cleanup(void)
{
+#ifdef GIT_USE_ICONV
git_path_iconv_clear(&ic);
+#endif
}
void test_core_iconv__unchanged(void)
{
+#ifdef GIT_USE_ICONV
char *data = "Ascii data", *original = data;
size_t datalen = strlen(data);
@@ -25,10 +32,12 @@ void test_core_iconv__unchanged(void)
/* There are no high bits set, so this should leave data untouched */
cl_assert(data == original);
+#endif
}
void test_core_iconv__decomposed_to_precomposed(void)
{
+#ifdef GIT_USE_ICONV
char *data = nfd;
size_t datalen = strlen(nfd);
@@ -38,15 +47,13 @@ void test_core_iconv__decomposed_to_precomposed(void)
/* The decomposed nfd string should be transformed to the nfc form
* (on platforms where iconv is enabled, of course).
*/
-#ifdef GIT_USE_ICONV
cl_assert_equal_s(nfc, data);
-#else
- cl_assert_equal_s(nfd, data);
#endif
}
void test_core_iconv__precomposed_is_unmodified(void)
{
+#ifdef GIT_USE_ICONV
char *data = nfc;
size_t datalen = strlen(nfc);
@@ -57,4 +64,5 @@ void test_core_iconv__precomposed_is_unmodified(void)
* the high-bit set, the iconv transform should result in no change.
*/
cl_assert_equal_s(nfc, data);
+#endif
}
diff --git a/tests-clar/pack/indexer.c b/tests-clar/pack/indexer.c
index e26b3ec..d795330 100644
--- a/tests-clar/pack/indexer.c
+++ b/tests-clar/pack/indexer.c
@@ -100,7 +100,6 @@ void test_pack_indexer__fix_thin(void)
unsigned char buffer[128];
int fd;
ssize_t read;
- git_off_t left;
struct stat st;
const char *name = "pack-11f0f69b334728fdd8bc86b80499f22f29d85b15.pack";
@@ -108,7 +107,6 @@ void test_pack_indexer__fix_thin(void)
cl_assert(fd != -1);
cl_git_pass(p_stat(name, &st));
- left = st.st_size;
cl_git_pass(git_indexer_new(&idx, ".", NULL, NULL, NULL));
read = p_read(fd, buffer, sizeof(buffer));
diff --git a/tests-clar/repo/init.c b/tests-clar/repo/init.c
index 617fdf8..aea383c 100644
--- a/tests-clar/repo/init.c
+++ b/tests-clar/repo/init.c
@@ -232,6 +232,7 @@ void test_repo_init__detect_ignorecase(void)
void test_repo_init__detect_precompose_unicode_required(void)
{
+#ifdef GIT_USE_ICONV
char *composed = "ḱṷṓn", *decomposed = "ḱṷṓn";
struct stat st;
bool found_with_nfd;
@@ -240,7 +241,6 @@ void test_repo_init__detect_precompose_unicode_required(void)
found_with_nfd = (p_stat(decomposed, &st) == 0);
cl_must_pass(p_unlink(composed));
-#ifdef GIT_USE_ICONV
assert_config_entry_on_init("core.precomposeunicode", found_with_nfd);
#else
assert_config_entry_on_init("core.precomposeunicode", GIT_ENOTFOUND);
diff --git a/tests-clar/threads/refdb.c b/tests-clar/threads/refdb.c
index f8d76cb..3c651e3 100644
--- a/tests-clar/threads/refdb.c
+++ b/tests-clar/threads/refdb.c
@@ -147,13 +147,16 @@ static void *delete_refs(void *arg)
void test_threads_refdb__edit_while_iterate(void)
{
int r, t;
- git_thread th[THREADS];
int id[THREADS];
git_oid head;
git_reference *ref;
char name[128];
git_refdb *refdb;
+#ifdef GIT_THREADS
+ git_thread th[THREADS];
+#endif
+
g_repo = cl_git_sandbox_init("testrepo2");
cl_git_pass(git_reference_name_to_id(&head, g_repo, "HEAD"));
@@ -187,7 +190,6 @@ void test_threads_refdb__edit_while_iterate(void)
#ifdef GIT_THREADS
cl_git_pass(git_thread_create(&th[t], NULL, fn, &id[t]));
#else
- th[t] = t;
fn(&id[t]);
#endif
}