[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/release-0.3.4] Windows: Silence a spurious warning in the GetAdaptersAddresses cast



commit 1570f17f97ad99ddf3f63745ab3571c1aa411141
Author: teor <teor@xxxxxxxxxxxxxx>
Date:   Thu Sep 6 13:11:23 2018 +1000

    Windows: Silence a spurious warning in the GetAdaptersAddresses cast
    
    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     | 5 +++++
 src/common/address.c | 5 ++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/changes/bug27465 b/changes/bug27465
new file mode 100644
index 000000000..743b35130
--- /dev/null
+++ b/changes/bug27465
@@ -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.
diff --git a/src/common/address.c b/src/common/address.c
index 96b99fa08..794345a13 100644
--- a/src/common/address.c
+++ b/src/common/address.c
@@ -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");



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits