Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Ramsay Jones authored and Junio C Hamano committed Apr 28, 2013
1 parent 657b35f commit 84d32bf
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 15 deletions.
4 changes: 2 additions & 2 deletions compat/mingw.h
Expand Up @@ -346,8 +346,8 @@ extern CRITICAL_SECTION pinfo_cs;
*/

#define main(c,v) dummy_decl_mingw_main(); \
static int mingw_main(); \
int main(int argc, const char **argv) \
static int mingw_main(c,v); \
int main(int argc, char **argv) \
{ \
extern CRITICAL_SECTION pinfo_cs; \
_fmode = _O_BINARY; \
Expand Down
4 changes: 2 additions & 2 deletions credential-store.c
Expand Up @@ -114,7 +114,7 @@ static int lookup_credential(const char *fn, struct credential *c)
return c->username && c->password;
}

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

umask(077);

argc = parse_options(argc, argv, NULL, options, usage, 0);
argc = parse_options(argc, (const char **)argv, NULL, options, usage, 0);
if (argc != 1)
usage_with_options(usage, options);
op = argv[0];
Expand Down
4 changes: 2 additions & 2 deletions fast-import.c
Expand Up @@ -297,7 +297,7 @@ static int failure;
static FILE *pack_edges;
static unsigned int show_stats = 1;
static int global_argc;
static const char **global_argv;
static char **global_argv;

/* Memory pools */
static size_t mem_pool_alloc = 2*1024*1024 - sizeof(struct mem_pool);
Expand Down Expand Up @@ -3347,7 +3347,7 @@ static void parse_argv(void)
read_marks();
}

int main(int argc, const char **argv)
int main(int argc, char **argv)
{
unsigned int i;

Expand Down
3 changes: 2 additions & 1 deletion git.c
Expand Up @@ -507,8 +507,9 @@ static int run_argv(int *argcp, const char ***argv)
}


int main(int argc, const char **argv)
int main(int argc, char **av)
{
const char **argv = (const char **) av;
const char *cmd;

startup_info = &git_startup_info;
Expand Down
2 changes: 1 addition & 1 deletion remote-testsvn.c
Expand Up @@ -286,7 +286,7 @@ static int do_command(struct strbuf *line)
return 0;
}

int main(int argc, const char **argv)
int main(int argc, char **argv)
{
struct strbuf buf = STRBUF_INIT, url_sb = STRBUF_INIT,
private_ref_sb = STRBUF_INIT, marksfilename_sb = STRBUF_INIT,
Expand Down
2 changes: 1 addition & 1 deletion test-chmtime.c
Expand Up @@ -56,7 +56,7 @@ static int timespec_arg(const char *arg, long int *set_time, int *set_eq)
return 1;
}

int main(int argc, const char *argv[])
int main(int argc, char *argv[])
{
static int verbose;

Expand Down
2 changes: 1 addition & 1 deletion test-index-version.c
@@ -1,6 +1,6 @@
#include "cache.h"

int main(int argc, const char **argv)
int main(int argc, char **argv)
{
struct cache_header hdr;
int version;
Expand Down
2 changes: 1 addition & 1 deletion test-mergesort.c
Expand Up @@ -22,7 +22,7 @@ static int compare_strings(const void *a, const void *b)
return strcmp(x->text, y->text);
}

int main(int argc, const char **argv)
int main(int argc, char **argv)
{
struct line *line, *p = NULL, *lines = NULL;
struct strbuf sb = STRBUF_INIT;
Expand Down
4 changes: 2 additions & 2 deletions test-parse-options.c
Expand Up @@ -29,7 +29,7 @@ static int number_callback(const struct option *opt, const char *arg, int unset)
return 0;
}

int main(int argc, const char **argv)
int main(int argc, char **argv)
{
const char *prefix = "prefix/";
const char *usage[] = {
Expand Down Expand Up @@ -81,7 +81,7 @@ int main(int argc, const char **argv)
};
int i;

argc = parse_options(argc, argv, prefix, options, usage, 0);
argc = parse_options(argc, (const char **)argv, prefix, options, usage, 0);

printf("boolean: %d\n", boolean);
printf("integer: %u\n", integer);
Expand Down
4 changes: 2 additions & 2 deletions test-subprocess.c
@@ -1,7 +1,7 @@
#include "cache.h"
#include "run-command.h"

int main(int argc, const char **argv)
int main(int argc, char **argv)
{
struct child_process cp;
int nogit = 0;
Expand All @@ -15,6 +15,6 @@ int main(int argc, const char **argv)
}
memset(&cp, 0, sizeof(cp));
cp.git_cmd = 1;
cp.argv = argv + 1;
cp.argv = (const char **)argv + 1;
return run_command(&cp);
}

0 comments on commit 84d32bf

Please sign in to comment.