Commit f280dff9 authored by Steven Murray's avatar Steven Murray
Browse files

Started to fix the strict-aliasing bugs that are detected when compiling with

the -O2 option.
parent 1430cf74
......@@ -231,7 +231,7 @@ void Cglobals_getTid(int *Tid)
int *C__serrno() {
int rc;
int *addr;
void *addr;
if ( local_setspec == NULL ) {
return(&serrno);
......@@ -240,10 +240,10 @@ int *C__serrno() {
/*
* We re-use the old single thread serrno as key
*/
rc = local_getspec(&serrno,(void **)&addr);
rc = local_getspec(&serrno,&addr);
if ( rc == -1 || addr == NULL ) {
addr = (int *)calloc(1,sizeof(int));
rc = local_setspec(&serrno,(void *)addr);
rc = local_setspec(&serrno,addr);
}
/*
* If memory allocation failed, we can still
......@@ -259,7 +259,7 @@ int *C__serrno() {
int *C__rfio_errno() {
int rc;
int *addr;
void *addr;
if ( local_setspec == NULL ) {
return(&rfio_errno);
......@@ -268,10 +268,10 @@ int *C__rfio_errno() {
/*
* We re-use the old single thread rfio_errno as key
*/
rc = local_getspec(&rfio_errno,(void **)&addr);
rc = local_getspec(&rfio_errno,&addr);
if ( rc == -1 || addr == NULL ) {
addr = (int *)calloc(1,sizeof(int));
rc = local_setspec(&rfio_errno,(void *)addr);
rc = local_setspec(&rfio_errno,addr);
}
/*
* If memory allocation failed, we can still
......@@ -287,7 +287,7 @@ int *C__rfio_errno() {
int *C__Copterr() {
int rc;
int *addr;
void *addr;
if ( local_setspec == NULL ) {
return(&Copterr);
......@@ -296,10 +296,10 @@ int *C__Copterr() {
/*
* We re-use the old single thread Copterr as key
*/
rc = local_getspec(&Copterr,(void **)&addr);
rc = local_getspec(&Copterr,&addr);
if ( rc == -1 || addr == NULL ) {
addr = (int *)calloc(1,sizeof(int));
rc = local_setspec(&Copterr,(void *)addr);
rc = local_setspec(&Copterr,addr);
}
/*
* If memory allocation failed, we can still
......@@ -315,7 +315,7 @@ int *C__Copterr() {
int *C__Coptind() {
int rc;
int *addr;
void *addr;
if ( local_setspec == NULL ) {
return(&Coptind);
......@@ -324,10 +324,10 @@ int *C__Coptind() {
/*
* We re-use the old single thread rfio_errno as key
*/
rc = local_getspec(&Coptind,(void **)&addr);
rc = local_getspec(&Coptind,&addr);
if ( rc == -1 || addr == NULL ) {
addr = (int *)calloc(1,sizeof(int));
rc = local_setspec(&Coptind,(void *)addr);
rc = local_setspec(&Coptind,addr);
}
/*
* If memory allocation failed, we can still
......@@ -343,7 +343,7 @@ int *C__Coptind() {
int *C__Coptopt() {
int rc;
int *addr;
void *addr;
if ( local_setspec == NULL ) {
return(&Coptopt);
......@@ -352,10 +352,10 @@ int *C__Coptopt() {
/*
* We re-use the old single thread rfio_errno as key
*/
rc = local_getspec(&Coptopt,(void **)&addr);
rc = local_getspec(&Coptopt,&addr);
if ( rc == -1 || addr == NULL ) {
addr = (int *)calloc(1,sizeof(int));
rc = local_setspec(&Coptopt,(void *)addr);
rc = local_setspec(&Coptopt,addr);
}
/*
* If memory allocation failed, we can still
......@@ -371,7 +371,7 @@ int *C__Coptopt() {
int *C__Coptreset() {
int rc;
int *addr;
void *addr;
if ( local_setspec == NULL ) {
return(&Coptreset);
......@@ -380,10 +380,10 @@ int *C__Coptreset() {
/*
* We re-use the old single thread rfio_errno as key
*/
rc = local_getspec(&Coptreset,(void **)&addr);
rc = local_getspec(&Coptreset,&addr);
if ( rc == -1 || addr == NULL ) {
addr = (int *)calloc(1,sizeof(int));
rc = local_setspec(&Coptreset,(void *)addr);
rc = local_setspec(&Coptreset,addr);
}
/*
* If memory allocation failed, we can still
......@@ -399,7 +399,7 @@ int *C__Coptreset() {
char **C__Coptarg() {
int rc;
char **addr;
void *addr;
if ( local_setspec == NULL ) {
return(&Coptarg);
......@@ -408,10 +408,10 @@ char **C__Coptarg() {
/*
* We re-use the old single thread rfio_errno as key
*/
rc = local_getspec(&Coptarg_key,(void **)&addr);
rc = local_getspec(&Coptarg_key,&addr);
if ( rc == -1 || addr == NULL ) {
addr = (char **)calloc(1,sizeof(char *));
rc = local_setspec(&Coptarg_key,(void *)addr);
rc = local_setspec(&Coptarg_key,addr);
}
/*
* If memory allocation failed, we can still
......
......@@ -29,14 +29,14 @@ const char *name;
*/
static int grp_key = -1;
static int grpbuf_key = -1;
struct group *grp = NULL;
void *grp = NULL;
struct group *result = NULL;
char *grpbuf = NULL;
void *grpbuf = NULL;
size_t grpbuflen = BUFSIZ;
int rc;
Cglobals_get(&grp_key,(void **)&grp,sizeof(struct group));
Cglobals_get(&grpbuf_key,(void **)&grpbuf,grpbuflen);
Cglobals_get(&grp_key,&grp,sizeof(struct group));
Cglobals_get(&grpbuf_key,&grpbuf,grpbuflen);
if ( grp == NULL || grpbuf == NULL ) {
serrno = SEINTERNAL;
......@@ -60,14 +60,14 @@ gid_t gid;
*/
static int grp_key = -1;
static int grpbuf_key = -1;
struct group *grp = NULL;
void *grp = NULL;
struct group *result = NULL;
char *grpbuf = NULL;
void *grpbuf = NULL;
size_t grpbuflen = BUFSIZ;
int rc;
Cglobals_get(&grp_key,(void **)&grp,sizeof(struct group));
Cglobals_get(&grpbuf_key,(void **)&grpbuf,grpbuflen);
Cglobals_get(&grp_key,&grp,sizeof(struct group));
Cglobals_get(&grpbuf_key,&grpbuf,grpbuflen);
if ( grp == NULL || grpbuf == NULL ) {
serrno = SEINTERNAL;
......
......@@ -33,15 +33,15 @@ const char *name;
static int hostdata_key = -1;
int rc;
struct hostent *hp;
struct hostent *result = (struct hostent *)NULL;
char *buffer = (char *)NULL;
void *result = NULL;
void *buffer = NULL;
int bufsize = 1024;
int h_errnoop = 0;
Cglobals_get(&hostent_key,(void **)&result,sizeof(struct hostent));
Cglobals_get(&hostdata_key,(void **)&buffer,bufsize);
Cglobals_get(&hostent_key,&result,sizeof(struct hostent));
Cglobals_get(&hostdata_key,&buffer,bufsize);
if ( result == (struct hostent *)NULL || buffer == (char *)NULL ) {
if ( result == NULL || buffer == NULL ) {
h_errno = NO_RECOVERY;
return(NULL);
}
......@@ -74,15 +74,15 @@ int type;
static int hostdata_key = -1;
int rc;
struct hostent *hp;
struct hostent *result = (struct hostent *)NULL;
char *buffer = (char *)NULL;
void *result = NULL;
void *buffer = NULL;
int bufsize = 1024;
int h_errnoop = 0;
Cglobals_get(&hostent_key,(void **)&result,sizeof(struct hostent));
Cglobals_get(&hostdata_key,(void **)&buffer,bufsize);
Cglobals_get(&hostent_key,&result,sizeof(struct hostent));
Cglobals_get(&hostdata_key,&buffer,bufsize);
if ( result == (struct hostent *)NULL || buffer == (char *)NULL ) {
if ( result == NULL || buffer == NULL ) {
h_errno = NO_RECOVERY;
return(NULL);
}
......@@ -114,14 +114,14 @@ const char *proto;
static int servdata_key = -1;
int rc;
struct servent *sp;
struct servent *result = (struct servent *)NULL;
char *buffer = (char *)NULL;
void *result = NULL;
void *buffer = NULL;
int bufsize = 1024;
Cglobals_get(&servent_key,(void **)&result,sizeof(struct servent));
Cglobals_get(&servdata_key,(void **)&buffer,bufsize);
Cglobals_get(&servent_key,&result,sizeof(struct servent));
Cglobals_get(&servdata_key,&buffer,bufsize);
if ( result == (struct servent *)NULL || buffer == (char *)NULL ) {
if ( result == NULL || buffer == NULL ) {
return(NULL);
}
rc = getservbyname_r(name,proto,result,buffer,bufsize,&sp);
......
......@@ -86,9 +86,9 @@ static int getacct_key = -1;
char *getacct()
{
char *resbuf = NULL;
void *resbuf = NULL;
Cglobals_get(&getacct_key,(void **) &resbuf,BUFSIZ+1);
Cglobals_get(&getacct_key, &resbuf,BUFSIZ+1);
if ( resbuf == NULL ) return(NULL);
return(getacct_r(resbuf));
......
......@@ -123,10 +123,10 @@ char *getifnam_r(int s,
char *getifnam(int s)
{
char *ifname = NULL;
void *ifname = NULL;
size_t ifnamelen = 16;
Cglobals_get(&ifname_key,(void **)&ifname,ifnamelen);
Cglobals_get(&ifname_key,&ifname,ifnamelen);
return(getifnam_r(s,ifname,ifnamelen));
}
......@@ -609,9 +609,9 @@ static int sstrerror_key = -1;
char *sstrerror(int n)
{
char *buf = NULL;
void *buf = NULL;
int buflen = 80;
Cglobals_get(&sstrerror_key,(void **)&buf,buflen);
Cglobals_get(&sstrerror_key,&buf,buflen);
return(sstrerror_r(n,buf,buflen));
}
......@@ -21,9 +21,6 @@ typedef struct trc_spec {
int _trace_level ; /* dynamic trace level */
int _indent_level ; /* dynamic indentation level */
} trc_spec_t;
#define trace_level trc->_trace_level
#define trace_initialized trc->_trace_initialized
#define indent_level trc->_indent_level
extern char* getenv(); /* get environment variable */
......@@ -31,17 +28,17 @@ void print_trace(int level, const char *label, const char *format, ...)
{
va_list args; /* arguments */
register int i; /* general purpose index */
trc_spec_t *trc;
void *trc;
int sav_errno = errno;
int sav_serrno = serrno;
va_start(args, format);
Cglobals_get(&trc_key,(void **)&trc,sizeof(trc_spec_t));
if (trace_level < level) {
Cglobals_get(&trc_key,&trc,sizeof(trc_spec_t));
if ( ((trc_spec_t*)trc)->_trace_level < level) {
va_end (args);
return;
}
for (i=0; i< level+indent_level ; i++) {
for (i=0; i< level+ ((trc_spec_t*)trc)->_indent_level; i++) {
fprintf(stdout," "); /* indentation */
}
fprintf(stdout,"%s: ", label);
......@@ -57,36 +54,36 @@ void init_trace(const char *name) /* environment variable na
/* initialize trace level */
{
register char *p; /* general purpose char. string pointer */
trc_spec_t *trc;
void *trc;
int sav_errno = errno;
int sav_serrno = serrno;
Cglobals_get(&trc_key,(void **)&trc,sizeof(trc_spec_t));
if (!trace_initialized) {
Cglobals_get(&trc_key,&trc,sizeof(trc_spec_t));
if (!((trc_spec_t*)trc)->_trace_initialized) {
if ((p = getenv(name)) != NULL) {
if (atoi(p) != 0) {
trace_level = atoi(p);
((trc_spec_t*)trc)->_trace_level = atoi(p);
/* only print the trace level for levels 2 and above */
if (trace_level > 1) {
print_trace(0, " **** ", "trace level set to %d", trace_level);
if (((trc_spec_t*)trc)->_trace_level > 1) {
print_trace(0, " **** ", "trace level set to %d", ((trc_spec_t*)trc)->_trace_level);
}
}
}
trace_initialized++;
(((trc_spec_t*)trc)->_trace_initialized)++;
}
indent_level++;
(((trc_spec_t*)trc)->_indent_level)++;
errno = sav_errno;
serrno = sav_serrno;
}
void end_trace() /* end trace level */
{
trc_spec_t *trc;
void *trc;
int sav_errno = errno;
int sav_serrno = serrno;
Cglobals_get(&trc_key,(void **)&trc,sizeof(trc_spec_t));
if (indent_level > 0) indent_level--;
Cglobals_get(&trc_key,&trc,sizeof(trc_spec_t));
if (((trc_spec_t*)trc)->_indent_level > 0) (((trc_spec_t*)trc)->_indent_level)--;
errno = sav_errno;
serrno = sav_serrno;
}
......@@ -108,11 +105,11 @@ void print_trace_r(void *trace, int level, const char *label, const char *format
return;
}
trc = (trc_spec_t *)trace;
if (trace_level < level) {
if (trc->_trace_level < level) {
va_end (args);
return;
}
for (i=0; i< level+indent_level ; i++) {
for (i=0; i< level+(((trc_spec_t*)trc)->_indent_level) ; i++) {
fprintf(stdout," "); /* indentation */
}
fprintf(stdout,"%s: ", label);
......@@ -136,19 +133,19 @@ void init_trace_r( /* initialize trace level */
*trace = calloc(1, sizeof(trc_spec_t));
if (*trace == NULL) return;
trc = (trc_spec_t *)*trace;
if (!trace_initialized) {
if (!((trc_spec_t*)trc)->_trace_initialized) {
if ((p = getenv(name)) != NULL) {
if (atoi(p) != 0) {
trace_level = atoi(p);
((trc_spec_t*)trc)->_trace_level = atoi(p);
/* only print the trace level for levels 2 and above */
if (trace_level > 1) {
print_trace(0, " **** ", "trace level set to %d", trace_level);
if (((trc_spec_t*)trc)->_trace_level > 1) {
print_trace(0, " **** ", "trace level set to %d", ((trc_spec_t*)trc)->_trace_level);
}
}
}
trace_initialized++;
(((trc_spec_t*)trc)->_trace_initialized)++;
}
indent_level++;
(((trc_spec_t*)trc)->_indent_level)++;
errno = sav_errno;
serrno = sav_serrno;
}
......@@ -161,7 +158,7 @@ void end_trace_r(void *trace) /* end trace level */
if (trace == NULL) return;
trc = (trc_spec_t *)trace;
if (indent_level > 0) indent_level--;
if (((trc_spec_t*)trc)->_indent_level > 0) (((trc_spec_t*)trc)->_indent_level)--;
errno = sav_errno;
serrno = sav_serrno;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment