windows: fix DWORD format string complaints
authorSitsofe Wheeler <sitsofe@yahoo.com>
Wed, 19 Aug 2020 22:58:35 +0000 (23:58 +0100)
committerSitsofe Wheeler <sitsofe@yahoo.com>
Sat, 12 Sep 2020 10:50:35 +0000 (11:50 +0100)
Printing DWORD variables causes Windows clang to grumble about types:

os/windows/cpu-affinity.c:263:5: error: format specifies type 'int' but the argument has type 'DWORD' (aka 'unsigned long') [-Werror,-Wformat]
                         GetLastError());
                         ^~~~~~~~~~~~~~

Since a DWORD is defined to be an unsigned 32 bit integer and is
declared to be an unsigned long
(https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-dtyp/262627d8-3418-4627-9218-4ffe110850b2
) just use long as the format specifier. When printing the cpu mask in
hex on legacy Windows builds, cast to unsigned long long which should be
safe because there won't be more than 64 CPUs with old versions of
Windows.

(As some format strings are longer than the wrapping width, make an
exception and avoid splitting/preserve them to make greping easier)

Suggested-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Sitsofe Wheeler <sitsofe@yahoo.com>
engines/windowsaio.c
os/windows/cpu-affinity.c
os/windows/posix.c

index 5c7e79643aaf35978d62919455c235fbb3f41260..9868e816adb68b8e196dc42d1832b8869e36fec3 100644 (file)
@@ -161,15 +161,15 @@ static int windowsaio_invalidate_cache(struct fio_file *f)
        if (ihFile != INVALID_HANDLE_VALUE) {
                if (!CloseHandle(ihFile)) {
                        error = GetLastError();
-                       log_info("windowsaio: invalidation fd close %s "
-                                "failed: error %d\n", f->file_name, error);
+                       log_info("windowsaio: invalidation fd close %s failed: error %lu\n",
+                                f->file_name, error);
                        rc = 1;
                }
        } else {
                error = GetLastError();
                if (error != ERROR_FILE_NOT_FOUND) {
-                       log_info("windowsaio: cache invalidation of %s failed: "
-                                       "error %d\n", f->file_name, error);
+                       log_info("windowsaio: cache invalidation of %s failed: error %lu\n",
+                                f->file_name, error);
                        rc = 1;
                }
        }
index 4ac32ed16c805d4c4f6d215391f0ab2986f5ee38..46fd048d3abc26180cff0d5bc66edeb436fd157e 100644 (file)
@@ -14,7 +14,7 @@ int fio_setaffinity(int pid, os_cpu_mask_t cpumask)
                bSuccess = SetThreadAffinityMask(h, cpumask);
                if (!bSuccess)
                        log_err("fio_setaffinity failed: failed to set thread affinity (pid %d, mask %.16llx)\n",
-                               pid, cpumask);
+                               pid, (long long unsigned) cpumask);
 
                CloseHandle(h);
        } else {
@@ -261,10 +261,8 @@ int fio_setaffinity(int pid, os_cpu_mask_t cpumask)
        if (SetThreadGroupAffinity(handle, &new_group_affinity, NULL) != 0)
                ret = 0;
        else {
-               log_err("fio_setaffinity: failed to set thread affinity "
-                        "(pid %d, group %d, mask %" PRIx64 ", "
-                        "GetLastError=%d)\n", pid, group, group_mask,
-                        GetLastError());
+               log_err("fio_setaffinity: failed to set thread affinity (pid %d, group %d, mask %" PRIx64 ", GetLastError=%lu)\n",
+                       pid, group, group_mask, GetLastError());
                goto err;
        }
 
@@ -323,7 +321,7 @@ int fio_getaffinity(int pid, os_cpu_mask_t *mask)
                goto err;
        }
        if (!GetProcessGroupAffinity(handle, &group_count, current_groups)) {
-               log_err("%s: failed to get single group affinity for pid %d (%d)\n",
+               log_err("%s: failed to get single group affinity for pid %d (%lu)\n",
                        __func__, pid, GetLastError());
                goto err;
        }
index 31271de049133b8728c26f47f6d4e34a13208cc6..9e9f12effbea9aaf738d159b4211ab617b3d2450 100644 (file)
@@ -168,7 +168,7 @@ int win_to_posix_error(DWORD winerr)
        case ERROR_FILE_INVALID:
                return ENXIO;
        default:
-               log_err("fio: windows error %d not handled\n", winerr);
+               log_err("fio: windows error %lu not handled\n", winerr);
                return EIO;
        }
 
@@ -188,7 +188,8 @@ int GetNumLogicalProcessors(void)
                if (error == ERROR_INSUFFICIENT_BUFFER)
                        processor_info = malloc(len);
                else {
-                       log_err("Error: GetLogicalProcessorInformation failed: %d\n", error);
+                       log_err("Error: GetLogicalProcessorInformation failed: %lu\n",
+                               error);
                        return -1;
                }