From b331b484670f374859f67469f130b33521eda746 Mon Sep 17 00:00:00 2001 From: Taylor Richards Date: Fri, 2 May 2014 15:00:31 -0400 Subject: [PATCH] warnings (clang): various div-by-0 value set by not used unused variables various null ptr issues array bounds --- src/asteroid/asteroid.cpp | 6 ++--- src/bmpman/bmpman.cpp | 35 +++++++++++++-------------- src/cfile/cfile.cpp | 6 ++--- src/cfile/cfilearchive.cpp | 4 +-- src/cfile/cfilesystem.cpp | 2 +- src/freespace2/freespace.cpp | 29 ++++++---------------- src/gamesequence/gamesequence.cpp | 1 - src/graphics/grgl1render.cpp | 1 - src/graphics/grgl1texture.cpp | 4 +-- src/hud/hudtarget.cpp | 5 +++- src/hud/hudtargetbox.cpp | 3 +-- src/hud/hudwingmanstatus.cpp | 3 +-- src/lighting/lighting.cpp | 1 - src/localization/localize.cpp | 6 ++--- src/math/fvi.cpp | 12 +++------ src/math/vecmat.cpp | 2 -- src/menuui/barracks.cpp | 3 --- src/menuui/playermenu.cpp | 5 ++-- src/menuui/snazzyui.cpp | 1 - src/missionui/missionweaponchoice.cpp | 3 ++- src/network/multi_obj.cpp | 2 ++ src/ship/aicode.cpp | 5 ++++ 22 files changed, 54 insertions(+), 85 deletions(-) diff --git a/src/asteroid/asteroid.cpp b/src/asteroid/asteroid.cpp index 7fe1546..b75d7d8 100644 --- a/src/asteroid/asteroid.cpp +++ b/src/asteroid/asteroid.cpp @@ -602,10 +602,6 @@ object *asteroid_create(asteroid_field *asfieldp, int asteroid_type, int asteroi Num_asteroids++; - if (radius < 1.0) { - radius = 1.0f; - } - vector rotvel; if ( Game_mode & GM_NORMAL ) { vm_vec_rand_vec_quick(&rotvel); @@ -793,6 +789,8 @@ void asteroid_create_all() return; } + SDL_zero(ship_debris_odds_table); + int max_asteroids = Asteroid_field.num_initial_asteroids; // * (1.0f - 0.1f*(MAX_DETAIL_LEVEL-Detail.asteroid_density))); int num_debris_types = 0; diff --git a/src/bmpman/bmpman.cpp b/src/bmpman/bmpman.cpp index aaafdd9..a1be58a 100644 --- a/src/bmpman/bmpman.cpp +++ b/src/bmpman/bmpman.cpp @@ -978,7 +978,6 @@ int bm_load( const char * real_filename ) // found as pre-existing case 1: - found = 1; return handle; } @@ -1318,7 +1317,6 @@ extern int palman_is_nondarkening(int r,int g, int b); static void bm_convert_format( int bitmapnum, bitmap *bmp, ubyte bpp, ubyte flags ) { int idx; - int r, g, b, a; if(Fred_running || Pofview_running || Is_standalone){ SDL_assert(bmp->bpp == 8); @@ -1456,14 +1454,12 @@ void bm_lock_ani( int handle, int bitmapnum, bitmap_entry *be, bitmap *bmp, ubyt first_frame = be->info.ani.first_frame; nframes = bm_bitmaps[first_frame].info.ani.num_frames; - if ( (the_anim = anim_load(bm_bitmaps[first_frame].filename)) == NULL ) { - // Error(LOCATION, "Error opening %s in bm_lock\n", be->filename); - } - if ( (the_anim_instance = init_anim_instance(the_anim, bpp)) == NULL ) { - // Error(LOCATION, "Error opening %s in bm_lock\n", be->filename); - anim_free(the_anim); - } + the_anim = anim_load(bm_bitmaps[first_frame].filename); + SDL_assert_release(the_anim); // should never have gotten this far + + the_anim_instance = init_anim_instance(the_anim, bpp); + SDL_assert_release(the_anim); // should never have gotten this far int can_drop_frames = 0; @@ -1478,7 +1474,6 @@ void bm_lock_ani( int handle, int bitmapnum, bitmap_entry *be, bitmap *bmp, ubyt } for ( i=0; ibpp = bpp; } - bm->data = (ptr_u)bm_malloc(first_frame + i, size); frame_data = anim_get_next_raw_buffer(the_anim_instance, 0 ,flags & BMP_AABITMAP ? 1 : 0, bm->bpp); - if ( frame_data == NULL ) { + if (frame_data == NULL) { + Int3(); + break; // Error(LOCATION,"Fatal error locking .ani file: %s\n", be->filename); - } - + } + + bm->data = (ptr_u)bm_malloc(first_frame + i, size); + + ubyte *dptr, *sptr; sptr = frame_data; @@ -1563,7 +1562,7 @@ void bm_lock_ani( int handle, int bitmapnum, bitmap_entry *be, bitmap *bmp, ubyt // Skip a frame if ( (i < nframes-1) && can_drop_frames ) { - frame_data = anim_get_next_raw_buffer(the_anim_instance, 0, flags & BMP_AABITMAP ? 1 : 0, bm->bpp); + anim_get_next_raw_buffer(the_anim_instance, 0, flags & BMP_AABITMAP ? 1 : 0, bm->bpp); } //mprintf(( "Checksum = %d\n", be->palette_checksum )); @@ -2465,8 +2464,8 @@ void bm_get_filename(int bitmapnum, char *filename) // given a bitmap and a section, return the size (w, h) void bm_get_section_size(int bitmapnum, int sx, int sy, int *w, int *h) { - int bw, bh; - bitmap_section_info *sections; + int bw = 0, bh = 0; + bitmap_section_info *sections = NULL; // bogus input? SDL_assert((w != NULL) && (h != NULL)); @@ -2478,7 +2477,7 @@ void bm_get_section_size(int bitmapnum, int sx, int sy, int *w, int *h) bm_get_info(bitmapnum, &bw, &bh, NULL, NULL, NULL, §ions); // determine the width and height of this section - if (gr_screen.use_sections) { + if ( gr_screen.use_sections && (sections != NULL) ) { *w = sx < (sections->num_x - 1) ? MAX_BMAP_SECTION_SIZE : bw - sections->sx[sx]; *h = sy < (sections->num_y - 1) ? MAX_BMAP_SECTION_SIZE : bh - sections->sy[sy]; } else { diff --git a/src/cfile/cfile.cpp b/src/cfile/cfile.cpp index 42d4ac2..82d9d7a 100644 --- a/src/cfile/cfile.cpp +++ b/src/cfile/cfile.cpp @@ -1377,14 +1377,13 @@ int cfwrite(const void *buf, int elsize, int nelem, CFILE *cfile) // int cfputc(int c, CFILE *cfile) { - int result; + int result = 0; SDL_assert(cfile != NULL); Cfile_block *cb; SDL_assert(cfile->id >= 0 && cfile->id < MAX_CFILE_BLOCKS); cb = &Cfile_block_list[cfile->id]; - result = 0; // cfputc() not supported for memory-mapped files SDL_assert( !cb->data ); @@ -1471,9 +1470,8 @@ int cfputs(const char *str, CFILE *cfile) SDL_assert(cfile->id >= 0 && cfile->id < MAX_CFILE_BLOCKS); cb = &Cfile_block_list[cfile->id]; - int result; + int result = 0; - result = 0; // cfputs() not supported for memory-mapped files SDL_assert( !cb->data ); SDL_assert(cb->fp != NULL); diff --git a/src/cfile/cfilearchive.cpp b/src/cfile/cfilearchive.cpp index 23e9335..78a844c 100644 --- a/src/cfile/cfilearchive.cpp +++ b/src/cfile/cfilearchive.cpp @@ -139,9 +139,7 @@ int cfeof(CFILE *cfile) SDL_assert(cfile->id >= 0 && cfile->id < MAX_CFILE_BLOCKS); cb = &Cfile_block_list[cfile->id]; - int result; - - result = 0; + int result = 0; // cfeof() not supported for memory-mapped files SDL_assert( !cb->data ); diff --git a/src/cfile/cfilesystem.cpp b/src/cfile/cfilesystem.cpp index d2ac3d7..dc86ee4 100644 --- a/src/cfile/cfilesystem.cpp +++ b/src/cfile/cfilesystem.cpp @@ -1381,7 +1381,7 @@ void cf_create_default_path_string( char *path, int pathtype, const char *filena } else { if ( cfile_init_paths() ) { - strcpy(path, filename); + strcpy(path, (filename) ? filename : ""); return; } diff --git a/src/freespace2/freespace.cpp b/src/freespace2/freespace.cpp index b820539..8203a2e 100644 --- a/src/freespace2/freespace.cpp +++ b/src/freespace2/freespace.cpp @@ -1372,8 +1372,6 @@ void game_framerate_check() } gr_printf(200, y_start, "%d%%", (int)pct); - - y_start += 10; } } @@ -2729,7 +2727,6 @@ void game_show_framerate() gr_printf( sx, sy, NOX("FLIP: %.0f%%"), Timing_flip*100.0f/Timing_total ); sy += dy; gr_printf( sx, sy, NOX("GAME: %.0f%%"), (Timing_total-(Timing_render2+Timing_render3+Timing_flip+Timing_clear))*100.0f/Timing_total ); - sy += dy; } } @@ -2762,7 +2759,6 @@ void game_show_framerate() { extern int Gr_textures_in; gr_printf( sx, sy, NOX("VRAM: %d KB\n"), Gr_textures_in/1024 ); - sy += dy; } } @@ -7400,10 +7396,6 @@ void game_show_event_debug(float frametime) FILE * Time_fp; FILE * Texture_fp; -#ifndef PLAT_UNIX -extern int Tmap_npixels; -#endif - int Tmap_num_too_big = 0; int Num_models_needing_splitting = 0; @@ -7470,10 +7462,6 @@ void Time_model( int modelnum ) ta.p = ta.b = ta.h = 0.0f; int framecount = 0; -#ifndef PLAT_UNIX - Tmap_npixels = 0; -#endif - int bitmaps_used_this_frame, bitmaps_new_this_frame; bm_get_frame_usage(&bitmaps_used_this_frame,&bitmaps_new_this_frame); @@ -7511,23 +7499,20 @@ void Time_model( int modelnum ) fix t2 = timer_get_fixed_seconds(); + if (framecount < 1) { + return; + } + bm_get_frame_usage(&bitmaps_used_this_frame,&bitmaps_new_this_frame); //bitmaps_used_this_frame /= framecount; modelstats_num_polys /= framecount; modelstats_num_verts /= framecount; -#ifndef PLAT_UNIX - Tmap_npixels /=framecount; -#endif - mprintf(( "'%s' is %.2f FPS\n", pof_file, i2fl(framecount)/f2fl(t2-t1) )); -#ifndef PLAT_UNIX - fprintf( Time_fp, "\"%s\"\t%.0f\t%d\t%d\t%d\t%d\n", pof_file, i2fl(framecount)/f2fl(t2-t1), bitmaps_used_this_frame, modelstats_num_polys, modelstats_num_verts, Tmap_npixels ); -#else - fprintf( Time_fp, "\"%s\"\t%.0f\t%d\t%d\t%d\n", pof_file, i2fl(framecount)/f2fl(t2-t1), bitmaps_used_this_frame, modelstats_num_polys, modelstats_num_verts ); -#endif -// fprintf( Time_fp, "%.0f\t%d\t%d\t%d\t%d\n", i2fl(framecount)/f2fl(t2-t1), bitmaps_used_this_frame, modelstats_num_polys, modelstats_num_verts, Tmap_npixels ); + fprintf( Time_fp, "\"%s\"\t%.0f\t%d\t%d\t%d\n", pof_file, i2fl(framecount)/f2fl(t2-t1), bitmaps_used_this_frame, modelstats_num_polys, modelstats_num_verts ); + +// fprintf( Time_fp, "%.0f\t%d\t%d\t%d\n", i2fl(framecount)/f2fl(t2-t1), bitmaps_used_this_frame, modelstats_num_polys, modelstats_num_verts ); // key_getch(); diff --git a/src/gamesequence/gamesequence.cpp b/src/gamesequence/gamesequence.cpp index fbff08c..a208e5b 100644 --- a/src/gamesequence/gamesequence.cpp +++ b/src/gamesequence/gamesequence.cpp @@ -553,7 +553,6 @@ void gameseq_pop_state() // set the popped_state to be the one we moved into gs_current_stack--; - popped_state = gs[gs_current_stack].current_state; // swap all remaining events from the state which just got popped to this new state while(gs[gs_current_stack+1].queue_head != gs[gs_current_stack+1].queue_tail){ diff --git a/src/graphics/grgl1render.cpp b/src/graphics/grgl1render.cpp index 96381f6..ef5bd05 100644 --- a/src/graphics/grgl1render.cpp +++ b/src/graphics/grgl1render.cpp @@ -608,7 +608,6 @@ void gr_opengl1_string( int sx, int sy, const char *s ) glVertexPointer(2, GL_FLOAT, sizeof(rb_t), &render_buffer[0].x); glTexCoordPointer(2, GL_FLOAT, sizeof(rb_t), &render_buffer[0].u); - x = sx; y = sy; if (sx==0x8000) { //centered diff --git a/src/graphics/grgl1texture.cpp b/src/graphics/grgl1texture.cpp index 10f05e9..9678b7a 100644 --- a/src/graphics/grgl1texture.cpp +++ b/src/graphics/grgl1texture.cpp @@ -343,7 +343,7 @@ static void opengl1_tcache_get_adjusted_texture_size(int w_in, int h_in, int *w_ static int opengl1_create_texture_sub(int bitmap_type, int texture_handle, ushort *data, int sx, int sy, int src_w, int src_h, int bmap_w, int bmap_h, int tex_w, int tex_h, tcache_slot_opengl *t, int reload, int resize, int fail_on_full) { int ret_val = 1; - int size; + int size = 0; int i, j; ubyte *bmp_data = ((ubyte*)data); ubyte *texmem = NULL, *texmemp; @@ -406,8 +406,6 @@ static int opengl1_create_texture_sub(int bitmap_type, int texture_handle, ushor // gr_opengl_set_texture_state(GL_current_texture_source); // } - size = 0; - switch (bitmap_type) { case TCACHE_TYPE_AABITMAP: { diff --git a/src/hud/hudtarget.cpp b/src/hud/hudtarget.cpp index e80addb..80ff35b 100644 --- a/src/hud/hudtarget.cpp +++ b/src/hud/hudtarget.cpp @@ -841,6 +841,10 @@ object *hud_reticle_pick_target() return_objp = NULL; + if ( EMPTY(&Reticle_cur_list) ) { + return NULL; + } + // As a first step, see if both ships and debris are in the list. If so, cull the debris. int debris_in_list = 0; int ship_in_list = 0; @@ -3679,7 +3683,6 @@ void hud_show_hostile_triangle() int player_obj_index = OBJ_INDEX(Player_obj); int turret_is_attacking = 0; - so = GET_FIRST(&Ship_obj_list); for ( so = GET_FIRST(&Ship_obj_list); so != END_OF_LIST(&Ship_obj_list); so = GET_NEXT(so) ) { A = &Objects[so->objnum]; diff --git a/src/hud/hudtargetbox.cpp b/src/hud/hudtargetbox.cpp index f0de358..c277321 100644 --- a/src/hud/hudtargetbox.cpp +++ b/src/hud/hudtargetbox.cpp @@ -999,6 +999,7 @@ void hud_render_target_ship_info(object *target_objp) emp_hud_printf(Targetbox_coords[gr_screen.res][TBOX_CLASS][0], Targetbox_coords[gr_screen.res][TBOX_CLASS][1], EG_TBOX_CLASS, temp_name); ship_integrity = 1.0f; + shield_strength = 1.0f; hud_get_target_strength(target_objp, &shield_strength, &ship_integrity); // convert to values of 0->100 @@ -1753,7 +1754,6 @@ void hud_show_target_data(float frametime) sprintf(outstr, "Subsys: %s", aip->targeted_subsys->system_info->name); gr_printf(sx, sy, outstr); } - sy += dy; } // print out energy transfer information on the ship @@ -1830,7 +1830,6 @@ void hud_show_target_data(float frametime) sy += dy; gr_printf(sx, sy, "Mass: %.2f\n", pm->mass); - sy += dy; } } diff --git a/src/hud/hudwingmanstatus.cpp b/src/hud/hudwingmanstatus.cpp index 7c97b51..207ff06 100644 --- a/src/hud/hudwingmanstatus.cpp +++ b/src/hud/hudwingmanstatus.cpp @@ -589,8 +589,7 @@ void hud_wingman_status_blit_middle_frame(int num_wings_to_draw) Int3(); return; } - sx = -1; - sy = -1; + for(idx=num_wings_to_draw; idx>=3; idx--){ sx = HUD_wingman_middle_coords[gr_screen.res][idx - 1][0]; sy = HUD_wingman_middle_coords[gr_screen.res][idx - 1][1]; diff --git a/src/lighting/lighting.cpp b/src/lighting/lighting.cpp index 1957b44..e075b69 100644 --- a/src/lighting/lighting.cpp +++ b/src/lighting/lighting.cpp @@ -689,7 +689,6 @@ void light_rotate_all() int n = Num_light_levels-1; - l = Lights; for (i=0; i= -0.05f && root1 < 0.0f) { @@ -1242,9 +1240,7 @@ TryVertex: root2 = (float) ((-B - root)/(2*A)); if (root1 > root2) { - temp = root1; root1 = root2; - root2 = temp; } // look only at the fist hit (ignore negative first hit) @@ -1275,9 +1271,7 @@ TryVertex: root2 = (float) ((-B - root)/(2*A)); if (root1 > root2) { - temp = root1; root1 = root2; - root2 = temp; } // look only at the first hit (ignore negative first hit) @@ -1313,7 +1307,7 @@ TryVertex: } vm_vec_scale_add( &temp_sphere_hit, xs0, vs, t_sphere_hit ); - q = vm_vec_dist_squared(&temp_edge_hit, &temp_sphere_hit); + //q = vm_vec_dist_squared(&temp_edge_hit, &temp_sphere_hit); // if ( fl_abs(q - Rs*Rs) > 2*WARN_DIST*Rs ) { // mprintf(("Estimated radius error: Estimate %f, actual %f Get Dave A.\n", fl_sqrt(q), Rs)); // } diff --git a/src/math/vecmat.cpp b/src/math/vecmat.cpp index b95f2cf..fe3a884 100644 --- a/src/math/vecmat.cpp +++ b/src/math/vecmat.cpp @@ -2306,7 +2306,6 @@ void vm_fvec_matrix_interpolate(matrix *goal_orient, matrix *orient, vector *w_i // normalize rotation axis and determine total rotation angle theta = vm_vec_mag(&rot_axis); if (theta < SMALL_NUM) { - theta = 0.0f; M_intermed = *orient; } else { vm_vec_scale ( &rot_axis, 1/theta ); @@ -2657,7 +2656,6 @@ void vm_find_bounding_sphere(vector *pnts, int num_pnts, vector *center, float * dia2 = ymax; } if ( zspan > maxspan ) { - maxspan = yspan; dia1 = zmin; dia2 = zmax; } diff --git a/src/menuui/barracks.cpp b/src/menuui/barracks.cpp index c845f3a..1df196b 100644 --- a/src/menuui/barracks.cpp +++ b/src/menuui/barracks.cpp @@ -1310,7 +1310,6 @@ void barracks_accept_new_pilot_callsign() } else { for (i=1; buf[i]; i++) { if (!isalpha(buf[i]) && !isdigit(buf[i]) && !strchr(VALID_PILOT_CHARS, buf[i])) { - z = 1; return; } } @@ -1318,7 +1317,6 @@ void barracks_accept_new_pilot_callsign() for (i=1; i= 0) { // always true for (i=0; ip_info.team); } diff --git a/src/network/multi_obj.cpp b/src/network/multi_obj.cpp index d2aa4cc..040235a 100644 --- a/src/network/multi_obj.cpp +++ b/src/network/multi_obj.cpp @@ -874,6 +874,8 @@ int multi_oo_unpack_data(net_player *pl, ubyte *data) float val; int i; + SDL_zero(subsystem_percent); + // get the data for the subsystems GET_DATA( n_subsystems ); for ( i = 0; i < n_subsystems; i++ ){ diff --git a/src/ship/aicode.cpp b/src/ship/aicode.cpp index a9ca573..dd170a2 100644 --- a/src/ship/aicode.cpp +++ b/src/ship/aicode.cpp @@ -12776,6 +12776,11 @@ int ai_acquire_depart_path(object *pl_objp, int parent_objnum) // take the closest path we can find int ship_bay_path; ship_bay_path = ai_find_closest_depart_path(aip, pm); + + if (ship_bay_path == -1) { + return -1; + } + path_index = sb->paths[ship_bay_path]; aip->submode_parm0 = ship_bay_path; sb->depart_flags |= (1<