lwip-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-devel] [bug #27352] Change ip_addr from struct to typedef (u32_t)


From: David Empson
Subject: [lwip-devel] [bug #27352] Change ip_addr from struct to typedef (u32_t)
Date: Sun, 16 May 2010 23:04:47 +0000
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3

Follow-up Comment #47, bug #27352 (project lwip):

In this cast:

u8_t *a = &some_u8t;
u32_t b = (u32_t)a; <<-- compiler warns

why would the compiler warn you about converting a pointer to an integer?

Did you actually mean this:

u32_t *b = (u32_t *)a;

I'd expect a warning there, because some_u8t could be at any address, which
may not be aligned to a 32-bit boundary. The compiler doesn't know whether it
can access *b because it might not be aligned.

If you typecast via a void pointer, as in:

u32_t *c = (u32_t *)(void *)a;

the warning is defeated but the same problem applies - c may be pointing to
an unaligned object. You've just hidden a potential bug. This doesn't produce
a warning because the compiler expects you to know what you are doing when you
use (void *) to hide the details of a pointer type.

The lack of warning when creating a pointer to a 32-bit unaligned member of a
packed structure is probably an oversight on the part of the compiler. The
resulting pointer has the same issue.

    _______________________________________________________

Reply to this item at:

  <http://savannah.nongnu.org/bugs/?27352>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.nongnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]