sparse: Fix mingw_main() argument number/type errors

Sparse issues 68 errors (two errors for each main() function) such as the following: SP git.c git.c:510:5: error: too many arguments for function mingw_main git.c:510:5: error: symbol 'mingw_main' redeclared with different type \ (originally declared at git.c:510) - different argument counts The errors are caused by the 'main' macro used by the MinGW build to provide a replacement main() function. The original main function is effectively renamed to 'mingw_main' and is called from the new main function. The replacement main is used to execute certain actions common to all git programs on MinGW (e.g. ensure the standard I/O streams are in binary mode). In order to suppress the errors, we change the macro to include the parameters in the declaration of the mingw_main function. Unfortunately, this change provokes both sparse and gcc to complain about 9 calls to mingw_main(), such as the following: CC git.o git.c: In function 'main': git.c:510: warning: passing argument 2 of 'mingw_main' from \ incompatible pointer type git.c:510: note: expected 'const char **' but argument is of \ type 'char **' In order to suppress these warnings, since both of the main functions need to be declared with the same prototype, we change the declaration of the 9 main functions, thus: int main(int argc, char **argv) Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ramsay Jones committed Apr 27, 2013 at 20:19 UTC 84d32bf7678259c08406571cd6ce4b7a6724dcba
10 files changed +16 -15
compat/mingw.h
+2 -2
@@ -346,8 +346,8 @@ extern CRITICAL_SECTION pinfo_cs;
346 */
347
348 #define main(c,v) dummy_decl_mingw_main(); \
349 -static int mingw_main(); \
350 -int main(int argc, const char **argv) \
349 +static int mingw_main(c,v); \
350 +int main(int argc, char **argv) \
351 { \
352 extern CRITICAL_SECTION pinfo_cs; \
353 _fmode = _O_BINARY; \
credential-store.c
+2 -2
@@ -114,7 +114,7 @@ static int lookup_credential(const char *fn, struct credential *c)
114 return c->username && c->password;
115 }
116
117 -int main(int argc, const char **argv)
117 +int main(int argc, char **argv)
118 {
119 const char * const usage[] = {
120 "git credential-store [options] <action>",
@@ -131,7 +131,7 @@ int main(int argc, const char **argv)
131
132 umask(077);
133
134 - argc = parse_options(argc, argv, NULL, options, usage, 0);
134 + argc = parse_options(argc, (const char **)argv, NULL, options, usage, 0);
135 if (argc != 1)
136 usage_with_options(usage, options);
137 op = argv[0];
fast-import.c
+2 -2
@@ -297,7 +297,7 @@ static int failure;
297 static FILE *pack_edges;
298 static unsigned int show_stats = 1;
299 static int global_argc;
300 -static const char **global_argv;
300 +static char **global_argv;
301
302 /* Memory pools */
303 static size_t mem_pool_alloc = 2*1024*1024 - sizeof(struct mem_pool);
@@ -3347,7 +3347,7 @@ static void parse_argv(void)
3347 read_marks();
3348 }
3349
3350 -int main(int argc, const char **argv)
3350 +int main(int argc, char **argv)
3351 {
3352 unsigned int i;
3353
git.c
+2 -1
@@ -507,8 +507,9 @@ static int run_argv(int *argcp, const char ***argv)
507 }
508
509
510 -int main(int argc, const char **argv)
510 +int main(int argc, char **av)
511 {
512 + const char **argv = (const char **) av;
513 const char *cmd;
514
515 startup_info = &git_startup_info;
remote-testsvn.c
+1 -1
@@ -286,7 +286,7 @@ static int do_command(struct strbuf *line)
286 return 0;
287 }
288
289 -int main(int argc, const char **argv)
289 +int main(int argc, char **argv)
290 {
291 struct strbuf buf = STRBUF_INIT, url_sb = STRBUF_INIT,
292 private_ref_sb = STRBUF_INIT, marksfilename_sb = STRBUF_INIT,
test-chmtime.c
+1 -1
@@ -56,7 +56,7 @@ static int timespec_arg(const char *arg, long int *set_time, int *set_eq)
56 return 1;
57 }
58
59 -int main(int argc, const char *argv[])
59 +int main(int argc, char *argv[])
60 {
61 static int verbose;
62
test-index-version.c
+1 -1
@@ -1,6 +1,6 @@
1 #include "cache.h"
2
3 -int main(int argc, const char **argv)
3 +int main(int argc, char **argv)
4 {
5 struct cache_header hdr;
6 int version;
test-mergesort.c
+1 -1
@@ -22,7 +22,7 @@ static int compare_strings(const void *a, const void *b)
22 return strcmp(x->text, y->text);
23 }
24
25 -int main(int argc, const char **argv)
25 +int main(int argc, char **argv)
26 {
27 struct line *line, *p = NULL, *lines = NULL;
28 struct strbuf sb = STRBUF_INIT;
test-parse-options.c
+2 -2
@@ -29,7 +29,7 @@ static int number_callback(const struct option *opt, const char *arg, int unset)
29 return 0;
30 }
31
32 -int main(int argc, const char **argv)
32 +int main(int argc, char **argv)
33 {
34 const char *prefix = "prefix/";
35 const char *usage[] = {
@@ -81,7 +81,7 @@ int main(int argc, const char **argv)
81 };
82 int i;
83
84 - argc = parse_options(argc, argv, prefix, options, usage, 0);
84 + argc = parse_options(argc, (const char **)argv, prefix, options, usage, 0);
85
86 printf("boolean: %d\n", boolean);
87 printf("integer: %u\n", integer);
test-subprocess.c
+2 -2
@@ -1,7 +1,7 @@
1 #include "cache.h"
2 #include "run-command.h"
3
4 -int main(int argc, const char **argv)
4 +int main(int argc, char **argv)
5 {
6 struct child_process cp;
7 int nogit = 0;
@@ -15,6 +15,6 @@ int main(int argc, const char **argv)
15 }
16 memset(&cp, 0, sizeof(cp));
17 cp.git_cmd = 1;
18 - cp.argv = argv + 1;
18 + cp.argv = (const char **)argv + 1;
19 return run_command(&cp);
20 }