From 8ba546241137c6c1c43751b25e40bbaf610658a1 Mon Sep 17 00:00:00 2001 From: tma Date: Mon, 10 Nov 2008 23:55:22 +0000 Subject: * Fix some new GCC 4.3 warnings * Fix many many strict aliasing warnings, now that it's re-enabled git-svn-id: svn://svn.icculus.org/quake3/trunk@1487 edf5b092-35ff-0310-97b2-ce42778d08ea --- code/client/cl_cin.c | 77 ++++++++++++++++++++++++------------------- code/qcommon/cm_load.c | 19 ++++++----- code/qcommon/cmd.c | 15 +++++---- code/qcommon/net_ip.c | 8 ++--- code/qcommon/q_shared.c | 3 +- code/qcommon/unzip.c | 6 ++-- code/qcommon/vm.c | 72 ++++++++++++++++++++++------------------ code/renderer/tr_bsp.c | 13 +++++--- code/renderer/tr_image.c | 14 +++++--- code/renderer/tr_image_bmp.c | 19 ++++++----- code/renderer/tr_image_jpg.c | 13 +++++--- code/renderer/tr_image_pcx.c | 27 ++++++++------- code/renderer/tr_image_png.c | 7 +++- code/renderer/tr_image_tga.c | 15 +++++---- code/renderer/tr_model.c | 27 ++++++++------- code/sys/con_tty.c | 20 ++++++----- code/sys/sys_unix.c | 5 ++- code/tools/lcc/src/bytecode.c | 3 +- code/ui/ui_shared.c | 9 ++++- 19 files changed, 220 insertions(+), 152 deletions(-) (limited to 'code') diff --git a/code/client/cl_cin.c b/code/client/cl_cin.c index 2e5a9b7..1fc5520 100644 --- a/code/client/cl_cin.c +++ b/code/client/cl_cin.c @@ -620,7 +620,10 @@ static void decodeCodeBook( byte *input, unsigned short roq_flags ) unsigned short *aptr, *bptr, *cptr, *dptr; long y0,y1,y2,y3,cr,cb; byte *bbptr, *baptr, *bcptr, *bdptr; - unsigned int *iaptr, *ibptr, *icptr, *idptr; + union { + unsigned int *i; + unsigned short *s; + } iaptr, ibptr, icptr, idptr; if (!roq_flags) { two = four = 256; @@ -663,7 +666,7 @@ static void decodeCodeBook( byte *input, unsigned short roq_flags ) VQ2TO4(aptr,bptr,cptr,dptr); } } else if (cinTable[currentHandle].samplesPerPixel==4) { - ibptr = (unsigned int *)bptr; + ibptr.s = bptr; for(i=0;iname, name, sizeof(name)); Com_sprintf( symbols, sizeof( symbols ), "vm/%s.map", name ); - len = FS_ReadFile( symbols, (void **)&mapfile ); - if ( !mapfile ) { + len = FS_ReadFile( symbols, &mapfile.v ); + if ( !mapfile.c ) { Com_Printf( "Couldn't load symbol file: %s\n", symbols ); return; } @@ -244,7 +248,7 @@ void VM_LoadSymbols( vm_t *vm ) { numInstructions = vm->instructionPointersLength >> 2; // parse the symbols - text_p = mapfile; + text_p = mapfile.c; prev = &vm->symbols; count = 0; @@ -291,7 +295,7 @@ void VM_LoadSymbols( vm_t *vm ) { vm->numSymbols = count; Com_Printf( "%i symbols parsed from %s\n", count, symbols ); - FS_FreeFile( mapfile ); + FS_FreeFile( mapfile.v ); } /* @@ -364,47 +368,50 @@ vmHeader_t *VM_LoadQVM( vm_t *vm, qboolean alloc ) { int dataLength; int i; char filename[MAX_QPATH]; - vmHeader_t *header; + union { + vmHeader_t *h; + void *v; + } header; // load the image Com_sprintf( filename, sizeof(filename), "vm/%s.qvm", vm->name ); Com_Printf( "Loading vm file %s...\n", filename ); - length = FS_ReadFile( filename, (void **)&header ); - if ( !header ) { + length = FS_ReadFile( filename, &header.v ); + if ( !header.h ) { Com_Printf( "Failed.\n" ); VM_Free( vm ); return NULL; } - if( LittleLong( header->vmMagic ) == VM_MAGIC_VER2 ) { + if( LittleLong( header.h->vmMagic ) == VM_MAGIC_VER2 ) { Com_Printf( "...which has vmMagic VM_MAGIC_VER2\n" ); // byte swap the header for ( i = 0 ; i < sizeof( vmHeader_t ) / 4 ; i++ ) { - ((int *)header)[i] = LittleLong( ((int *)header)[i] ); + ((int *)header.h)[i] = LittleLong( ((int *)header.h)[i] ); } // validate - if ( header->jtrgLength < 0 - || header->bssLength < 0 - || header->dataLength < 0 - || header->litLength < 0 - || header->codeLength <= 0 ) { + if ( header.h->jtrgLength < 0 + || header.h->bssLength < 0 + || header.h->dataLength < 0 + || header.h->litLength < 0 + || header.h->codeLength <= 0 ) { VM_Free( vm ); Com_Error( ERR_FATAL, "%s has bad header", filename ); } - } else if( LittleLong( header->vmMagic ) == VM_MAGIC ) { + } else if( LittleLong( header.h->vmMagic ) == VM_MAGIC ) { // byte swap the header // sizeof( vmHeader_t ) - sizeof( int ) is the 1.32b vm header size for ( i = 0 ; i < ( sizeof( vmHeader_t ) - sizeof( int ) ) / 4 ; i++ ) { - ((int *)header)[i] = LittleLong( ((int *)header)[i] ); + ((int *)header.h)[i] = LittleLong( ((int *)header.h)[i] ); } // validate - if ( header->bssLength < 0 - || header->dataLength < 0 - || header->litLength < 0 - || header->codeLength <= 0 ) { + if ( header.h->bssLength < 0 + || header.h->dataLength < 0 + || header.h->litLength < 0 + || header.h->codeLength <= 0 ) { VM_Free( vm ); Com_Error( ERR_FATAL, "%s has bad header", filename ); } @@ -416,7 +423,7 @@ vmHeader_t *VM_LoadQVM( vm_t *vm, qboolean alloc ) { // round up to next power of 2 so all data operations can // be mask protected - dataLength = header->dataLength + header->litLength + header->bssLength; + dataLength = header.h->dataLength + header.h->litLength + header.h->bssLength; for ( i = 0 ; dataLength > ( 1 << i ) ; i++ ) { } dataLength = 1 << i; @@ -431,33 +438,34 @@ vmHeader_t *VM_LoadQVM( vm_t *vm, qboolean alloc ) { } // copy the intialized data - Com_Memcpy( vm->dataBase, (byte *)header + header->dataOffset, header->dataLength + header->litLength ); + Com_Memcpy( vm->dataBase, (byte *)header.h + header.h->dataOffset, + header.h->dataLength + header.h->litLength ); // byte swap the longs - for ( i = 0 ; i < header->dataLength ; i += 4 ) { + for ( i = 0 ; i < header.h->dataLength ; i += 4 ) { *(int *)(vm->dataBase + i) = LittleLong( *(int *)(vm->dataBase + i ) ); } - if( header->vmMagic == VM_MAGIC_VER2 ) { - vm->numJumpTableTargets = header->jtrgLength >> 2; + if( header.h->vmMagic == VM_MAGIC_VER2 ) { + vm->numJumpTableTargets = header.h->jtrgLength >> 2; Com_Printf( "Loading %d jump table targets\n", vm->numJumpTableTargets ); if( alloc ) { - vm->jumpTableTargets = Hunk_Alloc( header->jtrgLength, h_high ); + vm->jumpTableTargets = Hunk_Alloc( header.h->jtrgLength, h_high ); } else { - Com_Memset( vm->jumpTableTargets, 0, header->jtrgLength ); + Com_Memset( vm->jumpTableTargets, 0, header.h->jtrgLength ); } - Com_Memcpy( vm->jumpTableTargets, (byte *)header + header->dataOffset + - header->dataLength + header->litLength, header->jtrgLength ); + Com_Memcpy( vm->jumpTableTargets, (byte *)header.h + header.h->dataOffset + + header.h->dataLength + header.h->litLength, header.h->jtrgLength ); // byte swap the longs - for ( i = 0 ; i < header->jtrgLength ; i += 4 ) { + for ( i = 0 ; i < header.h->jtrgLength ; i += 4 ) { *(int *)(vm->jumpTableTargets + i) = LittleLong( *(int *)(vm->jumpTableTargets + i ) ); } } - return header; + return header.h; } /* diff --git a/code/renderer/tr_bsp.c b/code/renderer/tr_bsp.c index 90aaf9d..8e0031b 100644 --- a/code/renderer/tr_bsp.c +++ b/code/renderer/tr_bsp.c @@ -1795,7 +1795,10 @@ Called directly from cgame void RE_LoadWorldMap( const char *name ) { int i; dheader_t *header; - byte *buffer; + union { + byte *b; + void *v; + } buffer; byte *startMarker; if ( tr.worldMapLoaded ) { @@ -1813,8 +1816,8 @@ void RE_LoadWorldMap( const char *name ) { tr.worldMapLoaded = qtrue; // load it - ri.FS_ReadFile( name, (void **)&buffer ); - if ( !buffer ) { + ri.FS_ReadFile( name, &buffer.v ); + if ( !buffer.b ) { ri.Error (ERR_DROP, "RE_LoadWorldMap: %s not found", name); } @@ -1831,7 +1834,7 @@ void RE_LoadWorldMap( const char *name ) { startMarker = ri.Hunk_Alloc(0, h_low); c_gridVerts = 0; - header = (dheader_t *)buffer; + header = (dheader_t *)buffer.b; fileBase = (byte *)header; i = LittleLong (header->version); @@ -1863,6 +1866,6 @@ void RE_LoadWorldMap( const char *name ) { // only set tr.world now that we know the entire level has loaded properly tr.world = &s_worldData; - ri.FS_FreeFile( buffer ); + ri.FS_FreeFile( buffer.v ); } diff --git a/code/renderer/tr_image.c b/code/renderer/tr_image.c index 2c3b72f..c86e32a 100644 --- a/code/renderer/tr_image.c +++ b/code/renderer/tr_image.c @@ -1431,7 +1431,11 @@ qhandle_t RE_RegisterSkin( const char *name ) { qhandle_t hSkin; skin_t *skin; skinSurface_t *surf; - char *text, *text_p; + union { + char *c; + void *v; + } text; + char *text_p; char *token; char surfName[MAX_QPATH]; @@ -1480,12 +1484,12 @@ qhandle_t RE_RegisterSkin( const char *name ) { } // load and parse the skin file - ri.FS_ReadFile( name, (void **)&text ); - if ( !text ) { + ri.FS_ReadFile( name, &text.v ); + if ( !text.c ) { return 0; } - text_p = text; + text_p = text.c; while ( text_p && *text_p ) { // get surface name token = CommaParse( &text_p ); @@ -1514,7 +1518,7 @@ qhandle_t RE_RegisterSkin( const char *name ) { skin->numSurfaces++; } - ri.FS_FreeFile( text ); + ri.FS_FreeFile( text.v ); // never let a skin have 0 shaders diff --git a/code/renderer/tr_image_bmp.c b/code/renderer/tr_image_bmp.c index 190b878..0b78abb 100644 --- a/code/renderer/tr_image_bmp.c +++ b/code/renderer/tr_image_bmp.c @@ -50,7 +50,10 @@ void R_LoadBMP( const char *name, byte **pic, int *width, int *height ) int row, column; byte *buf_p; byte *end; - byte *buffer = NULL; + union { + byte *b; + void *v; + } buffer; int length; BMPHeader_t bmpHeader; byte *bmpRGBA; @@ -66,8 +69,8 @@ void R_LoadBMP( const char *name, byte **pic, int *width, int *height ) // // load the file // - length = ri.FS_ReadFile( ( char * ) name, (void **)&buffer); - if (!buffer || length < 0) { + length = ri.FS_ReadFile( ( char * ) name, &buffer.v); + if (!buffer.b || length < 0) { return; } @@ -76,8 +79,8 @@ void R_LoadBMP( const char *name, byte **pic, int *width, int *height ) ri.Error( ERR_DROP, "LoadBMP: header too short (%s)\n", name ); } - buf_p = buffer; - end = buffer + length; + buf_p = buffer.b; + end = buffer.b + length; bmpHeader.id[0] = *buf_p++; bmpHeader.id[1] = *buf_p++; @@ -119,12 +122,12 @@ void R_LoadBMP( const char *name, byte **pic, int *width, int *height ) buf_p += sizeof(bmpHeader.palette); } - if (buffer + bmpHeader.bitmapDataOffset > end) + if (buffer.b + bmpHeader.bitmapDataOffset > end) { ri.Error( ERR_DROP, "LoadBMP: invalid offset value in header (%s)\n", name ); } - buf_p = buffer + bmpHeader.bitmapDataOffset; + buf_p = buffer.b + bmpHeader.bitmapDataOffset; if ( bmpHeader.id[0] != 'B' && bmpHeader.id[1] != 'M' ) { @@ -231,6 +234,6 @@ void R_LoadBMP( const char *name, byte **pic, int *width, int *height ) } } - ri.FS_FreeFile( buffer ); + ri.FS_FreeFile( buffer.v ); } diff --git a/code/renderer/tr_image_jpg.c b/code/renderer/tr_image_jpg.c index fb4f212..2e1a52a 100644 --- a/code/renderer/tr_image_jpg.c +++ b/code/renderer/tr_image_jpg.c @@ -57,7 +57,10 @@ void R_LoadJPG( const char *filename, unsigned char **pic, int *width, int *heig unsigned pixelcount, memcount; unsigned char *out; int len; - byte *fbuffer; + union { + byte *b; + void *v; + } fbuffer; byte *buf; /* In this example we want to open the input file before doing anything else, @@ -66,8 +69,8 @@ void R_LoadJPG( const char *filename, unsigned char **pic, int *width, int *heig * requires it in order to read binary files. */ - len = ri.FS_ReadFile ( ( char * ) filename, (void **)&fbuffer); - if (!fbuffer || len < 0) { + len = ri.FS_ReadFile ( ( char * ) filename, &fbuffer.v); + if (!fbuffer.b || len < 0) { return; } @@ -85,7 +88,7 @@ void R_LoadJPG( const char *filename, unsigned char **pic, int *width, int *heig /* Step 2: specify data source (eg, a file) */ - jpeg_mem_src(&cinfo, fbuffer, len); + jpeg_mem_src(&cinfo, fbuffer.b, len); /* Step 3: read file parameters with jpeg_read_header() */ @@ -203,7 +206,7 @@ void R_LoadJPG( const char *filename, unsigned char **pic, int *width, int *heig * so as to simplify the setjmp error logic above. (Actually, I don't * think that jpeg_destroy can do an error exit, but why assume anything...) */ - ri.FS_FreeFile (fbuffer); + ri.FS_FreeFile (fbuffer.v); /* At this point you may want to check to see whether any corrupt-data * warnings occurred (test whether jerr.pub.num_warnings is nonzero). diff --git a/code/renderer/tr_image_pcx.c b/code/renderer/tr_image_pcx.c index db407de..d1b1a5e 100644 --- a/code/renderer/tr_image_pcx.c +++ b/code/renderer/tr_image_pcx.c @@ -50,7 +50,10 @@ typedef struct { void R_LoadPCX ( const char *filename, byte **pic, int *width, int *height) { - byte *raw; + union { + byte *b; + void *v; + } raw; byte *end; pcx_t *pcx; int len; @@ -71,23 +74,23 @@ void R_LoadPCX ( const char *filename, byte **pic, int *width, int *height) // // load the file // - len = ri.FS_ReadFile( ( char * ) filename, (void **)&raw); - if (!raw || len < 0) { + len = ri.FS_ReadFile( ( char * ) filename, &raw.v); + if (!raw.b || len < 0) { return; } if((unsigned)len < sizeof(pcx_t)) { ri.Printf (PRINT_ALL, "PCX truncated: %s\n", filename); - ri.FS_FreeFile (raw); + ri.FS_FreeFile (raw.v); return; } // // parse the PCX file // - pcx = (pcx_t *)raw; - end = raw+len; + pcx = (pcx_t *)raw.b; + end = raw.b+len; w = LittleShort(pcx->xmax)+1; h = LittleShort(pcx->ymax)+1; @@ -107,7 +110,7 @@ void R_LoadPCX ( const char *filename, byte **pic, int *width, int *height) pix = pic8 = ri.Malloc ( size ); - raw = pcx->data; + raw.b = pcx->data; // FIXME: should use bytes_per_line but original q3 didn't do that either while(pix < pic8+size) { @@ -117,16 +120,16 @@ void R_LoadPCX ( const char *filename, byte **pic, int *width, int *height) continue; } - if(raw+1 > end) + if(raw.b+1 > end) break; - dataByte = *raw++; + dataByte = *raw.b++; if((dataByte & 0xC0) == 0xC0) { - if(raw+1 > end) + if(raw.b+1 > end) break; runLength = dataByte & 0x3F; - dataByte = *raw++; + dataByte = *raw.b++; } else runLength = 1; @@ -139,7 +142,7 @@ void R_LoadPCX ( const char *filename, byte **pic, int *width, int *height) ri.Free (pic8); } - if (raw-(byte*)pcx >= end - (byte*)769 || end[-769] != 0x0c) + if (raw.b-(byte*)pcx >= end - (byte*)769 || end[-769] != 0x0c) { ri.Printf (PRINT_ALL, "PCX missing palette: %s\n", filename); ri.FS_FreeFile (pcx); diff --git a/code/renderer/tr_image_png.c b/code/renderer/tr_image_png.c index e33ffff..ef44c16 100644 --- a/code/renderer/tr_image_png.c +++ b/code/renderer/tr_image_png.c @@ -215,6 +215,10 @@ struct BufferedFile static struct BufferedFile *ReadBufferedFile(const char *name) { struct BufferedFile *BF; + union { + byte *b; + void *v; + } buffer; /* * input verification @@ -248,7 +252,8 @@ static struct BufferedFile *ReadBufferedFile(const char *name) * Read the file. */ - BF->Length = ri.FS_ReadFile((char *) name, (void **) &BF->Buffer); + BF->Length = ri.FS_ReadFile((char *) name, &buffer.v); + BF->Buffer = buffer.b; /* * Did we get it? Is it big enough? diff --git a/code/renderer/tr_image_tga.c b/code/renderer/tr_image_tga.c index 2147acd..e66e60d 100644 --- a/code/renderer/tr_image_tga.c +++ b/code/renderer/tr_image_tga.c @@ -45,7 +45,10 @@ void R_LoadTGA ( const char *name, byte **pic, int *width, int *height) int row, column; byte *buf_p; byte *end; - byte *buffer = NULL; + union { + byte *b; + void *v; + } buffer; TargaHeader targa_header; byte *targa_rgba; int length; @@ -60,8 +63,8 @@ void R_LoadTGA ( const char *name, byte **pic, int *width, int *height) // // load the file // - length = ri.FS_ReadFile ( ( char * ) name, (void **)&buffer); - if (!buffer || length < 0) { + length = ri.FS_ReadFile ( ( char * ) name, &buffer.v); + if (!buffer.b || length < 0) { return; } @@ -70,8 +73,8 @@ void R_LoadTGA ( const char *name, byte **pic, int *width, int *height) ri.Error( ERR_DROP, "LoadTGA: header too short (%s)\n", name ); } - buf_p = buffer; - end = buffer + length; + buf_p = buffer.b; + end = buffer.b + length; targa_header.id_length = buf_p[0]; targa_header.colormap_type = buf_p[1]; @@ -313,5 +316,5 @@ void R_LoadTGA ( const char *name, byte **pic, int *width, int *height) *pic = targa_rgba; - ri.FS_FreeFile (buffer); + ri.FS_FreeFile (buffer.v); } diff --git a/code/renderer/tr_model.c b/code/renderer/tr_model.c index d721e2f..5355580 100644 --- a/code/renderer/tr_model.c +++ b/code/renderer/tr_model.c @@ -83,7 +83,10 @@ asked for again. */ qhandle_t RE_RegisterModel( const char *name ) { model_t *mod; - unsigned *buf; + union { + unsigned *u; + void *v; + } buf; int lod; int ident; qboolean loaded = qfalse; @@ -151,19 +154,19 @@ qhandle_t RE_RegisterModel( const char *name ) { { int filesize; - filesize = ri.FS_ReadFile(name, (void **) &buf); - if(!buf) + filesize = ri.FS_ReadFile(name, (void **) &buf.v); + if(!buf.u) { ri.Printf (PRINT_WARNING,"RE_RegisterModel: couldn't load %s\n", name); mod->type = MOD_BAD; return 0; } - ident = LittleLong(*(unsigned *)buf); + ident = LittleLong(*(unsigned *)buf.u); if(ident == MDR_IDENT) - loaded = R_LoadMDR(mod, buf, filesize, name); + loaded = R_LoadMDR(mod, buf.u, filesize, name); - ri.FS_FreeFile (buf); + ri.FS_FreeFile (buf.v); if(!loaded) { @@ -184,26 +187,26 @@ qhandle_t RE_RegisterModel( const char *name ) { else Com_sprintf(namebuf, sizeof(namebuf), "%s.%s", filename, fext); - ri.FS_ReadFile( namebuf, (void **)&buf ); - if ( !buf ) { + ri.FS_ReadFile( namebuf, &buf.v ); + if ( !buf.u ) { continue; } loadmodel = mod; - ident = LittleLong(*(unsigned *)buf); + ident = LittleLong(*(unsigned *)buf.u); if ( ident == MD4_IDENT ) { - loaded = R_LoadMD4( mod, buf, name ); + loaded = R_LoadMD4( mod, buf.u, name ); } else { if ( ident != MD3_IDENT ) { ri.Printf (PRINT_WARNING,"RE_RegisterModel: unknown fileid for %s\n", name); goto fail; } - loaded = R_LoadMD3( mod, lod, buf, name ); + loaded = R_LoadMD3( mod, lod, buf.u, name ); } - ri.FS_FreeFile (buf); + ri.FS_FreeFile (buf.v); if ( !loaded ) { if ( lod == 0 ) { diff --git a/code/sys/con_tty.c b/code/sys/con_tty.c index c2e553a..28f1fd4 100644 --- a/code/sys/con_tty.c +++ b/code/sys/con_tty.c @@ -86,12 +86,14 @@ send "\b \b" static void CON_Back( void ) { char key; + size_t size; + key = '\b'; - write(1, &key, 1); + size = write(1, &key, 1); key = ' '; - write(1, &key, 1); + size = write(1, &key, 1); key = '\b'; - write(1, &key, 1); + size = write(1, &key, 1); } /* @@ -142,12 +144,13 @@ static void CON_Show( void ) ttycon_hide--; if (ttycon_hide == 0) { - write( 1, "]", 1 ); + size_t size; + size = write( 1, "]", 1 ); if (TTY_con.cursor) { for (i=0; ifullScreen)) { + union + { + qboolean b; + int i; + } fullScreen; + + if (!PC_Int_Parse(handle, &fullScreen.i)) { return qfalse; } + menu->fullScreen = fullScreen.b; return qtrue; } -- cgit v1.2.3