From 8c3968245a0d0f015dcc0fb6b39fbec42c608ea1 Mon Sep 17 00:00:00 2001 From: Doug Kwan Date: Mon, 8 Aug 2011 22:08:35 -0700 Subject: Fix undefined behaviour in C. This patch uses offsetof() macro defined in the C specs instead of using a macro which dereferences a null pointer. The offsetof() macro is available since C89. Change-Id: I62b9b1d726dd0c3a956bdc4ae4cdd5db3dc55040 --- bcm4329/dhdutil/include/bcmutils.h | 4 +++- bcmdhd/dhdutil/include/bcmutils.h | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/bcm4329/dhdutil/include/bcmutils.h b/bcm4329/dhdutil/include/bcmutils.h index f08fe56..3b823a1 100644 --- a/bcm4329/dhdutil/include/bcmutils.h +++ b/bcm4329/dhdutil/include/bcmutils.h @@ -22,6 +22,8 @@ #ifndef _bcmutils_h_ #define _bcmutils_h_ +#include + #define bcm_strcpy_s(dst, noOfElements, src) strcpy((dst), (src)) #define bcm_strncpy_s(dst, noOfElements, src, count) strncpy((dst), (src), (count)) #define bcm_strcat_s(dst, noOfElements, src) strcat((dst), (src)) @@ -527,7 +529,7 @@ extern int bcm_format_ssid(char* buf, const uchar ssid[], uint ssid_len); #define ISPOWEROF2(x) ((((x)-1)&(x)) == 0) #define VALID_MASK(mask) !((mask) & ((mask) + 1)) #ifndef OFFSETOF -#define OFFSETOF(type, member) ((uint)(uintptr)&((type *)0)->member) +#define OFFSETOF(type, member) ((uint)offsetof(type, member)) #endif #ifndef ARRAYSIZE #define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0])) diff --git a/bcmdhd/dhdutil/include/bcmutils.h b/bcmdhd/dhdutil/include/bcmutils.h index f08fe56..3b823a1 100644 --- a/bcmdhd/dhdutil/include/bcmutils.h +++ b/bcmdhd/dhdutil/include/bcmutils.h @@ -22,6 +22,8 @@ #ifndef _bcmutils_h_ #define _bcmutils_h_ +#include + #define bcm_strcpy_s(dst, noOfElements, src) strcpy((dst), (src)) #define bcm_strncpy_s(dst, noOfElements, src, count) strncpy((dst), (src), (count)) #define bcm_strcat_s(dst, noOfElements, src) strcat((dst), (src)) @@ -527,7 +529,7 @@ extern int bcm_format_ssid(char* buf, const uchar ssid[], uint ssid_len); #define ISPOWEROF2(x) ((((x)-1)&(x)) == 0) #define VALID_MASK(mask) !((mask) & ((mask) + 1)) #ifndef OFFSETOF -#define OFFSETOF(type, member) ((uint)(uintptr)&((type *)0)->member) +#define OFFSETOF(type, member) ((uint)offsetof(type, member)) #endif #ifndef ARRAYSIZE #define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0])) -- cgit v1.2.3