Merge pull request #1373 from arrbee/why-cdecl-why Why cdecl why?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
diff --git a/src/common.h b/src/common.h
index ca203ee..e3a9e19 100644
--- a/src/common.h
+++ b/src/common.h
@@ -33,14 +33,14 @@
# include "win32/pthread.h"
#endif
-# define snprintf _snprintf
-
#else
-# include <unistd.h>
+# include <unistd.h>
# ifdef GIT_THREADS
# include <pthread.h>
# endif
+#define GIT_STDLIB_CALL
+
#endif
#include "git2/types.h"
diff --git a/src/hashsig.c b/src/hashsig.c
index 60649fd..e9c5164 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 714a85e..50865ed 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 c439dad..4d56299 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;