Fix MSVC compilation warnings
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
diff --git a/src/tsort.c b/src/tsort.c
index eda9a2f..70ed589 100644
--- a/src/tsort.c
+++ b/src/tsort.c
@@ -3,6 +3,9 @@
#include <stdint.h>
#include <stdlib.h>
+#ifndef GIT_WIN32
+#include <common.h>
+#endif
/**
* An array-of-pointers implementation of Python's Timsort
* Based on code by Christopher Swenson under the MIT license
@@ -89,6 +92,8 @@ static int binsearch(void **dst, const void *x, size_t size, cmp_ptr_t cmp)
static void bisort(void **dst, size_t start, size_t size, cmp_ptr_t cmp)
{
size_t i;
+ void *x;
+ int location;
for (i = start; i < size; i++) {
int j;
@@ -97,8 +102,8 @@ static void bisort(void **dst, size_t start, size_t size, cmp_ptr_t cmp)
continue;
/* Else we need to find the right place, shift everything over, and squeeze in */
- void *x = dst[i];
- int location = binsearch(dst, x, i, cmp);
+ x = dst[i];
+ location = binsearch(dst, x, i, cmp);
for (j = i - 1; j >= location; j--) {
dst[j + 1] = dst[j];
}
@@ -323,7 +328,8 @@ static ssize_t collapse(void **dst, struct tsort_run *stack, ssize_t stack_curr,
bisort(&dst[curr], len, run, cmp);\
len = run;\
}\
- run_stack[stack_curr++] = (struct tsort_run) {curr, len};\
+ run_stack[stack_curr].start = curr;\
+ run_stack[stack_curr++].length = len;\
curr += len;\
if (curr == (ssize_t)size) {\
/* finish up */ \
@@ -341,7 +347,6 @@ static ssize_t collapse(void **dst, struct tsort_run *stack, ssize_t stack_curr,
}\
while (0)
-
void git__tsort(void **dst, size_t size, cmp_ptr_t cmp)
{
struct tsort_store _store, *store = &_store;
diff --git a/src/util.h b/src/util.h
index 410ebfb..e649070 100644
--- a/src/util.h
+++ b/src/util.h
@@ -118,7 +118,7 @@ extern int git__fnmatch(const char *pattern, const char *name, int flags);
} \
} while (0)
-extern int git__tsort(void **b, size_t n, int (*cmp)(const void *, const void *));
+extern void git__tsort(void **dst, size_t size, int (*cmp)(const void *, const void *));
extern void **git__bsearch(const void *key, void **base, size_t nmemb,
int (*compar)(const void *, const void *));
diff --git a/tests/t00-core.c b/tests/t00-core.c
index 660f10c..6b20e18 100644
--- a/tests/t00-core.c
+++ b/tests/t00-core.c
@@ -75,7 +75,7 @@ END_TEST
static int test_cmp(const void *a, const void *b)
{
- return a - b;
+ return (int)a - (int)b;
}
BEGIN_TEST(vector2, "remove duplicates")