On Tue, 15 Oct 2013, Kevin Lo wrote:

Log:
 Treat INADDR_NONE as uint32_t.

 Reviewed by:   glebius

Modified:
 head/sys/netinet/in.h

Modified: head/sys/netinet/in.h
==============================================================================
--- head/sys/netinet/in.h       Tue Oct 15 06:38:40 2013        (r256504)
+++ head/sys/netinet/in.h       Tue Oct 15 07:35:39 2013        (r256505)
@@ -379,7 +379,7 @@ __END_DECLS

#define INADDR_LOOPBACK         (u_int32_t)0x7f000001

The old casts of inet address macros are remarkably buggy:
- all are missing parentheses.  This gives an incorrect parse for weird
  code like INADDR_LOOPBACK[array] (this syntax is valid but gives
  different semantics to array[INADDR_LOOPBACK], unlike if the array and
  the index are either correctly written macros or not macros.
- all cast to u_int32_t instead of to in_addr_t.  This is not just a
  style bug.  u_int32_t isn't even declared, except accidentally via
  namespace pollution.

#ifndef _KERNEL
-#define        INADDR_NONE             0xffffffff              /* -1 return */
+#define        INADDR_NONE             (uint32_t)0xffffffff    /* -1 return */

This cast has no effect (except to add bugs) on any supported arch, since
all supported arches have 32-bit ints.

I first thought that this copied all the bugs from one of the old casts.
Actually, it uses a not-incorrect type, so its bugs are only:
- missing parentheses
- the type is not visually identical to the type of an inet address
  (in_addr_t)
- it is a style bug to not be bug for bug compatible with the spelling in
  the old casts.

#endif

#define INADDR_UNSPEC_GROUP     (u_int32_t)0xe0000000   /* 224.0.0.0 */


u_int32_t is also used in many non-address macros starting with IN_CLASSA().
These macros don't aren't missing parentheses.

I thought that namespace errors in <net/in.h> had all been fixed.  It
carefully declares in_addr_t and uint32_t, but still uses u_int32_t in
the POSIX inet address macros; these macros are also placed before the
typedefs.

Bruce
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to