Skip to content

Commit fcaac14

Browse files
committed
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 0ab43ed + 386d372 commit fcaac14

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

compat/compiler.h

Lines changed: 2 additions & 2 deletions
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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ static inline void filetime_to_timespec(const FILETIME *ft, struct timespec *ts)
782782
*/
783783
static int has_valid_directory_prefix(wchar_t *wfilename)
784784
{
785-
int n = wcslen(wfilename);
785+
size_t n = wcslen(wfilename);
786786

787787
while (n > 0) {
788788
wchar_t c = wfilename[--n];
@@ -891,7 +891,7 @@ static int do_lstat(int follow, const char *file_name, struct stat *buf)
891891
*/
892892
static int do_stat_internal(int follow, const char *file_name, struct stat *buf)
893893
{
894-
int namelen;
894+
size_t namelen;
895895
char alt_name[PATH_MAX];
896896

897897
if (!do_lstat(follow, file_name, buf))
@@ -1274,7 +1274,8 @@ static const char *parse_interpreter(const char *cmd)
12741274
{
12751275
static char buf[100];
12761276
char *p, *opt;
1277-
int n, fd;
1277+
ssize_t n; /* read() can return negative values */
1278+
int fd;
12781279

12791280
/* don't even try a .exe */
12801281
n = strlen(cmd);
@@ -1339,7 +1340,7 @@ static char *path_lookup(const char *cmd, int exe_only)
13391340
{
13401341
const char *path;
13411342
char *prog = NULL;
1342-
int len = strlen(cmd);
1343+
size_t len = strlen(cmd);
13431344
int isexe = len >= 4 && !strcasecmp(cmd+len-4, ".exe");
13441345

13451346
if (strpbrk(cmd, "/\\"))
@@ -1956,7 +1957,7 @@ char *mingw_getenv(const char *name)
19561957
#define GETENV_MAX_RETAIN 64
19571958
static char *values[GETENV_MAX_RETAIN];
19581959
static int value_counter;
1959-
int len_key, len_value;
1960+
size_t len_key, len_value;
19601961
wchar_t *w_key;
19611962
char *value;
19621963
wchar_t w_value[32768];
@@ -1968,7 +1969,8 @@ char *mingw_getenv(const char *name)
19681969
/* We cannot use xcalloc() here because that uses getenv() itself */
19691970
w_key = calloc(len_key, sizeof(wchar_t));
19701971
if (!w_key)
1971-
die("Out of memory, (tried to allocate %u wchar_t's)", len_key);
1972+
die("Out of memory, (tried to allocate %"PRIuMAX" wchar_t's)",
1973+
(uintmax_t)len_key);
19721974
xutftowcs(w_key, name, len_key);
19731975
/* GetEnvironmentVariableW() only sets the last error upon failure */
19741976
SetLastError(ERROR_SUCCESS);
@@ -1983,7 +1985,8 @@ char *mingw_getenv(const char *name)
19831985
/* We cannot use xcalloc() here because that uses getenv() itself */
19841986
value = calloc(len_value, sizeof(char));
19851987
if (!value)
1986-
die("Out of memory, (tried to allocate %u bytes)", len_value);
1988+
die("Out of memory, (tried to allocate %"PRIuMAX" bytes)",
1989+
(uintmax_t)len_value);
19871990
xwcstoutf(value, w_value, len_value);
19881991

19891992
/*
@@ -2001,7 +2004,7 @@ char *mingw_getenv(const char *name)
20012004

20022005
int mingw_putenv(const char *namevalue)
20032006
{
2004-
int size;
2007+
size_t size;
20052008
wchar_t *wide, *equal;
20062009
BOOL result;
20072010

@@ -2011,7 +2014,8 @@ int mingw_putenv(const char *namevalue)
20112014
size = strlen(namevalue) * 2 + 1;
20122015
wide = calloc(size, sizeof(wchar_t));
20132016
if (!wide)
2014-
die("Out of memory, (tried to allocate %u wchar_t's)", size);
2017+
die("Out of memory, (tried to allocate %" PRIuMAX " wchar_t's)",
2018+
(uintmax_t)size);
20152019
xutftowcs(wide, namevalue, size);
20162020
equal = wcschr(wide, L'=');
20172021
if (!equal)
@@ -3085,7 +3089,8 @@ static void maybe_redirect_std_handles(void)
30853089
*/
30863090
int wmain(int argc, const wchar_t **wargv)
30873091
{
3088-
int i, maxlen, exit_status;
3092+
int i, exit_status;
3093+
size_t maxlen;
30893094
char *buffer, **save;
30903095
const char **argv;
30913096

compat/vcbuild/include/unistd.h

Lines changed: 4 additions & 0 deletions
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)