[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Type punned-pointers
From: |
Henrik Goldman |
Subject: |
Re: Type punned-pointers |
Date: |
Fri, 9 Jun 2006 21:10:27 +0200 |
> FD_SET is probably a macro. I would take a look at the expanded code,
> which
> might try to do some illegal pointer assignment.
>
Yes, I've been thinking the same thing. Here is a piece of header from
/usr/include/sys/_fd_macros.h:
typedef int32_t __fd_mask;
#define _NFDBITS (sizeof(__fd_mask) * 8) /* 8 bits per byte */
#define __howmany(x,y) (((x)+((y)-1))/(y))
#ifndef _FD_SET
# define _FD_SET
typedef struct __fd_set {
long fds_bits[__howmany(FD_SETSIZE, (sizeof(long) * 8))];
} fd_set;
# ifndef _KERNEL
# ifdef __cplusplus
extern "C" {
# endif /* __cplusplus */
#ifdef _INCLUDE_HPUX_SOURCE
# define FD_SET(n,p) (((__fd_mask *)((p)->fds_bits))[(n)/_NFDBITS] |= (1 <<
((n) % _NFDBITS)))
# define FD_CLR(n,p) (((__fd_mask *)((p)->fds_bits))[(n)/_NFDBITS] &= ~(1 <<
((n) % _NFDBITS)))
# define FD_ISSET(n,p) (((__fd_mask *)((p)->fds_bits))[(n)/_NFDBITS] & (1 <<
((n) % _NFDBITS)))
# define FD_ZERO(p) memset((void *)(p), (int) 0, sizeof(*(p)))
#else
# define FD_SET(n,p) (__fd_set1(n, p))
# define FD_CLR(n,p) (__fd_clr(n, p))
# define FD_ISSET(n,p) (__fd_isset(n, p))
# define FD_ZERO(p) memset((void *)(p), (int) 0, sizeof(fd_set))
As you can see it does a typecast into (__fd_mask *). It's a little bit
unclear but I could foresee problems with this since it's not clear if sizes
are the same. In any case this is a system header so there is only so much
one can do about this since it's probably not recommended to change those
headers. Gcc 4.1.1 is brand new and was released for HP-UX as a binary depot
less then 2 weeks ago. There might be cases which it does not catch since it
has not been out for too long.
One idea would be to try going down to gcc 4.0.3 which also is released as a
binary version in order to see if there would be better results.
-- Henrik