diff --git a/src/common.h b/src/common.h index ca203ee5c..e3a9e1984 100644 --- a/src/common.h +++ b/src/common.h @@ -33,14 +33,14 @@ # include "win32/pthread.h" #endif -# define snprintf _snprintf - #else -# include +# include # ifdef GIT_THREADS # include # endif +#define GIT_STDLIB_CALL + #endif #include "git2/types.h" diff --git a/src/hashsig.c b/src/hashsig.c index 60649fd11..e9c5164a4 100644 --- a/src/hashsig.c +++ b/src/hashsig.c @@ -19,7 +19,7 @@ typedef uint64_t hashsig_state; #define HASHSIG_HEAP_SIZE ((1 << 7) - 1) -typedef int (*hashsig_cmp)(const void *a, const void *b); +typedef int (GIT_STDLIB_CALL *hashsig_cmp)(const void *a, const void *b); typedef struct { int size, asize; @@ -53,13 +53,13 @@ static void hashsig_heap_init(hashsig_heap *h, hashsig_cmp cmp) h->cmp = cmp; } -static int hashsig_cmp_max(const void *a, const void *b) +static int GIT_STDLIB_CALL hashsig_cmp_max(const void *a, const void *b) { hashsig_t av = *(const hashsig_t *)a, bv = *(const hashsig_t *)b; return (av < bv) ? -1 : (av > bv) ? 1 : 0; } -static int hashsig_cmp_min(const void *a, const void *b) +static int GIT_STDLIB_CALL hashsig_cmp_min(const void *a, const void *b) { hashsig_t av = *(const hashsig_t *)a, bv = *(const hashsig_t *)b; return (av > bv) ? -1 : (av < bv) ? 1 : 0; @@ -183,8 +183,8 @@ static void hashsig_initial_window( /* insert initial hash if we just finished */ if (win_len == HASHSIG_HASH_WINDOW) { - hashsig_heap_insert(&sig->mins, state); - hashsig_heap_insert(&sig->maxs, state); + hashsig_heap_insert(&sig->mins, (hashsig_t)state); + hashsig_heap_insert(&sig->maxs, (hashsig_t)state); sig->considered = 1; } @@ -224,8 +224,8 @@ static int hashsig_add_hashes( state = (state * HASHSIG_HASH_SHIFT) & HASHSIG_HASH_MASK; state = (state + ch) & HASHSIG_HASH_MASK; - hashsig_heap_insert(&sig->mins, state); - hashsig_heap_insert(&sig->maxs, state); + hashsig_heap_insert(&sig->mins, (hashsig_t)state); + hashsig_heap_insert(&sig->maxs, (hashsig_t)state); sig->considered++; prog->window[prog->win_pos] = ch; @@ -307,7 +307,7 @@ int git_hashsig_create_fromfile( while (!error) { if ((buflen = p_read(fd, buf, sizeof(buf))) <= 0) { - if ((error = buflen) < 0) + if ((error = (int)buflen) < 0) giterr_set(GITERR_OS, "Read error on '%s' calculating similarity hashes", path); break; diff --git a/src/win32/msvc-compat.h b/src/win32/msvc-compat.h index 714a85e21..50865ed17 100644 --- a/src/win32/msvc-compat.h +++ b/src/win32/msvc-compat.h @@ -37,6 +37,15 @@ /* MSVC doesn't define ssize_t at all */ typedef SSIZE_T ssize_t; +/* define snprintf using variadic macro support if available */ +#if _MSC_VER >= 1400 +# define snprintf(BUF, SZ, FMT, ...) _snprintf_s(BUF, SZ, _TRUNCATE, FMT, __VA_ARGS__) +#else +# define snprintf _snprintf #endif +#endif + +#define GIT_STDLIB_CALL __cdecl + #endif /* INCLUDE_msvc_compat__ */ diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c index c439dadce..4d56299f7 100644 --- a/src/win32/posix_w32.c +++ b/src/win32/posix_w32.c @@ -375,7 +375,8 @@ int p_vsnprintf(char *buffer, size_t count, const char *format, va_list argptr) #ifdef _MSC_VER int len; - if (count == 0 || (len = _vsnprintf(buffer, count, format, argptr)) < 0) + if (count == 0 || + (len = _vsnprintf_s(buffer, count, _TRUNCATE, format, argptr)) < 0) return _vscprintf(format, argptr); return len;