]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Windows: Silence a spurious warning in the GetAdaptersAddresses cast
authorteor <teor@torproject.org>
Thu, 6 Sep 2018 03:11:23 +0000 (13:11 +1000)
committerteor <teor@torproject.org>
Fri, 7 Sep 2018 01:03:10 +0000 (11:03 +1000)
GetProcAddress() returns FARPROC, which is (long long int(*)()) on
64-bit Windows:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms683212(v=vs.85).aspx

But GetAdaptersAddresses() is (long unsigned int(*)()), on both 32-bit
and 64-bit Windows:
https://docs.microsoft.com/en-us/windows/desktop/api/iphlpapi/nf-iphlpapi-getadaptersaddresses

So gcc 8 issues a spurious "incompatible function pointer" warning
about the cast to GetAdaptersAddresses_fn_t.

Silence this warning by casting to a void function pointer, before
the cast to GetAdaptersAddresses_fn_t.

This issue is already fixed by 26481 in 0.3.5 and later, by removing
the lookup and cast.

Fixes bug 27465; bugfix on 0.2.3.11-alpha.

changes/bug27465 [new file with mode: 0644]
src/common/address.c

diff --git a/changes/bug27465 b/changes/bug27465
new file mode 100644 (file)
index 0000000..743b351
--- /dev/null
@@ -0,0 +1,5 @@
+  o Minor bugfixes (compilation):
+    - Silence a spurious compiler warning on the GetAdaptersAddresses
+      function pointer cast. This issue is already fixed by 26481 in
+      0.3.5 and later, by removing the lookup and cast.
+      Fixes bug 27465; bugfix on 0.2.3.11-alpha.
index 96b99fa0828569a2d0afac10833864b18644cb4c..794345a13899c7922d4d17a56e98fc1a14ca1a4f 100644 (file)
@@ -1492,7 +1492,10 @@ get_interface_addresses_win32(int severity, sa_family_t family)
     goto done;
   }
 
-  if (!(fn = (GetAdaptersAddresses_fn_t)
+  /* Cast through a void function pointer, to silence a spurious compiler
+   * warning on 64-bit Windows. This cast is safe, because we are casting to
+   * the correct type for GetAdaptersAddresses(). */
+  if (!(fn = (GetAdaptersAddresses_fn_t)(void(*)(void))
                   GetProcAddress(lib, "GetAdaptersAddresses"))) {
     log_fn(severity, LD_NET, "Unable to obtain pointer to "
            "GetAdaptersAddresses");