Skip to content

Commit a306a68

Browse files
ttaylorrdscho
authored andcommitted
Merge branch 'sk/msvc-warnings' into next
Fixes compile time warnings with 64-bit MSVC. * sk/msvc-warnings: mingw.c: Fix complier warnings for a 64 bit msvc
2 parents cfc349e + a7a3cea commit a306a68

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
@@ -1049,7 +1049,7 @@ int mingw_chmod(const char *filename, int mode)
10491049
*/
10501050
static int has_valid_directory_prefix(wchar_t *wfilename)
10511051
{
1052-
int n = wcslen(wfilename);
1052+
size_t n = wcslen(wfilename);
10531053

10541054
while (n > 0) {
10551055
wchar_t c = wfilename[--n];
@@ -1628,7 +1628,8 @@ static const char *parse_interpreter(const char *cmd)
16281628
{
16291629
static char buf[MAX_PATH];
16301630
char *p, *opt;
1631-
int n, fd;
1631+
ssize_t n; /* read() can return negative values */
1632+
int fd;
16321633

16331634
/* don't even try a .exe */
16341635
n = strlen(cmd);
@@ -1752,7 +1753,7 @@ static char *path_lookup(const char *cmd, int exe_only)
17521753
{
17531754
const char *path;
17541755
char *prog = NULL;
1755-
int len = strlen(cmd);
1756+
size_t len = strlen(cmd);
17561757
int isexe = len >= 4 && !strcasecmp(cmd+len-4, ".exe");
17571758

17581759
if (strpbrk(cmd, "/\\"))
@@ -2389,7 +2390,7 @@ char *mingw_getenv(const char *name)
23892390
#define GETENV_MAX_RETAIN 64
23902391
static char *values[GETENV_MAX_RETAIN];
23912392
static int value_counter;
2392-
int len_key, len_value;
2393+
size_t len_key, len_value;
23932394
wchar_t *w_key;
23942395
char *value;
23952396
wchar_t w_value[32768];
@@ -2401,7 +2402,8 @@ char *mingw_getenv(const char *name)
24012402
/* We cannot use xcalloc() here because that uses getenv() itself */
24022403
w_key = calloc(len_key, sizeof(wchar_t));
24032404
if (!w_key)
2404-
die("Out of memory, (tried to allocate %u wchar_t's)", len_key);
2405+
die("Out of memory, (tried to allocate %"PRIuMAX" wchar_t's)",
2406+
(uintmax_t)len_key);
24052407
xutftowcs(w_key, name, len_key);
24062408
/* GetEnvironmentVariableW() only sets the last error upon failure */
24072409
SetLastError(ERROR_SUCCESS);
@@ -2416,7 +2418,8 @@ char *mingw_getenv(const char *name)
24162418
/* We cannot use xcalloc() here because that uses getenv() itself */
24172419
value = calloc(len_value, sizeof(char));
24182420
if (!value)
2419-
die("Out of memory, (tried to allocate %u bytes)", len_value);
2421+
die("Out of memory, (tried to allocate %"PRIuMAX" bytes)",
2422+
(uintmax_t)len_value);
24202423
xwcstoutf(value, w_value, len_value);
24212424

24222425
/*
@@ -2434,7 +2437,7 @@ char *mingw_getenv(const char *name)
24342437

24352438
int mingw_putenv(const char *namevalue)
24362439
{
2437-
int size;
2440+
size_t size;
24382441
wchar_t *wide, *equal;
24392442
BOOL result;
24402443

@@ -2444,7 +2447,8 @@ int mingw_putenv(const char *namevalue)
24442447
size = strlen(namevalue) * 2 + 1;
24452448
wide = calloc(size, sizeof(wchar_t));
24462449
if (!wide)
2447-
die("Out of memory, (tried to allocate %u wchar_t's)", size);
2450+
die("Out of memory, (tried to allocate %" PRIuMAX " wchar_t's)",
2451+
(uintmax_t)size);
24482452
xutftowcs(wide, namevalue, size);
24492453
equal = wcschr(wide, L'=');
24502454
if (!equal)
@@ -4072,7 +4076,8 @@ static BOOL WINAPI handle_ctrl_c(DWORD ctrl_type)
40724076
*/
40734077
int wmain(int argc, const wchar_t **wargv)
40744078
{
4075-
int i, maxlen, exit_status;
4079+
int i, exit_status;
4080+
size_t maxlen;
40764081
char *buffer, **save;
40774082
const char **argv;
40784083

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)