Skip to content

Commit 9aff9d5

Browse files
ttaylorrdscho
authored andcommitted
Merge branch 'sk/msvc-warnings'
Fixes compile time warnings with 64-bit MSVC. * sk/msvc-warnings: mingw.c: Fix complier warnings for a 64 bit msvc
2 parents 531b803 + ac0b0e8 commit 9aff9d5

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

compat/compiler.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
static inline void get_compiler_info(struct strbuf *info)
1111
{
12-
int len = info->len;
12+
size_t len = info->len;
1313
#ifdef __clang__
1414
strbuf_addf(info, "clang: %s\n", __clang_version__);
1515
#elif defined(__GNUC__)
@@ -27,7 +27,7 @@ static inline void get_compiler_info(struct strbuf *info)
2727

2828
static inline void get_libc_info(struct strbuf *info)
2929
{
30-
int len = info->len;
30+
size_t len = info->len;
3131

3232
#ifdef __GLIBC__
3333
strbuf_addf(info, "glibc: %s\n", gnu_get_libc_version());

compat/mingw.c

+14-9
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ static inline void filetime_to_timespec(const FILETIME *ft, struct timespec *ts)
813813
*/
814814
static int has_valid_directory_prefix(wchar_t *wfilename)
815815
{
816-
int n = wcslen(wfilename);
816+
size_t n = wcslen(wfilename);
817817

818818
while (n > 0) {
819819
wchar_t c = wfilename[--n];
@@ -1390,7 +1390,8 @@ static const char *parse_interpreter(const char *cmd)
13901390
{
13911391
static char buf[MAX_PATH];
13921392
char *p, *opt;
1393-
int n, fd;
1393+
ssize_t n; /* read() can return negative values */
1394+
int fd;
13941395

13951396
/* don't even try a .exe */
13961397
n = strlen(cmd);
@@ -1455,7 +1456,7 @@ static char *path_lookup(const char *cmd, int exe_only)
14551456
{
14561457
const char *path;
14571458
char *prog = NULL;
1458-
int len = strlen(cmd);
1459+
size_t len = strlen(cmd);
14591460
int isexe = len >= 4 && !strcasecmp(cmd+len-4, ".exe");
14601461

14611462
if (strpbrk(cmd, "/\\"))
@@ -2072,7 +2073,7 @@ char *mingw_getenv(const char *name)
20722073
#define GETENV_MAX_RETAIN 64
20732074
static char *values[GETENV_MAX_RETAIN];
20742075
static int value_counter;
2075-
int len_key, len_value;
2076+
size_t len_key, len_value;
20762077
wchar_t *w_key;
20772078
char *value;
20782079
wchar_t w_value[32768];
@@ -2084,7 +2085,8 @@ char *mingw_getenv(const char *name)
20842085
/* We cannot use xcalloc() here because that uses getenv() itself */
20852086
w_key = calloc(len_key, sizeof(wchar_t));
20862087
if (!w_key)
2087-
die("Out of memory, (tried to allocate %u wchar_t's)", len_key);
2088+
die("Out of memory, (tried to allocate %"PRIuMAX" wchar_t's)",
2089+
(uintmax_t)len_key);
20882090
xutftowcs(w_key, name, len_key);
20892091
/* GetEnvironmentVariableW() only sets the last error upon failure */
20902092
SetLastError(ERROR_SUCCESS);
@@ -2099,7 +2101,8 @@ char *mingw_getenv(const char *name)
20992101
/* We cannot use xcalloc() here because that uses getenv() itself */
21002102
value = calloc(len_value, sizeof(char));
21012103
if (!value)
2102-
die("Out of memory, (tried to allocate %u bytes)", len_value);
2104+
die("Out of memory, (tried to allocate %"PRIuMAX" bytes)",
2105+
(uintmax_t)len_value);
21032106
xwcstoutf(value, w_value, len_value);
21042107

21052108
/*
@@ -2117,7 +2120,7 @@ char *mingw_getenv(const char *name)
21172120

21182121
int mingw_putenv(const char *namevalue)
21192122
{
2120-
int size;
2123+
size_t size;
21212124
wchar_t *wide, *equal;
21222125
BOOL result;
21232126

@@ -2127,7 +2130,8 @@ int mingw_putenv(const char *namevalue)
21272130
size = strlen(namevalue) * 2 + 1;
21282131
wide = calloc(size, sizeof(wchar_t));
21292132
if (!wide)
2130-
die("Out of memory, (tried to allocate %u wchar_t's)", size);
2133+
die("Out of memory, (tried to allocate %" PRIuMAX " wchar_t's)",
2134+
(uintmax_t)size);
21312135
xutftowcs(wide, namevalue, size);
21322136
equal = wcschr(wide, L'=');
21332137
if (!equal)
@@ -3454,7 +3458,8 @@ static void maybe_redirect_std_handles(void)
34543458
*/
34553459
int wmain(int argc, const wchar_t **wargv)
34563460
{
3457-
int i, maxlen, exit_status;
3461+
int i, exit_status;
3462+
size_t maxlen;
34583463
char *buffer, **save;
34593464
const char **argv;
34603465

compat/vcbuild/include/unistd.h

+4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ typedef _mode_t mode_t;
1414

1515
#ifndef _SSIZE_T_
1616
#define _SSIZE_T_
17+
#ifdef _WIN64
18+
typedef __int64 _ssize_t;
19+
#else
1720
typedef long _ssize_t;
21+
#endif /* _WIN64 */
1822

1923
#ifndef _OFF_T_
2024
#define _OFF_T_

0 commit comments

Comments
 (0)