Skip to content

Commit 84d32bf

Browse files
Ramsay Jonesgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 657b35f commit 84d32bf

File tree

10 files changed

+16
-15
lines changed

10 files changed

+16
-15
lines changed

compat/mingw.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,8 @@ extern CRITICAL_SECTION pinfo_cs;
346346
*/
347347

348348
#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) \
351351
{ \
352352
extern CRITICAL_SECTION pinfo_cs; \
353353
_fmode = _O_BINARY; \

credential-store.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ static int lookup_credential(const char *fn, struct credential *c)
114114
return c->username && c->password;
115115
}
116116

117-
int main(int argc, const char **argv)
117+
int main(int argc, char **argv)
118118
{
119119
const char * const usage[] = {
120120
"git credential-store [options] <action>",
@@ -131,7 +131,7 @@ int main(int argc, const char **argv)
131131

132132
umask(077);
133133

134-
argc = parse_options(argc, argv, NULL, options, usage, 0);
134+
argc = parse_options(argc, (const char **)argv, NULL, options, usage, 0);
135135
if (argc != 1)
136136
usage_with_options(usage, options);
137137
op = argv[0];

fast-import.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ static int failure;
297297
static FILE *pack_edges;
298298
static unsigned int show_stats = 1;
299299
static int global_argc;
300-
static const char **global_argv;
300+
static char **global_argv;
301301

302302
/* Memory pools */
303303
static size_t mem_pool_alloc = 2*1024*1024 - sizeof(struct mem_pool);
@@ -3347,7 +3347,7 @@ static void parse_argv(void)
33473347
read_marks();
33483348
}
33493349

3350-
int main(int argc, const char **argv)
3350+
int main(int argc, char **argv)
33513351
{
33523352
unsigned int i;
33533353

git.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,9 @@ static int run_argv(int *argcp, const char ***argv)
507507
}
508508

509509

510-
int main(int argc, const char **argv)
510+
int main(int argc, char **av)
511511
{
512+
const char **argv = (const char **) av;
512513
const char *cmd;
513514

514515
startup_info = &git_startup_info;

remote-testsvn.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ static int do_command(struct strbuf *line)
286286
return 0;
287287
}
288288

289-
int main(int argc, const char **argv)
289+
int main(int argc, char **argv)
290290
{
291291
struct strbuf buf = STRBUF_INIT, url_sb = STRBUF_INIT,
292292
private_ref_sb = STRBUF_INIT, marksfilename_sb = STRBUF_INIT,

test-chmtime.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static int timespec_arg(const char *arg, long int *set_time, int *set_eq)
5656
return 1;
5757
}
5858

59-
int main(int argc, const char *argv[])
59+
int main(int argc, char *argv[])
6060
{
6161
static int verbose;
6262

test-index-version.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "cache.h"
22

3-
int main(int argc, const char **argv)
3+
int main(int argc, char **argv)
44
{
55
struct cache_header hdr;
66
int version;

test-mergesort.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static int compare_strings(const void *a, const void *b)
2222
return strcmp(x->text, y->text);
2323
}
2424

25-
int main(int argc, const char **argv)
25+
int main(int argc, char **argv)
2626
{
2727
struct line *line, *p = NULL, *lines = NULL;
2828
struct strbuf sb = STRBUF_INIT;

test-parse-options.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static int number_callback(const struct option *opt, const char *arg, int unset)
2929
return 0;
3030
}
3131

32-
int main(int argc, const char **argv)
32+
int main(int argc, char **argv)
3333
{
3434
const char *prefix = "prefix/";
3535
const char *usage[] = {
@@ -81,7 +81,7 @@ int main(int argc, const char **argv)
8181
};
8282
int i;
8383

84-
argc = parse_options(argc, argv, prefix, options, usage, 0);
84+
argc = parse_options(argc, (const char **)argv, prefix, options, usage, 0);
8585

8686
printf("boolean: %d\n", boolean);
8787
printf("integer: %u\n", integer);

test-subprocess.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "cache.h"
22
#include "run-command.h"
33

4-
int main(int argc, const char **argv)
4+
int main(int argc, char **argv)
55
{
66
struct child_process cp;
77
int nogit = 0;
@@ -15,6 +15,6 @@ int main(int argc, const char **argv)
1515
}
1616
memset(&cp, 0, sizeof(cp));
1717
cp.git_cmd = 1;
18-
cp.argv = argv + 1;
18+
cp.argv = (const char **)argv + 1;
1919
return run_command(&cp);
2020
}

0 commit comments

Comments
 (0)