From 387d349dc8211e3eb2955cc5e29a85f186af82ce Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sun, 25 Sep 2022 17:11:12 +0300 Subject: [PATCH] Fix compiler warnings in the MS-Windows build. * src/w32/w32os.c (osync_get_mutex, osync_parse_mutex): Cast to DWORD_PTR when converting integers to HANDLEs and vice versa. * src/w32/pathstuff.c (w32ify): Pacify compiler warnings about 'strncpy'. * src/makeint.h (PRId64) [!HAVE_INTTYPES_H]: Define if undefined. * src/function.c (func_wordlist): Use PRId64 instead of %lld. --- src/function.c | 4 ++-- src/makeint.h | 8 ++++++++ src/w32/pathstuff.c | 4 ++-- src/w32/w32os.c | 6 ++++-- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/function.c b/src/function.c index a2fd90a7..ce6e7603 100644 --- a/src/function.c +++ b/src/function.c @@ -825,11 +825,11 @@ func_wordlist (char *o, char **argv, const char *funcname UNUSED) if (start < 1) ON (fatal, *expanding_var, - "invalid first argument to 'wordlist' function: '%lld'", start); + "invalid first argument to 'wordlist' function: '%" PRId64 "'", start); if (stop < 0) ON (fatal, *expanding_var, - "invalid second argument to 'wordlist' function: '%lld'", stop); + "invalid second argument to 'wordlist' function: '%" PRId64 "'", stop); count = stop - start + 1; diff --git a/src/makeint.h b/src/makeint.h index d941ff3d..54b500f3 100644 --- a/src/makeint.h +++ b/src/makeint.h @@ -290,6 +290,14 @@ char *strerror (int errnum); #if HAVE_INTTYPES_H # include +#else +# ifndef PRId64 +# ifdef WINDOWS32 +# define PRId64 "I64d" +# else +# define PRId64 "lld" +# endif +# endif #endif #if HAVE_STDINT_H # include diff --git a/src/w32/pathstuff.c b/src/w32/pathstuff.c index afee0a4a..ae761ae6 100644 --- a/src/w32/pathstuff.c +++ b/src/w32/pathstuff.c @@ -102,11 +102,11 @@ w32ify(const char *filename, int resolve) if (resolve) { char *fp = _fullpath (NULL, filename, sizeof (w32_path)); - strncpy (w32_path, fp, sizeof (w32_path)); + strncpy (w32_path, fp, sizeof (w32_path) - 1); free (fp); } else - strncpy(w32_path, filename, sizeof (w32_path)); + strncpy(w32_path, filename, sizeof (w32_path) - 1); for (p = w32_path; p && *p; p++) if (*p == '\\') diff --git a/src/w32/w32os.c b/src/w32/w32os.c index 528b5b70..23acccb9 100644 --- a/src/w32/w32os.c +++ b/src/w32/w32os.c @@ -22,7 +22,9 @@ this program. If not, see . */ #include #include #include +#if _WIN32_WINNT > 0x0601 #include +#endif #include "pathstuff.h" #include "sub_proc.h" #include "w32err.h" @@ -429,7 +431,7 @@ osync_get_mutex () /* Prepare the mutex handle string for our children. 2 hex digits per byte + 2 characters for "0x" + null. */ mutex = xmalloc ((2 * sizeof (osync_handle)) + 2 + 1); - sprintf (mutex, "0x%Ix", (unsigned long long)osync_handle); + sprintf (mutex, "0x%Ix", (unsigned long long)(DWORD_PTR)osync_handle); } return mutex; @@ -449,7 +451,7 @@ osync_parse_mutex (const char *mutex) if (endp[0] != '\0') OS (fatal, NILF, _("invalid output sync mutex: %s"), mutex); - osync_handle = (HANDLE) i; + osync_handle = (HANDLE) (DWORD_PTR) i; return 1; }