[bug #58650] Cast increases required alignment warning in debug output

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[bug #58650] Cast increases required alignment warning in debug output

Ashley Duncan
URL:
  <https://savannah.nongnu.org/bugs/?58650>

                 Summary: Cast increases required alignment warning in debug
output
                 Project: lwIP - A Lightweight TCP/IP stack
            Submitted by: ashesman
            Submitted on: Wed 24 Jun 2020 05:12:42 AM UTC
                Category: DNS
                Severity: 3 - Normal
              Item Group: Compiler Warning
                  Status: None
                 Privacy: Public
             Assigned to: None
             Open/Closed: Open
         Discussion Lock: Any
         Planned Release: None
            lwIP version: 2.1.1

    _______________________________________________________

Details:

On version 2.1.2

A very trivial thing but when enabling DNS_DEBUG, line 132 of netdb.c causes a
cast increases required alignment warning (or error in my case) due to the
cast of a char * to a ip_addr_t *.  Here is a proposed (but untested) fix, it
is not the most efficient, but it is only debug output display.

In this case it can be guaranteed that there is not an alignment issue, so the
cast cannot cause a runtime error.

An alternate may be to cast through a uintptr_t.

Original:

 LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_addr_list[%i]-> == %s\n", idx,
ipaddr_ntoa((ip_addr_t *)s_hostent.h_addr_list[idx])));

Proposed Fix:

      /* memcpy prevents cast increases required alignment warning */
      memcpy(&addr, s_hostent.h_addr_list[idx], sizeof(addr));
      LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_addr_list[%i]-> == %s\n", idx,
ipaddr_ntoa(&addr)));




    _______________________________________________________

Reply to this item at:

  <https://savannah.nongnu.org/bugs/?58650>

_______________________________________________
  Message sent via Savannah
  https://savannah.nongnu.org/


_______________________________________________
lwip-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-devel