]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
tuklib_physmem: Silence warning from -Wcast-function-type on MinGW-w64.
authorJia Tan <jiat0218@gmail.com>
Thu, 19 Jan 2023 12:35:09 +0000 (20:35 +0800)
committerJia Tan <jiat0218@gmail.com>
Thu, 19 Jan 2023 12:35:09 +0000 (20:35 +0800)
tuklib_physmem depends on GetProcAddress() for both MSVC and MinGW-w64
to retrieve a function address. The proper way to do this is to cast the
return value to the type of function pointer retrieved. Unfortunately,
this causes a cast-function-type warning, so the best solution is to
simply ignore the warning.

src/common/tuklib_physmem.c

index a1bccb2f67530bf1d28655515996df493971e25d..73d37c29876415f00234052727888a21f5cd1202 100644 (file)
@@ -87,8 +87,17 @@ tuklib_physmem(void)
                HMODULE kernel32 = GetModuleHandle(TEXT("kernel32.dll"));
                if (kernel32 != NULL) {
                        typedef BOOL (WINAPI *gmse_type)(LPMEMORYSTATUSEX);
+#if TUKLIB_GNUC_REQ(8,1) || (defined(__clang__) \
+               && __has_warning("-Wcast-function-type"))
+#      pragma GCC diagnostic push
+#      pragma GCC diagnostic ignored "-Wcast-function-type"
+#endif
                        gmse_type gmse = (gmse_type)GetProcAddress(
                                        kernel32, "GlobalMemoryStatusEx");
+#if TUKLIB_GNUC_REQ(8,1) || (defined(__clang__) \
+               && __has_warning("-Wcast-function-type"))
+#      pragma GCC diagnostic pop
+#endif
                        if (gmse != NULL) {
                                MEMORYSTATUSEX meminfo;
                                meminfo.dwLength = sizeof(meminfo);