Commit 71a4c1f16ffc71bced673c5883d5ea621cc8d24f

Vicent Martí 2011-09-18T20:07:59

Merge pull request #384 from kiryl/warnings Add more -W flags to CFLAGS

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
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3b32828..61eb799 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -58,7 +58,7 @@ IF (MSVC)
 	SET(CMAKE_C_FLAGS_DEBUG "/Od /DEBUG /MTd")
 	SET(CMAKE_C_FLAGS_RELEASE "/MT /O2")
 ELSE ()
-	SET(CMAKE_C_FLAGS "-O2 -g -Wall -Wextra")
+	SET(CMAKE_C_FLAGS "-O2 -g -Wall -Wextra -Wstrict-aliasing=2 -Wstrict-prototypes -Wmissing-prototypes")
 	IF (NOT MINGW) # MinGW always does PIC and complains if we tell it to
 		SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
 	ENDIF ()
diff --git a/src/cache.c b/src/cache.c
index cb3a4ec..79f3eae 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -58,12 +58,12 @@ void git_cache_free(git_cache *cache)
 
 void *git_cache_get(git_cache *cache, const git_oid *oid)
 {
-	const uint32_t *hash;
+	uint32_t hash;
 	cache_node *node = NULL;
 	void *result = NULL;
 
-	hash = (const uint32_t *)oid->id;
-	node = &cache->nodes[hash[0] & cache->size_mask];
+	memcpy(&hash, oid->id, sizeof(hash));
+	node = &cache->nodes[hash & cache->size_mask];
 
 	git_mutex_lock(&node->lock);
 	{
@@ -79,13 +79,13 @@ void *git_cache_get(git_cache *cache, const git_oid *oid)
 
 void *git_cache_try_store(git_cache *cache, void *entry)
 {
-	const uint32_t *hash;
+	uint32_t hash;
 	const git_oid *oid;
 	cache_node *node = NULL;
 
 	oid = &((git_cached_obj*)entry)->oid;
-	hash = (const uint32_t *)oid->id;
-	node = &cache->nodes[hash[0] & cache->size_mask];
+	memcpy(&hash, oid->id, sizeof(hash));
+	node = &cache->nodes[hash & cache->size_mask];
 
 	/* increase the refcount on this object, because
 	 * the cache now owns it */
diff --git a/src/commit.c b/src/commit.c
index 460057e..0ee3854 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -169,7 +169,7 @@ cleanup:
 	return error;
 }
 
-int commit_parse_buffer(git_commit *commit, const void *data, size_t len)
+int git_commit__parse_buffer(git_commit *commit, const void *data, size_t len)
 {
 	const char *buffer = data;
 	const char *buffer_end = (const char *)data + len;
@@ -236,7 +236,7 @@ int commit_parse_buffer(git_commit *commit, const void *data, size_t len)
 int git_commit__parse(git_commit *commit, git_odb_object *obj)
 {
 	assert(commit);
-	return commit_parse_buffer(commit, obj->raw.data, obj->raw.len);
+	return git_commit__parse_buffer(commit, obj->raw.data, obj->raw.len);
 }
 
 #define GIT_COMMIT_GETTER(_rvalue, _name, _return) \
diff --git a/src/commit.h b/src/commit.h
index 456aa79..bfc4bba 100644
--- a/src/commit.h
+++ b/src/commit.h
@@ -30,4 +30,5 @@ struct git_commit {
 void git_commit__free(git_commit *c);
 int git_commit__parse(git_commit *commit, git_odb_object *obj);
 
+int git_commit__parse_buffer(git_commit *commit, const void *data, size_t len);
 #endif
diff --git a/src/config_file.c b/src/config_file.c
index 3804f97..f76efed 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -553,7 +553,7 @@ static char *cfg_readline(diskfile_backend *cfg)
 /*
  * Consume a line, without storing it anywhere
  */
-void cfg_consume_line(diskfile_backend *cfg)
+static void cfg_consume_line(diskfile_backend *cfg)
 {
 	char *line_start, *line_end;
 
diff --git a/src/mwindow.c b/src/mwindow.c
index 76b80d7..c126fa2 100644
--- a/src/mwindow.c
+++ b/src/mwindow.c
@@ -113,7 +113,7 @@ void git_mwindow_scan_lru(
  * Close the least recently used window. You should check to see if
  * the file descriptors need closing from time to time.
  */
-int git_mwindow_close_lru(git_mwindow_file *mwf)
+static int git_mwindow_close_lru(git_mwindow_file *mwf)
 {
 	unsigned int i;
 	git_mwindow *lru_w = NULL, *lru_l = NULL;
diff --git a/src/odb_loose.c b/src/odb_loose.c
index 59703ce..3ca46d1 100644
--- a/src/odb_loose.c
+++ b/src/odb_loose.c
@@ -463,7 +463,7 @@ static int locate_object(char *object_location, loose_backend *backend, const gi
 }
 
 /* Explore an entry of a directory and see if it matches a short oid */
-int fn_locate_object_short_oid(void *state, char *pathbuf) {
+static int fn_locate_object_short_oid(void *state, char *pathbuf) {
 	loose_locate_object_state *sstate = (loose_locate_object_state *)state;
 
 	size_t pathbuf_len = strlen(pathbuf);
@@ -559,7 +559,7 @@ static int locate_object_short_oid(char *object_location, git_oid *res_oid, loos
  *
  ***********************************************************/
 
-int loose_backend__read_header(size_t *len_p, git_otype *type_p, git_odb_backend *backend, const git_oid *oid)
+static int loose_backend__read_header(size_t *len_p, git_otype *type_p, git_odb_backend *backend, const git_oid *oid)
 {
 	char object_path[GIT_PATH_MAX];
 	git_rawobj raw;
@@ -581,7 +581,7 @@ int loose_backend__read_header(size_t *len_p, git_otype *type_p, git_odb_backend
 	return GIT_SUCCESS;
 }
 
-int loose_backend__read(void **buffer_p, size_t *len_p, git_otype *type_p, git_odb_backend *backend, const git_oid *oid)
+static int loose_backend__read(void **buffer_p, size_t *len_p, git_otype *type_p, git_odb_backend *backend, const git_oid *oid)
 {
 	char object_path[GIT_PATH_MAX];
 	git_rawobj raw;
@@ -602,7 +602,7 @@ int loose_backend__read(void **buffer_p, size_t *len_p, git_otype *type_p, git_o
 	return GIT_SUCCESS;
 }
 
-int loose_backend__read_prefix(
+static int loose_backend__read_prefix(
 	git_oid *out_oid,
 	void **buffer_p,
 	size_t *len_p,
@@ -643,7 +643,7 @@ int loose_backend__read_prefix(
 	return GIT_SUCCESS;
 }
 
-int loose_backend__exists(git_odb_backend *backend, const git_oid *oid)
+static int loose_backend__exists(git_odb_backend *backend, const git_oid *oid)
 {
 	char object_path[GIT_PATH_MAX];
 
@@ -652,7 +652,7 @@ int loose_backend__exists(git_odb_backend *backend, const git_oid *oid)
 	return locate_object(object_path, (loose_backend *)backend, oid) == GIT_SUCCESS;
 }
 
-int loose_backend__stream_fwrite(git_oid *oid, git_odb_stream *_stream)
+static int loose_backend__stream_fwrite(git_oid *oid, git_odb_stream *_stream)
 {
 	loose_writestream *stream = (loose_writestream *)_stream;
 	loose_backend *backend = (loose_backend *)_stream->backend;
@@ -673,13 +673,13 @@ int loose_backend__stream_fwrite(git_oid *oid, git_odb_stream *_stream)
 	return git_filebuf_commit_at(&stream->fbuf, final_path);
 }
 
-int loose_backend__stream_write(git_odb_stream *_stream, const char *data, size_t len)
+static int loose_backend__stream_write(git_odb_stream *_stream, const char *data, size_t len)
 {
 	loose_writestream *stream = (loose_writestream *)_stream;
 	return git_filebuf_write(&stream->fbuf, data, len);
 }
 
-void loose_backend__stream_free(git_odb_stream *_stream)
+static void loose_backend__stream_free(git_odb_stream *_stream)
 {
 	loose_writestream *stream = (loose_writestream *)_stream;
 
@@ -702,7 +702,7 @@ static int format_object_header(char *hdr, size_t n, size_t obj_len, git_otype o
 	return len+1;
 }
 
-int loose_backend__stream(git_odb_stream **stream_out, git_odb_backend *_backend, size_t length, git_otype type)
+static int loose_backend__stream(git_odb_stream **stream_out, git_odb_backend *_backend, size_t length, git_otype type)
 {
 	loose_backend *backend;
 	loose_writestream *stream;
@@ -754,7 +754,7 @@ int loose_backend__stream(git_odb_stream **stream_out, git_odb_backend *_backend
 	return GIT_SUCCESS;
 }
 
-int loose_backend__write(git_oid *oid, git_odb_backend *_backend, const void *data, size_t len, git_otype type)
+static int loose_backend__write(git_oid *oid, git_odb_backend *_backend, const void *data, size_t len, git_otype type)
 {
 	int error, header_len;
 	char final_path[GIT_PATH_MAX], header[64];
@@ -797,7 +797,7 @@ cleanup:
 	return error;
 }
 
-void loose_backend__free(git_odb_backend *_backend)
+static void loose_backend__free(git_odb_backend *_backend)
 {
 	loose_backend *backend;
 	assert(_backend);
diff --git a/src/odb_pack.c b/src/odb_pack.c
index 1867ada..4607fb7 100644
--- a/src/odb_pack.c
+++ b/src/odb_pack.c
@@ -363,7 +363,7 @@ int pack_backend__read_header(git_rawobj *obj, git_odb_backend *backend, const g
 }
 */
 
-int pack_backend__read(void **buffer_p, size_t *len_p, git_otype *type_p, git_odb_backend *backend, const git_oid *oid)
+static int pack_backend__read(void **buffer_p, size_t *len_p, git_otype *type_p, git_odb_backend *backend, const git_oid *oid)
 {
 	struct git_pack_entry e;
 	git_rawobj raw;
@@ -382,7 +382,7 @@ int pack_backend__read(void **buffer_p, size_t *len_p, git_otype *type_p, git_od
 	return GIT_SUCCESS;
 }
 
-int pack_backend__read_prefix(
+static int pack_backend__read_prefix(
 	git_oid *out_oid,
 	void **buffer_p,
 	size_t *len_p,
@@ -421,13 +421,13 @@ int pack_backend__read_prefix(
 	return GIT_SUCCESS;
 }
 
-int pack_backend__exists(git_odb_backend *backend, const git_oid *oid)
+static int pack_backend__exists(git_odb_backend *backend, const git_oid *oid)
 {
 	struct git_pack_entry e;
 	return pack_entry_find(&e, (struct pack_backend *)backend, oid) == GIT_SUCCESS;
 }
 
-void pack_backend__free(git_odb_backend *_backend)
+static void pack_backend__free(git_odb_backend *_backend)
 {
 	struct pack_backend *backend;
 	size_t i;
diff --git a/src/refs.c b/src/refs.c
index 7cfbe55..bc8827b 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -1548,7 +1548,7 @@ int git_reference_foreach(git_repository *repo, unsigned int list_flags, int (*c
 	return git_futils_direach(refs_path, GIT_PATH_MAX, _dirent_loose_listall, &data);
 }
 
-int cb__reflist_add(const char *ref, void *data)
+static int cb__reflist_add(const char *ref, void *data)
 {
 	return git_vector_insert((git_vector *)data, git__strdup(ref));
 }
diff --git a/src/remote.c b/src/remote.c
index ad9dedc..f581b97 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -216,11 +216,6 @@ int git_remote_download(char **filename, git_remote *remote)
 	return git_fetch_download_pack(filename, remote);
 }
 
-git_headarray *git_remote_tips(git_remote *remote)
-{
-	return &remote->refs;
-}
-
 int git_remote_update_tips(struct git_remote *remote)
 {
 	int error = GIT_SUCCESS;
diff --git a/src/repository.c b/src/repository.c
index 15ee67f..bb7ef39 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -156,7 +156,7 @@ static int quickcheck_repository_dir(const char *repository_path)
 	return GIT_SUCCESS;
 }
 
-static git_repository *repository_alloc()
+static git_repository *repository_alloc(void)
 {
 	int error;
 
diff --git a/src/revwalk.c b/src/revwalk.c
index 768e110..72eb69a 100644
--- a/src/revwalk.c
+++ b/src/revwalk.c
@@ -52,7 +52,7 @@ struct git_revwalk {
 	unsigned int sorting;
 };
 
-commit_list *commit_list_insert(commit_object *item, commit_list **list_p)
+static commit_list *commit_list_insert(commit_object *item, commit_list **list_p)
 {
 	commit_list *new_list = git__malloc(sizeof(commit_list));
 	new_list->item = item;
@@ -61,7 +61,7 @@ commit_list *commit_list_insert(commit_object *item, commit_list **list_p)
 	return new_list;
 }
 
-void commit_list_free(commit_list **list_p)
+static void commit_list_free(commit_list **list_p)
 {
 	commit_list *list = *list_p;
 
@@ -74,7 +74,7 @@ void commit_list_free(commit_list **list_p)
 	*list_p = NULL;
 }
 
-commit_object *commit_list_pop(commit_list **stack)
+static commit_object *commit_list_pop(commit_list **stack)
 {
 	commit_list *top = *stack;
 	commit_object *item = top ? top->item : NULL;
diff --git a/src/signature.c b/src/signature.c
index 09915f8..7cc3733 100644
--- a/src/signature.c
+++ b/src/signature.c
@@ -203,7 +203,7 @@ static int parse_timezone_offset(const char *buffer, int *offset_out)
 	return GIT_SUCCESS;
 }
 
-int process_next_token(const char **buffer_out, char **storage,
+static int process_next_token(const char **buffer_out, char **storage,
 	const char *token_end, const char *right_boundary)
 {
 	int error = process_trimming(*buffer_out, storage, token_end, 0);
@@ -218,7 +218,7 @@ int process_next_token(const char **buffer_out, char **storage,
 	return GIT_SUCCESS;
 }
 
-const char *scan_for_previous_token(const char *buffer, const char *left_boundary)
+static const char *scan_for_previous_token(const char *buffer, const char *left_boundary)
 {
 	const char *start;
 
@@ -234,7 +234,7 @@ const char *scan_for_previous_token(const char *buffer, const char *left_boundar
 	return start;
 }
 
-int parse_time(git_time_t *time_out, const char *buffer)
+static int parse_time(git_time_t *time_out, const char *buffer)
 {
 	long time;
 	int error;
diff --git a/src/tree.c b/src/tree.c
index bccc911..ce399a6 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -24,7 +24,7 @@ struct tree_key_search {
 	size_t filename_len;
 };
 
-int entry_search_cmp(const void *key, const void *array_member)
+static int entry_search_cmp(const void *key, const void *array_member)
 {
 	const struct tree_key_search *ksearch = key;
 	const git_tree_entry *entry = array_member;
@@ -37,7 +37,7 @@ int entry_search_cmp(const void *key, const void *array_member)
 	return result ? result : ((int)ksearch->filename_len - (int)entry->filename_len);
 }
 
-int entry_sort_cmp(const void *a, const void *b)
+static int entry_sort_cmp(const void *a, const void *b)
 {
 	const git_tree_entry *entry_a = (const git_tree_entry *)(a);
 	const git_tree_entry *entry_b = (const git_tree_entry *)(b);
@@ -157,6 +157,7 @@ static int tree_parse_buffer(git_tree *tree, const char *buffer, const char *buf
 
 	while (buffer < buffer_end) {
 		git_tree_entry *entry;
+		long tmp;
 
 		entry = git__calloc(1, sizeof(git_tree_entry));
 		if (entry == NULL) {
@@ -167,8 +168,10 @@ static int tree_parse_buffer(git_tree *tree, const char *buffer, const char *buf
 		if (git_vector_insert(&tree->entries, entry) < GIT_SUCCESS)
 			return GIT_ENOMEM;
 
-		if (git__strtol32((long *)&entry->attr, buffer, &buffer, 8) < GIT_SUCCESS)
+		if (git__strtol32(&tmp, buffer, &buffer, 8) < GIT_SUCCESS ||
+			!buffer || tmp > UINT_MAX || tmp < 0)
 			return git__throw(GIT_EOBJCORRUPTED, "Failed to parse tree. Can't parse attributes");
+		entry->attr = tmp;
 
 		if (*buffer++ != ' ') {
 			error = git__throw(GIT_EOBJCORRUPTED, "Failed to parse tree. Object it corrupted");
diff --git a/tests/t00-core.c b/tests/t00-core.c
index 6d63d1c..5d1a7ac 100644
--- a/tests/t00-core.c
+++ b/tests/t00-core.c
@@ -506,7 +506,7 @@ END_TEST
 
 static char *empty_tmp_dir = "test_gitfo_rmdir_recurs_test";
 
-static int setup_empty_tmp_dir()
+static int setup_empty_tmp_dir(void)
 {
 	char path[GIT_PATH_MAX];
 
diff --git a/tests/t04-commit.c b/tests/t04-commit.c
index a8617ed..88c7efd 100644
--- a/tests/t04-commit.c
+++ b/tests/t04-commit.c
@@ -498,9 +498,6 @@ BEGIN_TEST(signature4, "creating a zero character signature")
 END_TEST
 
 
-/* External declaration for testing the buffer parsing method */
-int commit_parse_buffer(git_commit *commit, void *data, size_t len);
-
 BEGIN_TEST(parse2, "parse a whole commit buffer")
 	const int broken_commit_count = sizeof(test_commits_broken) / sizeof(*test_commits_broken);
 	const int working_commit_count = sizeof(test_commits_working) / sizeof(*test_commits_working);
@@ -516,7 +513,7 @@ BEGIN_TEST(parse2, "parse a whole commit buffer")
 		memset(commit, 0x0, sizeof(git_commit));
 		commit->object.repo = repo;
 
-		must_fail(commit_parse_buffer(
+		must_fail(git_commit__parse_buffer(
 					commit,
 					test_commits_broken[i],
 					strlen(test_commits_broken[i]))
@@ -532,7 +529,7 @@ BEGIN_TEST(parse2, "parse a whole commit buffer")
 		memset(commit, 0x0, sizeof(git_commit));
 		commit->object.repo = repo;
 
-		must_pass(commit_parse_buffer(
+		must_pass(git_commit__parse_buffer(
 					commit,
 					test_commits_working[i],
 					strlen(test_commits_working[i]))
@@ -544,7 +541,7 @@ BEGIN_TEST(parse2, "parse a whole commit buffer")
 		memset(commit, 0x0, sizeof(git_commit));
 		commit->object.repo = repo;
 
-		must_pass(commit_parse_buffer(
+		must_pass(git_commit__parse_buffer(
 					commit,
 					test_commits_working[i],
 					strlen(test_commits_working[i]))
diff --git a/tests/t07-hashtable.c b/tests/t07-hashtable.c
index 7313f2c..c0e8522 100644
--- a/tests/t07-hashtable.c
+++ b/tests/t07-hashtable.c
@@ -34,7 +34,7 @@ typedef struct _aux_object {
 	int visited;
 } table_item;
 
-uint32_t hash_func(const void *key, int hash_id)
+static uint32_t hash_func(const void *key, int hash_id)
 {
 	uint32_t r;
 	const git_oid *id = key;
@@ -43,7 +43,7 @@ uint32_t hash_func(const void *key, int hash_id)
 	return r;
 }
 
-int hash_cmpkey(const void *a, const void *b)
+static int hash_cmpkey(const void *a, const void *b)
 {
 	return git_oid_cmp(a, b);
 }
diff --git a/tests/t12-repo.c b/tests/t12-repo.c
index 1d9132c..de921f9 100644
--- a/tests/t12-repo.c
+++ b/tests/t12-repo.c
@@ -34,7 +34,7 @@ typedef struct {
 	int position;
 } fake_backend;
 
-git_odb_backend *new_backend(int position)
+static git_odb_backend *new_backend(int position)
 {
 	fake_backend *b;
 
@@ -47,7 +47,7 @@ git_odb_backend *new_backend(int position)
 	return (git_odb_backend *)b;
 }
 
-int test_backend_sorting(git_odb *odb)
+static int test_backend_sorting(git_odb *odb)
 {
 	unsigned int i;
 
diff --git a/tests/test_lib.h b/tests/test_lib.h
index fc75ed7..9d90e48 100755
--- a/tests/test_lib.h
+++ b/tests/test_lib.h
@@ -13,6 +13,7 @@
 #define SUITE_NAME(SNAME) libgit2_suite_##SNAME
 
 #define BEGIN_SUITE(SNAME) \
+	git_testsuite *libgit2_suite_##SNAME(void);\
 	git_testsuite *libgit2_suite_##SNAME(void) {\
 		git_testsuite *_gitsuite = git_testsuite_new(#SNAME);