Skip to content

Commit

Permalink
Merge branch 'rj/sparse'
Browse files Browse the repository at this point in the history
* rj/sparse:
  sparse: Fix mingw_main() argument number/type errors
  compat/mingw.c: Fix some sparse warnings
  compat/win32mmap.c: Fix some sparse warnings
  compat/poll/poll.c: Fix a sparse warning
  compat/win32/pthread.c: Fix a sparse warning
  compat/unsetenv.c: Fix a sparse warning
  compat/nedmalloc: Fix compiler warnings on linux
  compat/nedmalloc: Fix some sparse warnings
  compat/fnmatch/fnmatch.c: Fix a sparse error
  compat/regex/regexec.c: Fix some sparse warnings
  • Loading branch information
Junio C Hamano committed May 29, 2013
2 parents 2f1ef15 + 84d32bf commit 7e2d574
Show file tree
Hide file tree
Showing 20 changed files with 43 additions and 30 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2003,6 +2003,7 @@ endif
ifdef USE_NED_ALLOCATOR
compat/nedmalloc/nedmalloc.sp compat/nedmalloc/nedmalloc.o: EXTRA_CPPFLAGS = \
-DNDEBUG -DOVERRIDE_STRDUP -DREPLACE_SYSTEM_ALLOCATOR
compat/nedmalloc/nedmalloc.sp: SPARSE_FLAGS += -Wno-non-pointer-null
endif

git-%$X: %.o GIT-LDFLAGS $(GITLIBS)
Expand Down
3 changes: 2 additions & 1 deletion compat/fnmatch/fnmatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
# define _GNU_SOURCE 1
#endif

#include <stddef.h>
#include <errno.h>
#include <fnmatch.h>
#include <ctype.h>
Expand Down Expand Up @@ -121,7 +122,7 @@
whose names are inconsistent. */

# if !defined _LIBC && !defined getenv
extern char *getenv ();
extern char *getenv (const char *name);
# endif

# ifndef errno
Expand Down
6 changes: 3 additions & 3 deletions compat/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -841,8 +841,8 @@ struct pinfo_t {
struct pinfo_t *next;
pid_t pid;
HANDLE proc;
} pinfo_t;
struct pinfo_t *pinfo = NULL;
};
static struct pinfo_t *pinfo = NULL;
CRITICAL_SECTION pinfo_cs;

static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
Expand Down Expand Up @@ -1253,7 +1253,7 @@ static int WSAAPI getaddrinfo_stub(const char *node, const char *service,
else
sin->sin_addr.s_addr = INADDR_LOOPBACK;
ai->ai_addr = (struct sockaddr *)sin;
ai->ai_next = 0;
ai->ai_next = NULL;
return 0;
}

Expand Down
11 changes: 9 additions & 2 deletions compat/mingw.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,14 +333,21 @@ void mingw_open_html(const char *path);
char **make_augmented_environ(const char *const *vars);
void free_environ(char **env);

/*
* A critical section used in the implementation of the spawn
* functions (mingw_spawnv[p]e()) and waitpid(). Intialised in
* the replacement main() macro below.
*/
extern CRITICAL_SECTION pinfo_cs;

/*
* A replacement of main() that ensures that argv[0] has a path
* and that default fmode and std(in|out|err) are in binary mode
*/

#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
6 changes: 5 additions & 1 deletion compat/nedmalloc/malloc.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,10 @@ MAX_RELEASE_CHECK_RATE default: 4095 unless not HAVE_MMAP
#define DLMALLOC_VERSION 20804
#endif /* DLMALLOC_VERSION */

#if defined(linux)
#define _GNU_SOURCE 1
#endif

#ifndef WIN32
#ifdef _WIN32
#define WIN32 1
Expand Down Expand Up @@ -1802,7 +1806,7 @@ struct win32_mlock_t

static MLOCK_T malloc_global_mutex = { 0, 0, 0};

static FORCEINLINE long win32_getcurrentthreadid() {
static FORCEINLINE long win32_getcurrentthreadid(void) {
#ifdef _MSC_VER
#if defined(_M_IX86)
long *threadstruct=(long *)__readfsdword(0x18);
Expand Down
4 changes: 2 additions & 2 deletions compat/nedmalloc/nedmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ struct mallinfo nedmallinfo(void) THROWSPEC { return nedpmallinfo(0); }
#endif
int nedmallopt(int parno, int value) THROWSPEC { return nedpmallopt(0, parno, value); }
int nedmalloc_trim(size_t pad) THROWSPEC { return nedpmalloc_trim(0, pad); }
void nedmalloc_stats() THROWSPEC { nedpmalloc_stats(0); }
size_t nedmalloc_footprint() THROWSPEC { return nedpmalloc_footprint(0); }
void nedmalloc_stats(void) THROWSPEC { nedpmalloc_stats(0); }
size_t nedmalloc_footprint(void) THROWSPEC { return nedpmalloc_footprint(0); }
void **nedindependent_calloc(size_t elemsno, size_t elemsize, void **chunks) THROWSPEC { return nedpindependent_calloc(0, elemsno, elemsize, chunks); }
void **nedindependent_comalloc(size_t elems, size_t *sizes, void **chunks) THROWSPEC { return nedpindependent_comalloc(0, elems, sizes, chunks); }

Expand Down
2 changes: 1 addition & 1 deletion compat/poll/poll.c
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout)
{
/* It's a socket. */
WSAEnumNetworkEvents ((SOCKET) h, NULL, &ev);
WSAEventSelect ((SOCKET) h, 0, 0);
WSAEventSelect ((SOCKET) h, NULL, 0);

/* If we're lucky, WSAEnumNetworkEvents already provided a way
to distinguish FD_READ and FD_ACCEPT; this saves a recv later. */
Expand Down
6 changes: 3 additions & 3 deletions compat/regex/regexec.c
Original file line number Diff line number Diff line change
Expand Up @@ -2313,7 +2313,7 @@ transit_state (reg_errcode_t *err, re_match_context_t *mctx,
}

/* Update the state_log if we need */
re_dfastate_t *
static re_dfastate_t *
internal_function
merge_state_with_log (reg_errcode_t *err, re_match_context_t *mctx,
re_dfastate_t *next_state)
Expand All @@ -2326,7 +2326,7 @@ merge_state_with_log (reg_errcode_t *err, re_match_context_t *mctx,
mctx->state_log[cur_idx] = next_state;
mctx->state_log_top = cur_idx;
}
else if (mctx->state_log[cur_idx] == 0)
else if (mctx->state_log[cur_idx] == NULL)
{
mctx->state_log[cur_idx] = next_state;
}
Expand Down Expand Up @@ -2392,7 +2392,7 @@ merge_state_with_log (reg_errcode_t *err, re_match_context_t *mctx,
/* Skip bytes in the input that correspond to part of a
multi-byte match, then look in the log for a state
from which to restart matching. */
re_dfastate_t *
static re_dfastate_t *
internal_function
find_recover_state (reg_errcode_t *err, re_match_context_t *mctx)
{
Expand Down
1 change: 0 additions & 1 deletion compat/unsetenv.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

void gitunsetenv (const char *name)
{
extern char **environ;
int src, dst;
size_t nmln;

Expand Down
2 changes: 1 addition & 1 deletion compat/win32/pthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int win32_pthread_join(pthread_t *thread, void **value_ptr)

pthread_t pthread_self(void)
{
pthread_t t = { 0 };
pthread_t t = { NULL };
t.tid = GetCurrentThreadId();
return t;
}
Expand Down
4 changes: 2 additions & 2 deletions compat/win32mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ void *git_mmap(void *start, size_t length, int prot, int flags, int fd, off_t of
if (!(flags & MAP_PRIVATE))
die("Invalid usage of mmap when built with USE_WIN32_MMAP");

hmap = CreateFileMapping((HANDLE)_get_osfhandle(fd), 0, PAGE_WRITECOPY,
0, 0, 0);
hmap = CreateFileMapping((HANDLE)_get_osfhandle(fd), NULL,
PAGE_WRITECOPY, 0, 0, NULL);

if (!hmap)
return MAP_FAILED;
Expand Down
4 changes: 2 additions & 2 deletions credential-store.c
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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 7e2d574

Please sign in to comment.