Git fork

mingw.c: Fix complier warnings for a 64 bit msvc

Remove some complier warnings from msvc in compat/mingw.c for value
truncation from 64 bit to 32 bit integers.

Compiling compat/mingw.c under a 64 bit version of msvc produces
warnings. An "int" is 32 bit, and ssize_t or size_t should be 64 bit
long. Prepare compat/vcbuild/include/unistd.h to have a 64 bit type
_ssize_t, when _WIN64 is defined and 32 bit otherwise.

Further down in this include file, as before, ssize_t is defined as
_ssize_t, if needed.

Use size_t instead of int for all variables that hold the result of
strlen() or wcslen() (which cannot be negative).

Use ssize_t to hold the return value of read().

Signed-off-by: Sören Krecker <soekkle@freenet.de>
Signed-off-by: Taylor Blau <me@ttaylorr.com>

authored by

Sören Krecker and committed by
Taylor Blau
386d3720 15030f95

+21 -12
+2 -2
compat/compiler.h
··· 9 10 static inline void get_compiler_info(struct strbuf *info) 11 { 12 - int len = info->len; 13 #ifdef __clang__ 14 strbuf_addf(info, "clang: %s\n", __clang_version__); 15 #elif defined(__GNUC__) ··· 27 28 static inline void get_libc_info(struct strbuf *info) 29 { 30 - int len = info->len; 31 32 #ifdef __GLIBC__ 33 strbuf_addf(info, "glibc: %s\n", gnu_get_libc_version());
··· 9 10 static inline void get_compiler_info(struct strbuf *info) 11 { 12 + size_t len = info->len; 13 #ifdef __clang__ 14 strbuf_addf(info, "clang: %s\n", __clang_version__); 15 #elif defined(__GNUC__) ··· 27 28 static inline void get_libc_info(struct strbuf *info) 29 { 30 + size_t len = info->len; 31 32 #ifdef __GLIBC__ 33 strbuf_addf(info, "glibc: %s\n", gnu_get_libc_version());
+15 -10
compat/mingw.c
··· 782 */ 783 static int has_valid_directory_prefix(wchar_t *wfilename) 784 { 785 - int n = wcslen(wfilename); 786 787 while (n > 0) { 788 wchar_t c = wfilename[--n]; ··· 891 */ 892 static int do_stat_internal(int follow, const char *file_name, struct stat *buf) 893 { 894 - int namelen; 895 char alt_name[PATH_MAX]; 896 897 if (!do_lstat(follow, file_name, buf)) ··· 1274 { 1275 static char buf[100]; 1276 char *p, *opt; 1277 - int n, fd; 1278 1279 /* don't even try a .exe */ 1280 n = strlen(cmd); ··· 1339 { 1340 const char *path; 1341 char *prog = NULL; 1342 - int len = strlen(cmd); 1343 int isexe = len >= 4 && !strcasecmp(cmd+len-4, ".exe"); 1344 1345 if (strpbrk(cmd, "/\\")) ··· 1956 #define GETENV_MAX_RETAIN 64 1957 static char *values[GETENV_MAX_RETAIN]; 1958 static int value_counter; 1959 - int len_key, len_value; 1960 wchar_t *w_key; 1961 char *value; 1962 wchar_t w_value[32768]; ··· 1968 /* We cannot use xcalloc() here because that uses getenv() itself */ 1969 w_key = calloc(len_key, sizeof(wchar_t)); 1970 if (!w_key) 1971 - die("Out of memory, (tried to allocate %u wchar_t's)", len_key); 1972 xutftowcs(w_key, name, len_key); 1973 /* GetEnvironmentVariableW() only sets the last error upon failure */ 1974 SetLastError(ERROR_SUCCESS); ··· 1983 /* We cannot use xcalloc() here because that uses getenv() itself */ 1984 value = calloc(len_value, sizeof(char)); 1985 if (!value) 1986 - die("Out of memory, (tried to allocate %u bytes)", len_value); 1987 xwcstoutf(value, w_value, len_value); 1988 1989 /* ··· 2001 2002 int mingw_putenv(const char *namevalue) 2003 { 2004 - int size; 2005 wchar_t *wide, *equal; 2006 BOOL result; 2007 ··· 2011 size = strlen(namevalue) * 2 + 1; 2012 wide = calloc(size, sizeof(wchar_t)); 2013 if (!wide) 2014 - die("Out of memory, (tried to allocate %u wchar_t's)", size); 2015 xutftowcs(wide, namevalue, size); 2016 equal = wcschr(wide, L'='); 2017 if (!equal) ··· 3085 */ 3086 int wmain(int argc, const wchar_t **wargv) 3087 { 3088 - int i, maxlen, exit_status; 3089 char *buffer, **save; 3090 const char **argv; 3091
··· 782 */ 783 static int has_valid_directory_prefix(wchar_t *wfilename) 784 { 785 + size_t n = wcslen(wfilename); 786 787 while (n > 0) { 788 wchar_t c = wfilename[--n]; ··· 891 */ 892 static int do_stat_internal(int follow, const char *file_name, struct stat *buf) 893 { 894 + size_t namelen; 895 char alt_name[PATH_MAX]; 896 897 if (!do_lstat(follow, file_name, buf)) ··· 1274 { 1275 static char buf[100]; 1276 char *p, *opt; 1277 + ssize_t n; /* read() can return negative values */ 1278 + int fd; 1279 1280 /* don't even try a .exe */ 1281 n = strlen(cmd); ··· 1340 { 1341 const char *path; 1342 char *prog = NULL; 1343 + size_t len = strlen(cmd); 1344 int isexe = len >= 4 && !strcasecmp(cmd+len-4, ".exe"); 1345 1346 if (strpbrk(cmd, "/\\")) ··· 1957 #define GETENV_MAX_RETAIN 64 1958 static char *values[GETENV_MAX_RETAIN]; 1959 static int value_counter; 1960 + size_t len_key, len_value; 1961 wchar_t *w_key; 1962 char *value; 1963 wchar_t w_value[32768]; ··· 1969 /* We cannot use xcalloc() here because that uses getenv() itself */ 1970 w_key = calloc(len_key, sizeof(wchar_t)); 1971 if (!w_key) 1972 + die("Out of memory, (tried to allocate %"PRIuMAX" wchar_t's)", 1973 + (uintmax_t)len_key); 1974 xutftowcs(w_key, name, len_key); 1975 /* GetEnvironmentVariableW() only sets the last error upon failure */ 1976 SetLastError(ERROR_SUCCESS); ··· 1985 /* We cannot use xcalloc() here because that uses getenv() itself */ 1986 value = calloc(len_value, sizeof(char)); 1987 if (!value) 1988 + die("Out of memory, (tried to allocate %"PRIuMAX" bytes)", 1989 + (uintmax_t)len_value); 1990 xwcstoutf(value, w_value, len_value); 1991 1992 /* ··· 2004 2005 int mingw_putenv(const char *namevalue) 2006 { 2007 + size_t size; 2008 wchar_t *wide, *equal; 2009 BOOL result; 2010 ··· 2014 size = strlen(namevalue) * 2 + 1; 2015 wide = calloc(size, sizeof(wchar_t)); 2016 if (!wide) 2017 + die("Out of memory, (tried to allocate %" PRIuMAX " wchar_t's)", 2018 + (uintmax_t)size); 2019 xutftowcs(wide, namevalue, size); 2020 equal = wcschr(wide, L'='); 2021 if (!equal) ··· 3089 */ 3090 int wmain(int argc, const wchar_t **wargv) 3091 { 3092 + int i, exit_status; 3093 + size_t maxlen; 3094 char *buffer, **save; 3095 const char **argv; 3096
+4
compat/vcbuild/include/unistd.h
··· 14 15 #ifndef _SSIZE_T_ 16 #define _SSIZE_T_ 17 typedef long _ssize_t; 18 19 #ifndef _OFF_T_ 20 #define _OFF_T_
··· 14 15 #ifndef _SSIZE_T_ 16 #define _SSIZE_T_ 17 + #ifdef _WIN64 18 + typedef __int64 _ssize_t; 19 + #else 20 typedef long _ssize_t; 21 + #endif /* _WIN64 */ 22 23 #ifndef _OFF_T_ 24 #define _OFF_T_