Changed some variable definitions to make gcc -O2 aliasing checker happy

This commit is contained in:
Gerhard Rieger 2014-03-21 14:42:31 +01:00
parent 3f207a2e70
commit 58e48301a2
4 changed files with 32 additions and 20 deletions

View file

@ -19,6 +19,9 @@ corrections:
OPENSSL-CONNECT with bind option failed on some systems, eg.FreeBSD, with OPENSSL-CONNECT with bind option failed on some systems, eg.FreeBSD, with
"Invalid argument" "Invalid argument"
Thanks to Emile den Tex for reporting this bug. Thanks to Emile den Tex for reporting this bug.
Changed some variable definitions to make gcc -O2 aliasing checker happy
Thanks to Ilya Gordeev for reporting these warnings
fixed bug in xio-openssl.c that prevented error handling of bad number fixed bug in xio-openssl.c that prevented error handling of bad number
of arguments, thanks to Paulik Tamas for reporting of arguments, thanks to Paulik Tamas for reporting

42
filan.c
View file

@ -599,7 +599,10 @@ int sockan(int fd, FILE *outfile) {
{SO_DETACH_FILTER, "DETACH_FILTER"}, {SO_DETACH_FILTER, "DETACH_FILTER"},
#endif #endif
{0, NULL} } ; {0, NULL} } ;
char optval[FILAN_OPTLEN]; union {
char c[FILAN_OPTLEN];
int i[FILAN_OPTLEN/sizeof(int)];
} optval;
const struct sockopt *optname; const struct sockopt *optname;
union sockaddr_union sockname, peername; /* the longest I know of */ union sockaddr_union sockname, peername; /* the longest I know of */
socklen_t namelen; socklen_t namelen;
@ -609,33 +612,33 @@ int sockan(int fd, FILE *outfile) {
#endif #endif
optlen = FILAN_OPTLEN; optlen = FILAN_OPTLEN;
result = Getsockopt(fd, SOL_SOCKET, SO_TYPE, optval, &optlen); result = Getsockopt(fd, SOL_SOCKET, SO_TYPE, optval.c, &optlen);
if (result < 0) { if (result < 0) {
Debug4("getsockopt(%d, SOL_SOCKET, SO_TYPE, %p, {"F_socklen"}): %s", Debug4("getsockopt(%d, SOL_SOCKET, SO_TYPE, %p, {"F_socklen"}): %s",
fd, optval, optlen, strerror(errno)); fd, optval.c, optlen, strerror(errno));
} else { } else {
Debug3("fd %d: socket of type %d (\"%s\")", fd, *(int *)optval, Debug3("fd %d: socket of type %d (\"%s\")", fd, *optval.i,
socktypes[*(int *)optval]); socktypes[*optval.i]);
} }
optname = sockopts; while (optname->so) { optname = sockopts; while (optname->so) {
optlen = FILAN_OPTLEN; optlen = FILAN_OPTLEN;
result = result =
Getsockopt(fd, SOL_SOCKET, optname->so, (void *)optval, &optlen); Getsockopt(fd, SOL_SOCKET, optname->so, (void *)optval.c, &optlen);
if (result < 0) { if (result < 0) {
Debug5("getsockopt(%d, SOL_SOCKET, %d, %p, {"F_socklen"}): %s", Debug5("getsockopt(%d, SOL_SOCKET, %d, %p, {"F_socklen"}): %s",
fd, optname->so, optval, optlen, strerror(errno)); fd, optname->so, optval.c, optlen, strerror(errno));
fputc('\t', outfile); fputc('\t', outfile);
} else if (optlen == sizeof(int)) { } else if (optlen == sizeof(int)) {
Debug2("getsockopt(,,, {%d}, %d)", Debug2("getsockopt(,,, {%d}, %d)",
*(int *)optval, optlen); *optval.i, optlen);
/*Info2("%s: %d", optname->name, *(int *)optval);*/ /*Info2("%s: %d", optname->name, *optval.i);*/
fprintf(outfile, "%s=%d\t", optname->name, *(int *)optval); fprintf(outfile, "%s=%d\t", optname->name, *optval.i);
} else { } else {
Debug3("getsockopt(,,, {%d,%d}, %d)", Debug3("getsockopt(,,, {%d,%d}, %d)",
((int *)optval)[0], ((int *)optval)[1], optlen); optval.i[0], optval.i[1], optlen);
fprintf(outfile, "%s={%d,%d}\t", optname->name, fprintf(outfile, "%s={%d,%d}\t", optname->name,
((int *)optval)[0], ((int *)optval)[1]); optval.i[0], optval.i[1]);
} }
++optname; ++optname;
} }
@ -890,16 +893,19 @@ int tcpan(int fd, FILE *outfile) {
#if _WITH_SOCKET #if _WITH_SOCKET
int sockoptan(int fd, const struct sockopt *optname, int socklay, FILE *outfile) { int sockoptan(int fd, const struct sockopt *optname, int socklay, FILE *outfile) {
#define FILAN_OPTLEN 256 #define FILAN_OPTLEN 256
char optval[FILAN_OPTLEN]; union {
char c[FILAN_OPTLEN];
char i[FILAN_OPTLEN/sizeof(int)];
} optval;
socklen_t optlen; socklen_t optlen;
int result; int result;
optlen = FILAN_OPTLEN; optlen = FILAN_OPTLEN;
result = result =
Getsockopt(fd, socklay, optname->so, (void *)optval, &optlen); Getsockopt(fd, socklay, optname->so, (void *)optval.c, &optlen);
if (result < 0) { if (result < 0) {
Debug6("getsockopt(%d, %d, %d, %p, {"F_socklen"}): %s", Debug6("getsockopt(%d, %d, %d, %p, {"F_socklen"}): %s",
fd, socklay, optname->so, optval, optlen, strerror(errno)); fd, socklay, optname->so, optval.c, optlen, strerror(errno));
fputc('\t', outfile); fputc('\t', outfile);
return -1; return -1;
} else if (optlen == 0) { } else if (optlen == 0) {
@ -907,13 +913,13 @@ int sockoptan(int fd, const struct sockopt *optname, int socklay, FILE *outfile)
fprintf(outfile, "%s=\"\"\t", optname->name); fprintf(outfile, "%s=\"\"\t", optname->name);
} else if (optlen == sizeof(int)) { } else if (optlen == sizeof(int)) {
Debug2("getsockopt(,,, {%d}, %d)", Debug2("getsockopt(,,, {%d}, %d)",
*(int *)optval, optlen); *optval.i, optlen);
fprintf(outfile, "%s=%d\t", optname->name, *(int *)optval); fprintf(outfile, "%s=%d\t", optname->name, *optval.i);
} else { } else {
char outbuf[FILAN_OPTLEN*9+128], *cp = outbuf; char outbuf[FILAN_OPTLEN*9+128], *cp = outbuf;
int i; int i;
for (i = 0; i < optlen/sizeof(unsigned int); ++i) { for (i = 0; i < optlen/sizeof(unsigned int); ++i) {
cp += sprintf(cp, "%08x ", ((unsigned int *)optval)[i]); cp += sprintf(cp, "%08x ", (unsigned int)optval.i[i]);
} }
*--cp = '\0'; /* delete trailing space */ *--cp = '\0'; /* delete trailing space */
Debug2("getsockopt(,,, {%s}, %d)", outbuf, optlen); Debug2("getsockopt(,,, {%s}, %d)", outbuf, optlen);

View file

@ -20,7 +20,7 @@ int procan_cdefs(FILE *outfile) {
fprintf(outfile, "#define FD_SETSIZE %u\n", FD_SETSIZE); fprintf(outfile, "#define FD_SETSIZE %u\n", FD_SETSIZE);
#endif #endif
#ifdef NFDBITS #ifdef NFDBITS
fprintf(outfile, "#define NFDBITS %u\n", (unsigned int)NFDBITS); fprintf(outfile, "#define NFDBITS %d\n", NFDBITS);
#endif #endif
#ifdef O_RDONLY #ifdef O_RDONLY
fprintf(outfile, "#define O_RDONLY %u\n", O_RDONLY); fprintf(outfile, "#define O_RDONLY %u\n", O_RDONLY);

View file

@ -230,7 +230,10 @@ int xiolog_ancillary_ip6(struct cmsghdr *cmsg, int *num,
case IPV6_HOPLIMIT: case IPV6_HOPLIMIT:
strncpy(typbuff, "IPV6_HOPLIMIT", typlen); strncpy(typbuff, "IPV6_HOPLIMIT", typlen);
strncpy(nambuff, "hoplimit", namlen); strncpy(nambuff, "hoplimit", namlen);
snprintf(valbuff, vallen, "%d", *(int *)CMSG_DATA(cmsg)); {
int *intp = (int *)CMSG_DATA(cmsg);
snprintf(valbuff, vallen, "%d", *intp);
}
return STAT_OK; return STAT_OK;
#endif /* defined(IPV6_HOPLIMIT) */ #endif /* defined(IPV6_HOPLIMIT) */
#ifdef IPV6_RTHDR #ifdef IPV6_RTHDR