Skip to content

Commit 948f00b

Browse files
committed
Merge pull request libgit2#1933 from libgit2/vmg/gcc-warnings
Warnings for Windows x64 (MSVC) and GCC on Linux
2 parents ac5e507 + d3ed210 commit 948f00b

File tree

14 files changed

+62
-29
lines changed

14 files changed

+62
-29
lines changed

src/array.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ GIT_INLINE(void *) git_array_grow(void *_a, size_t item_size)
5757
}
5858

5959
#define git_array_alloc(a) \
60-
((a).size >= (a).asize) ? \
60+
(((a).size >= (a).asize) ? \
6161
git_array_grow(&(a), sizeof(*(a).ptr)) : \
62-
((a).ptr ? &(a).ptr[(a).size++] : NULL)
62+
((a).ptr ? &(a).ptr[(a).size++] : NULL))
6363

6464
#define git_array_last(a) ((a).size ? &(a).ptr[(a).size - 1] : NULL)
6565

src/checkout.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1694,7 +1694,6 @@ static int checkout_write_merge(
16941694

16951695
static int checkout_create_conflicts(checkout_data *data)
16961696
{
1697-
git_vector conflicts = GIT_VECTOR_INIT;
16981697
checkout_conflictdata *conflict;
16991698
size_t i;
17001699
int error = 0;

src/indexer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ static int inject_object(git_indexer *idx, git_oid *id)
660660
/* And then the compressed object */
661661
git_filebuf_write(&idx->pack_file, buf.ptr, buf.size);
662662
idx->pack->mwf.size += buf.size;
663-
entry->crc = htonl(crc32(entry->crc, (unsigned char *)buf.ptr, buf.size));
663+
entry->crc = htonl(crc32(entry->crc, (unsigned char *)buf.ptr, (uInt)buf.size));
664664
git_buf_free(&buf);
665665

666666
/* Write a fake trailer so the pack functions play ball */

src/pack-objects.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ struct unpacked {
2626
git_pobject *object;
2727
void *data;
2828
struct git_delta_index *index;
29-
unsigned int depth;
29+
int depth;
3030
};
3131

3232
struct tree_walk_context {
@@ -659,7 +659,7 @@ static int delta_cacheable(git_packbuilder *pb, unsigned long src_size,
659659
}
660660

661661
static int try_delta(git_packbuilder *pb, struct unpacked *trg,
662-
struct unpacked *src, unsigned int max_depth,
662+
struct unpacked *src, int max_depth,
663663
unsigned long *mem_usage, int *ret)
664664
{
665665
git_pobject *trg_object = trg->object;

src/pack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ static unsigned char *pack_window_open(
372372
* - each byte afterwards: low seven bits are size continuation,
373373
* with the high bit being "size continues"
374374
*/
375-
int git_packfile__object_header(unsigned char *hdr, unsigned long size, git_otype type)
375+
size_t git_packfile__object_header(unsigned char *hdr, size_t size, git_otype type)
376376
{
377377
unsigned char *hdr_base;
378378
unsigned char c;
@@ -392,7 +392,7 @@ int git_packfile__object_header(unsigned char *hdr, unsigned long size, git_otyp
392392
}
393393
*hdr++ = c;
394394

395-
return (int)(hdr - hdr_base);
395+
return (hdr - hdr_base);
396396
}
397397

398398

src/pack.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ typedef struct git_packfile_stream {
112112
git_mwindow *mw;
113113
} git_packfile_stream;
114114

115-
int git_packfile__object_header(unsigned char *hdr, unsigned long size, git_otype type);
115+
size_t git_packfile__object_header(unsigned char *hdr, size_t size, git_otype type);
116116

117117
int git_packfile_unpack_header(
118118
size_t *size_p,

src/path.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,12 @@ int git_path_direach(
834834
DIR *dir;
835835
path_dirent_data de_data;
836836
struct dirent *de, *de_buf = (struct dirent *)&de_data;
837+
838+
(void)flags;
839+
840+
#ifdef GIT_USE_ICONV
837841
git_path_iconv_t ic = GIT_PATH_ICONV_INIT;
842+
#endif
838843

839844
if (git_path_to_dir(path) < 0)
840845
return -1;
@@ -846,8 +851,10 @@ int git_path_direach(
846851
return -1;
847852
}
848853

854+
#ifdef GIT_USE_ICONV
849855
if ((flags & GIT_PATH_DIR_PRECOMPOSE_UNICODE) != 0)
850856
(void)git_path_iconv_init_precompose(&ic);
857+
#endif
851858

852859
while (p_readdir_r(dir, de_buf, &de) == 0 && de != NULL) {
853860
char *de_path = de->d_name;
@@ -856,8 +863,12 @@ int git_path_direach(
856863
if (git_path_is_dot_or_dotdot(de_path))
857864
continue;
858865

859-
if ((error = git_path_iconv(&ic, &de_path, &de_len)) < 0 ||
860-
(error = git_buf_put(path, de_path, de_len)) < 0)
866+
#ifdef GIT_USE_ICONV
867+
if ((error = git_path_iconv(&ic, &de_path, &de_len)) < 0)
868+
break;
869+
#endif
870+
871+
if ((error = git_buf_put(path, de_path, de_len)) < 0)
861872
break;
862873

863874
error = fn(arg, path);
@@ -871,7 +882,10 @@ int git_path_direach(
871882
}
872883

873884
closedir(dir);
885+
886+
#ifdef GIT_USE_ICONV
874887
git_path_iconv_clear(&ic);
888+
#endif
875889

876890
return error;
877891
}
@@ -888,7 +902,12 @@ int git_path_dirload(
888902
size_t path_len;
889903
path_dirent_data de_data;
890904
struct dirent *de, *de_buf = (struct dirent *)&de_data;
905+
906+
(void)flags;
907+
908+
#ifdef GIT_USE_ICONV
891909
git_path_iconv_t ic = GIT_PATH_ICONV_INIT;
910+
#endif
892911

893912
assert(path && contents);
894913

@@ -903,8 +922,10 @@ int git_path_dirload(
903922
return -1;
904923
}
905924

925+
#ifdef GIT_USE_ICONV
906926
if ((flags & GIT_PATH_DIR_PRECOMPOSE_UNICODE) != 0)
907927
(void)git_path_iconv_init_precompose(&ic);
928+
#endif
908929

909930
path += prefix_len;
910931
path_len -= prefix_len;
@@ -917,8 +938,10 @@ int git_path_dirload(
917938
if (git_path_is_dot_or_dotdot(de_path))
918939
continue;
919940

941+
#ifdef GIT_USE_ICONV
920942
if ((error = git_path_iconv(&ic, &de_path, &de_len)) < 0)
921943
break;
944+
#endif
922945

923946
alloc_size = path_len + need_slash + de_len + 1 + alloc_extra;
924947
if ((entry_path = git__calloc(alloc_size, 1)) == NULL) {
@@ -937,7 +960,10 @@ int git_path_dirload(
937960
}
938961

939962
closedir(dir);
963+
964+
#ifdef GIT_USE_ICONV
940965
git_path_iconv_clear(&ic);
966+
#endif
941967

942968
if (error != 0)
943969
giterr_set(GITERR_OS, "Failed to process directory entry in '%s'", path);

src/path.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -425,16 +425,6 @@ extern void git_path_iconv_clear(git_path_iconv_t *ic);
425425
*/
426426
extern int git_path_iconv(git_path_iconv_t *ic, char **in, size_t *inlen);
427427

428-
#else
429-
430-
typedef struct {
431-
int unused;
432-
} git_path_iconv_t;
433-
#define GIT_PATH_ICONV_INIT { 0 }
434-
#define git_path_iconv_init_precompose(X) 0
435-
#define git_path_iconv_clear(X) (void)(X)
436-
#define git_path_iconv(X,Y,Z) 0
437-
438428
#endif /* GIT_USE_ICONV */
439429

440430
#endif

src/refs.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,10 @@ int git_reference__normalize_name(
737737
int segment_len, segments_count = 0, error = GIT_EINVALIDSPEC;
738738
unsigned int process_flags;
739739
bool normalize = (buf != NULL);
740+
741+
#ifdef GIT_USE_ICONV
740742
git_path_iconv_t ic = GIT_PATH_ICONV_INIT;
743+
#endif
741744

742745
assert(name);
743746

@@ -750,13 +753,15 @@ int git_reference__normalize_name(
750753
if (normalize)
751754
git_buf_clear(buf);
752755

756+
#ifdef GIT_USE_ICONV
753757
if ((flags & GIT_REF_FORMAT__PRECOMPOSE_UNICODE) != 0) {
754758
size_t namelen = strlen(current);
755759
if ((error = git_path_iconv_init_precompose(&ic)) < 0 ||
756760
(error = git_path_iconv(&ic, &current, &namelen)) < 0)
757761
goto cleanup;
758762
error = GIT_EINVALIDSPEC;
759763
}
764+
#endif
760765

761766
while (true) {
762767
segment_len = ensure_segment_validity(current);
@@ -834,7 +839,9 @@ int git_reference__normalize_name(
834839
if (error && normalize)
835840
git_buf_free(buf);
836841

842+
#ifdef GIT_USE_ICONV
837843
git_path_iconv_clear(&ic);
844+
#endif
838845

839846
return error;
840847
}

tests-clar/checkout/conflict.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,9 @@ static void collect_progress(
10711071
{
10721072
git_vector *paths = payload;
10731073

1074+
(void)completed_steps;
1075+
(void)total_steps;
1076+
10741077
if (path == NULL)
10751078
return;
10761079

tests-clar/core/iconv.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
#include "clar_libgit2.h"
22
#include "path.h"
33

4+
#ifdef GIT_USE_ICONV
45
static git_path_iconv_t ic;
56
static char *nfc = "\xC3\x85\x73\x74\x72\xC3\xB6\x6D";
67
static char *nfd = "\x41\xCC\x8A\x73\x74\x72\x6F\xCC\x88\x6D";
8+
#endif
79

810
void test_core_iconv__initialize(void)
911
{
12+
#ifdef GIT_USE_ICONV
1013
cl_git_pass(git_path_iconv_init_precompose(&ic));
14+
#endif
1115
}
1216

1317
void test_core_iconv__cleanup(void)
1418
{
19+
#ifdef GIT_USE_ICONV
1520
git_path_iconv_clear(&ic);
21+
#endif
1622
}
1723

1824
void test_core_iconv__unchanged(void)
1925
{
26+
#ifdef GIT_USE_ICONV
2027
char *data = "Ascii data", *original = data;
2128
size_t datalen = strlen(data);
2229

@@ -25,10 +32,12 @@ void test_core_iconv__unchanged(void)
2532

2633
/* There are no high bits set, so this should leave data untouched */
2734
cl_assert(data == original);
35+
#endif
2836
}
2937

3038
void test_core_iconv__decomposed_to_precomposed(void)
3139
{
40+
#ifdef GIT_USE_ICONV
3241
char *data = nfd;
3342
size_t datalen = strlen(nfd);
3443

@@ -38,15 +47,13 @@ void test_core_iconv__decomposed_to_precomposed(void)
3847
/* The decomposed nfd string should be transformed to the nfc form
3948
* (on platforms where iconv is enabled, of course).
4049
*/
41-
#ifdef GIT_USE_ICONV
4250
cl_assert_equal_s(nfc, data);
43-
#else
44-
cl_assert_equal_s(nfd, data);
4551
#endif
4652
}
4753

4854
void test_core_iconv__precomposed_is_unmodified(void)
4955
{
56+
#ifdef GIT_USE_ICONV
5057
char *data = nfc;
5158
size_t datalen = strlen(nfc);
5259

@@ -57,4 +64,5 @@ void test_core_iconv__precomposed_is_unmodified(void)
5764
* the high-bit set, the iconv transform should result in no change.
5865
*/
5966
cl_assert_equal_s(nfc, data);
67+
#endif
6068
}

tests-clar/pack/indexer.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,13 @@ void test_pack_indexer__fix_thin(void)
100100
unsigned char buffer[128];
101101
int fd;
102102
ssize_t read;
103-
git_off_t left;
104103
struct stat st;
105104
const char *name = "pack-11f0f69b334728fdd8bc86b80499f22f29d85b15.pack";
106105

107106
fd = p_open(name, O_RDONLY);
108107
cl_assert(fd != -1);
109108

110109
cl_git_pass(p_stat(name, &st));
111-
left = st.st_size;
112110

113111
cl_git_pass(git_indexer_new(&idx, ".", NULL, NULL, NULL));
114112
read = p_read(fd, buffer, sizeof(buffer));

tests-clar/repo/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ void test_repo_init__detect_ignorecase(void)
232232

233233
void test_repo_init__detect_precompose_unicode_required(void)
234234
{
235+
#ifdef GIT_USE_ICONV
235236
char *composed = "ḱṷṓn", *decomposed = "ḱṷṓn";
236237
struct stat st;
237238
bool found_with_nfd;
@@ -240,7 +241,6 @@ void test_repo_init__detect_precompose_unicode_required(void)
240241
found_with_nfd = (p_stat(decomposed, &st) == 0);
241242
cl_must_pass(p_unlink(composed));
242243

243-
#ifdef GIT_USE_ICONV
244244
assert_config_entry_on_init("core.precomposeunicode", found_with_nfd);
245245
#else
246246
assert_config_entry_on_init("core.precomposeunicode", GIT_ENOTFOUND);

tests-clar/threads/refdb.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,16 @@ static void *delete_refs(void *arg)
147147
void test_threads_refdb__edit_while_iterate(void)
148148
{
149149
int r, t;
150-
git_thread th[THREADS];
151150
int id[THREADS];
152151
git_oid head;
153152
git_reference *ref;
154153
char name[128];
155154
git_refdb *refdb;
156155

156+
#ifdef GIT_THREADS
157+
git_thread th[THREADS];
158+
#endif
159+
157160
g_repo = cl_git_sandbox_init("testrepo2");
158161

159162
cl_git_pass(git_reference_name_to_id(&head, g_repo, "HEAD"));
@@ -187,7 +190,6 @@ void test_threads_refdb__edit_while_iterate(void)
187190
#ifdef GIT_THREADS
188191
cl_git_pass(git_thread_create(&th[t], NULL, fn, &id[t]));
189192
#else
190-
th[t] = t;
191193
fn(&id[t]);
192194
#endif
193195
}

0 commit comments

Comments
 (0)