From eecc36e08a21d1e7655c4962ac38fd947aeeb0f7 Mon Sep 17 00:00:00 2001 From: Taylor Richards Date: Tue, 24 Mar 2015 03:16:00 -0400 Subject: [PATCH] use SDL_arraysize() instead of sizeof() where appropriate --- src/anim/animplay.cpp | 18 +- src/bmpman/bmpman.cpp | 20 +-- src/cfile/cfile.cpp | 16 +- src/cfile/cfilesystem.cpp | 80 ++++----- src/cmdline/cmdline.cpp | 14 +- src/controlconfig/controlsconfig.cpp | 22 +-- src/controlconfig/controlsconfigcommon.cpp | 14 +- src/cutscene/cutscenes.cpp | 4 +- src/debugconsole/console.cpp | 16 +- src/demo/demo.cpp | 4 +- src/fireball/fireballs.cpp | 2 +- src/freespace2/freespace.cpp | 58 +++---- src/gamehelp/gameplayhelp.cpp | 10 +- src/gamesnd/eventmusic.cpp | 6 +- src/globalincs/systemvars.cpp | 2 +- src/globalincs/version.cpp | 6 +- src/graphics/2d.cpp | 4 +- src/graphics/font.cpp | 8 +- src/graphics/grgl1.cpp | 4 +- src/hud/hud.cpp | 34 ++-- src/hud/hudbrackets.cpp | 2 +- src/hud/hudconfig.cpp | 6 +- src/hud/hudescort.cpp | 4 +- src/hud/hudmessage.cpp | 8 +- src/hud/hudreticle.cpp | 2 +- src/hud/hudshield.cpp | 2 +- src/hud/hudsquadmsg.cpp | 16 +- src/hud/hudtarget.cpp | 22 +-- src/hud/hudtargetbox.cpp | 104 ++++++------ src/inetfile/cftp.cpp | 30 ++-- src/inetfile/chttpget.cpp | 12 +- src/io/keycontrol.cpp | 2 +- src/io/timer.cpp | 4 +- src/localization/localize.cpp | 80 ++++----- src/menuui/barracks.cpp | 40 ++--- src/menuui/credits.cpp | 8 +- src/menuui/mainhallmenu.cpp | 18 +- src/menuui/mainhalltemp.cpp | 4 +- src/menuui/optionsmenu.cpp | 2 +- src/menuui/optionsmenumulti.cpp | 6 +- src/menuui/playermenu.cpp | 28 ++-- src/menuui/readyroom.cpp | 36 ++-- src/menuui/snazzyui.cpp | 4 +- src/menuui/techmenu.cpp | 20 +-- src/menuui/trainingmenu.cpp | 4 +- src/mission/missionbriefcommon.cpp | 16 +- src/mission/missioncampaign.cpp | 78 ++++----- src/mission/missiongoals.cpp | 4 +- src/mission/missionhotkey.cpp | 6 +- src/mission/missionload.cpp | 10 +- src/mission/missionlog.cpp | 26 +-- src/mission/missionmessage.cpp | 22 +-- src/mission/missionparse.cpp | 30 ++-- src/mission/missiontraining.cpp | 18 +- src/missionui/chatbox.cpp | 10 +- src/missionui/missionbrief.cpp | 16 +- src/missionui/missioncmdbrief.cpp | 4 +- src/missionui/missiondebrief.cpp | 58 +++---- src/missionui/missionscreencommon.cpp | 2 +- src/missionui/missionshipchoice.cpp | 18 +- src/missionui/missionweaponchoice.cpp | 20 +-- src/missionui/redalert.cpp | 6 +- src/model/modelread.cpp | 66 ++++---- src/movie/mvelib.cpp | 2 +- src/nebula/neb.cpp | 4 +- src/network/multi.cpp | 2 +- src/network/multi_campaign.cpp | 16 +- src/network/multi_dogfight.cpp | 16 +- src/network/multi_endgame.cpp | 50 +++--- src/network/multi_ingame.cpp | 4 +- src/network/multi_kick.cpp | 2 +- src/network/multi_log.cpp | 10 +- src/network/multi_observer.cpp | 4 +- src/network/multi_options.cpp | 40 ++--- src/network/multi_pause.cpp | 2 +- src/network/multi_pinfo.cpp | 28 ++-- src/network/multi_pmsg.cpp | 38 ++--- src/network/multi_rate.cpp | 2 +- src/network/multi_respawn.cpp | 2 +- src/network/multi_team.cpp | 4 +- src/network/multi_update.cpp | 16 +- src/network/multi_voice.cpp | 2 +- src/network/multi_xfer.cpp | 10 +- src/network/multimsgs.cpp | 18 +- src/network/multiteamselect.cpp | 26 +-- src/network/multiui.cpp | 186 ++++++++++----------- src/network/multiutil.cpp | 40 ++--- src/network/psnet.cpp | 6 +- src/network/psnet2.cpp | 6 +- src/object/objectsnd.cpp | 8 +- src/osapi/outwnd.cpp | 10 +- src/palman/palman.cpp | 16 +- src/parse/parselo.cpp | 14 +- src/parse/sexp.cpp | 10 +- src/pcxutils/pcxutils.cpp | 24 +-- src/platform/platform.cpp | 8 +- src/playerman/managepilot.cpp | 40 ++--- src/playerman/playercontrol.cpp | 18 +- src/popup/popup.cpp | 8 +- src/radar/radar.cpp | 2 +- src/ship/aigoals.cpp | 4 +- src/ship/ship.cpp | 22 +-- src/ship/shiphit.cpp | 28 ++-- src/sound/sound.cpp | 4 +- src/starfield/starfield.cpp | 34 ++-- src/stats/medals.cpp | 30 ++-- src/stats/scoring.cpp | 2 +- src/stats/stats.cpp | 50 +++--- src/tgautils/tgautils.cpp | 12 +- src/ui/gadget.cpp | 10 +- src/ui/slider.cpp | 6 +- src/ui/window.cpp | 2 +- src/vcodec/codec1.cpp | 2 +- src/weapon/emp.cpp | 16 +- src/weapon/weapons.cpp | 4 +- 115 files changed, 1068 insertions(+), 1068 deletions(-) diff --git a/src/anim/animplay.cpp b/src/anim/animplay.cpp index 089f741..491c560 100644 --- a/src/anim/animplay.cpp +++ b/src/anim/animplay.cpp @@ -887,12 +887,12 @@ anim *anim_load(const char *real_filename) SDL_assert ( real_filename != NULL ); - SDL_strlcpy(name, real_filename, sizeof(name)); + SDL_strlcpy(name, real_filename, SDL_arraysize(name)); char *p = SDL_strchr( name, '.' ); if ( p ) { *p = 0; } - SDL_strlcat(name, ".ani", sizeof(name)); + SDL_strlcat(name, ".ani", SDL_arraysize(name)); ptr = first_anim; while (ptr) { @@ -913,7 +913,7 @@ anim *anim_load(const char *real_filename) ptr->flags = 0; ptr->next = first_anim; first_anim = ptr; - SDL_strlcpy(ptr->name, name, sizeof(ptr->name)); + SDL_strlcpy(ptr->name, name, SDL_arraysize(ptr->name)); ptr->instance_count = 0; ptr->width = 0; ptr->height = 0; @@ -1108,7 +1108,7 @@ int anim_write_frames_out(const char *filename) int i,j; ubyte **row_data; - SDL_strlcpy(root_name, filename, sizeof(root_name)); + SDL_strlcpy(root_name, filename, SDL_arraysize(root_name)); root_name[strlen(filename)-4] = 0; source_anim = anim_load(filename); @@ -1121,9 +1121,9 @@ int anim_write_frames_out(const char *filename) for ( i = 0; i < source_anim->total_frames; i++ ) { anim_get_next_raw_buffer(ai, 0, 0, 16); - SDL_strlcpy(pcxname, root_name, sizeof(pcxname)); - SDL_snprintf(buf, sizeof(buf), "%04d", i); - SDL_strlcat(pcxname, buf, sizeof(pcxname)); + SDL_strlcpy(pcxname, root_name, SDL_arraysize(pcxname)); + SDL_snprintf(buf, SDL_arraysize(buf), "%04d", i); + SDL_strlcat(pcxname, buf, SDL_arraysize(pcxname)); for ( j = 0; j < source_anim->height; j++ ) { row_data[j] = &ai->frame[j*source_anim->width]; @@ -1158,12 +1158,12 @@ void anim_display_info(const char *real_filename) int i, uncompressed, compressed, *key_frame_nums=NULL, tmp; char filename[MAX_FILENAME_LEN]; - SDL_strlcpy( filename, real_filename, sizeof(filename) ); + SDL_strlcpy( filename, real_filename, SDL_arraysize(filename) ); char *p = SDL_strchr( filename, '.' ); if ( p ) { *p = 0; } - SDL_strlcat( filename, ".ani", sizeof(filename) ); + SDL_strlcat( filename, ".ani", SDL_arraysize(filename) ); fp = cfopen(filename, "rb"); if ( !fp ) { diff --git a/src/bmpman/bmpman.cpp b/src/bmpman/bmpman.cpp index 4194073..257f47f 100644 --- a/src/bmpman/bmpman.cpp +++ b/src/bmpman/bmpman.cpp @@ -904,8 +904,8 @@ int bm_load_sub(const char *real_filename, const char *ext, int *handle) int i; char filename[MAX_FILENAME_LEN] = ""; - SDL_strlcpy( filename, real_filename, sizeof(filename) ); - SDL_strlcat( filename, ext, sizeof(filename) ); + SDL_strlcpy( filename, real_filename, SDL_arraysize(filename) ); + SDL_strlcat( filename, ext, SDL_arraysize(filename) ); for (i=0; i<(int)strlen(filename); i++ ){ filename[i] = char(tolower(filename[i])); } @@ -952,11 +952,11 @@ int bm_load( const char * real_filename ) // nice little trick for keeping standalone memory usage way low - always return a bogus bitmap if(Game_mode & GM_STANDALONE_SERVER){ - SDL_strlcpy(filename,"test128", sizeof(filename)); + SDL_strlcpy(filename,"test128", SDL_arraysize(filename)); } // make sure no one passed an extension - SDL_strlcpy( filename, real_filename, sizeof(filename) ); + SDL_strlcpy( filename, real_filename, SDL_arraysize(filename) ); char *p = SDL_strchr( filename, '.' ); if ( p ) { mprintf(( "Someone passed an extension to bm_load for file '%s'\n", real_filename )); @@ -973,7 +973,7 @@ int bm_load( const char * real_filename ) // found as a file case 0: found = 1; - SDL_strlcat(filename, ".pcx", sizeof(filename)); + SDL_strlcat(filename, ".pcx", SDL_arraysize(filename)); break; // found as pre-existing @@ -991,7 +991,7 @@ int bm_load( const char * real_filename ) // found as a file case 0: - SDL_strlcat(filename, ".tga", sizeof(filename)); + SDL_strlcat(filename, ".tga", SDL_arraysize(filename)); tga = 1; break; @@ -1159,14 +1159,14 @@ int bm_load_animation( const char *real_filename, int *nframes, int *fps, int ca if ( !bm_inited ) bm_init(); - SDL_strlcpy( filename, real_filename, sizeof(filename) ); + SDL_strlcpy( filename, real_filename, SDL_arraysize(filename) ); char *p = SDL_strchr( filename, '.' ); if ( p ) { mprintf(( "Someone passed an extension to bm_load_animation for file '%s'\n", real_filename )); //Int3(); *p = 0; } - SDL_strlcat( filename, ".ani", sizeof(filename) ); + SDL_strlcat( filename, ".ani", SDL_arraysize(filename) ); if ( (fp = cfopen(filename, "rb")) == NULL ) { // Error(LOCATION,"Could not open filename %s in bm_load_ani()\n", filename); @@ -1176,7 +1176,7 @@ int bm_load_animation( const char *real_filename, int *nframes, int *fps, int ca int reduced = 0; #ifndef NDEBUG // for debug of ANI sizes - SDL_strlcpy(the_anim.name, real_filename, sizeof(the_anim.name)); + SDL_strlcpy(the_anim.name, real_filename, SDL_arraysize(the_anim.name)); #endif anim_read_header(&the_anim, fp); if ( can_drop_frames ) { @@ -1917,7 +1917,7 @@ void bm_release(int handle) // Fill in bogus structures! // For debugging: - SDL_strlcpy( bm_bitmaps[n].filename, "IVE_BEEN_RELEASED!", sizeof(bm_bitmaps[0].filename) ); + SDL_strlcpy( bm_bitmaps[n].filename, "IVE_BEEN_RELEASED!", SDL_arraysize(bm_bitmaps[0].filename) ); bm_bitmaps[n].signature = 0xDEADBEEF; // a unique signature identifying the data bm_bitmaps[n].palette_checksum = 0xDEADBEEF; // checksum used to be sure bitmap is in current palette diff --git a/src/cfile/cfile.cpp b/src/cfile/cfile.cpp index 0fcf24c..f8b6f62 100644 --- a/src/cfile/cfile.cpp +++ b/src/cfile/cfile.cpp @@ -332,7 +332,7 @@ int cfile_in_root_dir(char *exe_path) // copy the path memset(path_copy, 0, 2048); - SDL_strlcpy(path_copy, exe_path, sizeof(path_copy)); + SDL_strlcpy(path_copy, exe_path, SDL_arraysize(path_copy)); // count how many slashes there are in the path tok = strtok(path_copy, DIR_SEPARATOR_STR); @@ -445,7 +445,7 @@ int cfile_flush_dir(int dir_type) int find_handle; _finddata_t find; - SDL_strlcat( filespec, "*", sizeof(filespec) ); + SDL_strlcat( filespec, "*", SDL_arraysize(filespec) ); find_handle = _findfirst( filespec, &find ); @@ -482,10 +482,10 @@ char *cf_add_ext(const char *filename, const char *ext) flen = strlen(filename); elen = strlen(ext); SDL_assert(flen < MAX_PATH_LEN); - SDL_strlcpy(path, filename, sizeof(path)); + SDL_strlcpy(path, filename, SDL_arraysize(path)); if ((flen < 4) || SDL_strcasecmp(path + flen - elen, ext)) { SDL_assert(flen + elen < MAX_PATH_LEN); - SDL_strlcat(path, ext, sizeof(path)); + SDL_strlcat(path, ext, SDL_arraysize(path)); } return path; @@ -644,7 +644,7 @@ CFILE *cfopen(const char *file_path, const char *mode, int type, int dir_type, b // For write-only files, require a full path or a path type if ( strpbrk(file_path, toks) ) { // Full path given? - SDL_strlcpy(longname, file_path, sizeof(longname)); + SDL_strlcpy(longname, file_path, SDL_arraysize(longname)); } else { // Path type given? SDL_assert( dir_type != CF_TYPE_ANY ); @@ -670,7 +670,7 @@ CFILE *cfopen(const char *file_path, const char *mode, int type, int dir_type, b int offset, size; char copy_file_path[MAX_PATH_LEN]; // FIX change in memory from cf_find_file_location - SDL_strlcpy(copy_file_path, file_path, sizeof(copy_file_path)); + SDL_strlcpy(copy_file_path, file_path, SDL_arraysize(copy_file_path)); if ( cf_find_file_location( copy_file_path, dir_type, longname, &size, &offset, localize ) ) { @@ -1509,7 +1509,7 @@ int cfile_init_paths() } // set root directory - SDL_strlcpy(Cfile_root_dir, t_path, sizeof(Cfile_root_dir)); + SDL_strlcpy(Cfile_root_dir, t_path, SDL_arraysize(Cfile_root_dir)); // free SDL copy SDL_free(t_path); t_path = NULL; @@ -1536,7 +1536,7 @@ int cfile_init_paths() } // set user/pref directory - SDL_strlcpy(Cfile_user_dir, u_path, sizeof(Cfile_user_dir)); + SDL_strlcpy(Cfile_user_dir, u_path, SDL_arraysize(Cfile_user_dir)); // free SDL copy SDL_free(u_path); u_path = NULL; diff --git a/src/cfile/cfilesystem.cpp b/src/cfile/cfilesystem.cpp index e17c75e..374bc13 100644 --- a/src/cfile/cfilesystem.cpp +++ b/src/cfile/cfilesystem.cpp @@ -264,11 +264,11 @@ int cf_get_packfile_count(cf_root *root) // count up how many packfiles we're gonna have packfile_count = 0; for (i=CF_TYPE_ROOT; ipath, sizeof(filespec) ); + SDL_strlcpy( filespec, root->path, SDL_arraysize(filespec) ); if(strlen(Pathtypes[i].path)){ - SDL_strlcat( filespec, Pathtypes[i].path, sizeof(filespec) ); - SDL_strlcat( filespec, DIR_SEPARATOR_STR, sizeof(filespec) ); + SDL_strlcat( filespec, Pathtypes[i].path, SDL_arraysize(filespec) ); + SDL_strlcat( filespec, DIR_SEPARATOR_STR, SDL_arraysize(filespec) ); } #ifdef PLAT_UNIX @@ -285,7 +285,7 @@ int cf_get_packfile_count(cf_root *root) closedir(dirp); } #else - SDL_strlcat( filespec, "*.vp", sizeof(filespec) ); + SDL_strlcat( filespec, "*.vp", SDL_arraysize(filespec) ); int find_handle; _finddata_t find; @@ -348,11 +348,11 @@ void cf_build_pack_list( cf_root *root ) // now just setup all the root info root_index = 0; for (i=CF_TYPE_ROOT; ipath, sizeof(filespec) ); + SDL_strlcpy( filespec, root->path, SDL_arraysize(filespec) ); if(strlen(Pathtypes[i].path)){ - SDL_strlcat( filespec, Pathtypes[i].path, sizeof(filespec) ); - SDL_strlcat( filespec, DIR_SEPARATOR_STR, sizeof(filespec) ); + SDL_strlcat( filespec, Pathtypes[i].path, SDL_arraysize(filespec) ); + SDL_strlcat( filespec, DIR_SEPARATOR_STR, SDL_arraysize(filespec) ); } #ifdef PLAT_UNIX @@ -368,7 +368,7 @@ void cf_build_pack_list( cf_root *root ) SDL_assert(root_index < temp_root_count); char fn[MAX_PATH_LEN]; - SDL_snprintf(fn, sizeof(fn), "%s/%s", filespec, dir->d_name); + SDL_snprintf(fn, SDL_arraysize(fn), "%s/%s", filespec, dir->d_name); struct stat buf; if (stat(fn, &buf) == -1) { @@ -383,14 +383,14 @@ void cf_build_pack_list( cf_root *root ) rptr_sort = &temp_roots_sort[root_index++]; // fill in all the proper info - SDL_strlcpy(rptr_sort->path, root->path, sizeof(rptr_sort->path)); + SDL_strlcpy(rptr_sort->path, root->path, SDL_arraysize(rptr_sort->path)); if(strlen(Pathtypes[i].path)){ - SDL_strlcat(rptr_sort->path, Pathtypes[i].path, sizeof(rptr_sort->path)); - SDL_strlcat(rptr_sort->path, "/", sizeof(rptr_sort->path)); + SDL_strlcat(rptr_sort->path, Pathtypes[i].path, SDL_arraysize(rptr_sort->path)); + SDL_strlcat(rptr_sort->path, "/", SDL_arraysize(rptr_sort->path)); } - SDL_strlcat(rptr_sort->path, dir->d_name, sizeof(rptr_sort->path)); + SDL_strlcat(rptr_sort->path, dir->d_name, SDL_arraysize(rptr_sort->path)); rptr_sort->roottype = CF_ROOTTYPE_PACK; rptr_sort->cf_type = i; } @@ -398,7 +398,7 @@ void cf_build_pack_list( cf_root *root ) closedir(dirp); } #else - SDL_strlcat( filespec, "*.vp", sizeof(filespec) ); + SDL_strlcat( filespec, "*.vp", SDL_arraysize(filespec) ); int find_handle; _finddata_t find; @@ -415,14 +415,14 @@ void cf_build_pack_list( cf_root *root ) rptr_sort = &temp_roots_sort[root_index++]; // fill in all the proper info - SDL_strlcpy(rptr_sort->path, root->path, sizeof(rptr_sort->path)); + SDL_strlcpy(rptr_sort->path, root->path, SDL_arraysize(rptr_sort->path)); if(strlen(Pathtypes[i].path)){ - SDL_strlcat(rptr_sort->path, Pathtypes[i].path, sizeof(rptr_sort->path) ); - SDL_strlcat(rptr_sort->path, "\\", sizeof(rptr_sort->path)); + SDL_strlcat(rptr_sort->path, Pathtypes[i].path, SDL_arraysize(rptr_sort->path) ); + SDL_strlcat(rptr_sort->path, "\\", SDL_arraysize(rptr_sort->path)); } - SDL_strlcat(rptr_sort->path, find.name, sizeof(rptr_sort->path) ); + SDL_strlcat(rptr_sort->path, find.name, SDL_arraysize(rptr_sort->path) ); rptr_sort->roottype = CF_ROOTTYPE_PACK; rptr_sort->cf_type = i; } @@ -444,11 +444,11 @@ void cf_build_pack_list( cf_root *root ) cf_root *new_root; for(i=0; ipath, root->path, sizeof(new_root->path) ); + SDL_strlcpy( new_root->path, root->path, SDL_arraysize(new_root->path) ); // mwa -- 4/2/98 put in the next 2 lines because the path name needs to be there // to find the files. - SDL_strlcpy(new_root->path, temp_roots_sort[i].path, sizeof(new_root->path)); + SDL_strlcpy(new_root->path, temp_roots_sort[i].path, SDL_arraysize(new_root->path)); new_root->roottype = CF_ROOTTYPE_PACK; } @@ -466,11 +466,11 @@ void cf_build_root_list(const char *extras_dir) // ================================================================ // have user's writable directory as default for loading and saving files root = cf_create_root(); - SDL_strlcpy( root->path, Cfile_user_dir, sizeof(root->path) ); + SDL_strlcpy( root->path, Cfile_user_dir, SDL_arraysize(root->path) ); // do we already have a slash? as in the case of a root directory install if(strlen(root->path) && (root->path[strlen(root->path)-1] != DIR_SEPARATOR_CHAR)){ - SDL_strlcat(root->path, DIR_SEPARATOR_STR, sizeof(root->path)); // put trailing backslash on for easier path construction + SDL_strlcat(root->path, DIR_SEPARATOR_STR, SDL_arraysize(root->path)); // put trailing backslash on for easier path construction } root->roottype = CF_ROOTTYPE_PATH; @@ -481,11 +481,11 @@ void cf_build_root_list(const char *extras_dir) //====================================================== // Next, use the executable's directory for game data root = cf_create_root(); - SDL_strlcpy( root->path, Cfile_root_dir, sizeof(root->path) ); + SDL_strlcpy( root->path, Cfile_root_dir, SDL_arraysize(root->path) ); // do we already have a slash? as in the case of a root directory install if(strlen(root->path) && (root->path[strlen(root->path)-1] != DIR_SEPARATOR_CHAR)){ - SDL_strlcat(root->path, DIR_SEPARATOR_STR, sizeof(root->path)); // put trailing backslash on for easier path construction + SDL_strlcat(root->path, DIR_SEPARATOR_STR, SDL_arraysize(root->path)); // put trailing backslash on for easier path construction } root->roottype = CF_ROOTTYPE_PATH; @@ -498,7 +498,7 @@ void cf_build_root_list(const char *extras_dir) // Check the real CD if one... if ( extras_dir && strlen(extras_dir) ) { root = cf_create_root(); - SDL_strlcpy( root->path, extras_dir, sizeof(root->path) ); + SDL_strlcpy( root->path, extras_dir, SDL_arraysize(root->path) ); root->roottype = CF_ROOTTYPE_PATH; //====================================================== @@ -514,7 +514,7 @@ int is_ext_in_list( const char *ext_list, char *ext ) { char tmp_ext[128]; - SDL_strlcpy( tmp_ext, ext, sizeof(tmp_ext) ); + SDL_strlcpy( tmp_ext, ext, SDL_arraysize(tmp_ext) ); SDL_strlwr(tmp_ext); if ( strstr(ext_list, tmp_ext )) { return 1; @@ -535,11 +535,11 @@ void cf_search_root_path(int root_index) for (i=CF_TYPE_ROOT; ipath, sizeof(search_path) ); + SDL_strlcpy( search_path, root->path, SDL_arraysize(search_path) ); if(strlen(Pathtypes[i].path)){ - SDL_strlcat( search_path, Pathtypes[i].path, sizeof(search_path) ); - SDL_strlcat( search_path, DIR_SEPARATOR_STR, sizeof(search_path) ); + SDL_strlcat( search_path, Pathtypes[i].path, SDL_arraysize(search_path) ); + SDL_strlcat( search_path, DIR_SEPARATOR_STR, SDL_arraysize(search_path) ); } #ifdef PLAT_UNIX @@ -577,7 +577,7 @@ void cf_search_root_path(int root_index) // Found a file!!!! cf_file *file = cf_create_file(); - SDL_strlcpy( file->name_ext, dir->d_name, sizeof(file->name_ext) ); + SDL_strlcpy( file->name_ext, dir->d_name, SDL_arraysize(file->name_ext) ); file->root_index = root_index; file->pathtype_index = i; @@ -595,7 +595,7 @@ void cf_search_root_path(int root_index) closedir(dirp); } #else - SDL_strlcat( search_path, "*.*", sizeof(search_path) ); + SDL_strlcat( search_path, "*.*", SDL_arraysize(search_path) ); int find_handle; _finddata_t find; @@ -612,7 +612,7 @@ void cf_search_root_path(int root_index) // Found a file!!!! cf_file *file = cf_create_file(); - SDL_strlcpy( file->name_ext, find.name, sizeof(file->name_ext) ); + SDL_strlcpy( file->name_ext, find.name, SDL_arraysize(file->name_ext) ); file->root_index = root_index; file->pathtype_index = i; file->write_time = find.time_write; @@ -680,7 +680,7 @@ void cf_search_root_pack(int root_index) char search_path[CF_MAX_PATHNAME_LENGTH]; - SDL_strlcpy( search_path, "", sizeof(search_path) ); + SDL_strlcpy( search_path, "", SDL_arraysize(search_path) ); // Go through all the files for (i=0; iname_ext, find.filename, sizeof(file->name_ext) ); + SDL_strlcpy( file->name_ext, find.filename, SDL_arraysize(file->name_ext) ); file->root_index = root_index; file->pathtype_index = j; file->write_time = find.write_time; @@ -909,7 +909,7 @@ int cf_find_file_location( const char *filespec, int pathtype, char *pack_filena if (localize) { // create localized filespec char loc_filespec[MAX_PATH_LEN]; - SDL_strlcpy(loc_filespec, filespec, sizeof(loc_filespec)); + SDL_strlcpy(loc_filespec, filespec, SDL_arraysize(loc_filespec)); lcl_add_dir_to_path_with_filename(loc_filespec, sizeof(loc_filespec)); if ( !SDL_strcasecmp(loc_filespec, f->name_ext) ) { @@ -982,7 +982,7 @@ int cf_file_already_in_list( int num_files, char **list, char *filename ) char name_no_extension[MAX_PATH_LEN]; - SDL_strlcpy(name_no_extension, filename, sizeof(name_no_extension)); + SDL_strlcpy(name_no_extension, filename, SDL_arraysize(name_no_extension)); char *p = SDL_strchr( name_no_extension, '.' ); if ( p ) *p = 0; @@ -1163,7 +1163,7 @@ int cf_file_already_in_list_preallocated( int num_files, char arr[][MAX_FILENAME char name_no_extension[MAX_PATH_LEN]; - SDL_strlcpy(name_no_extension, filename, sizeof(name_no_extension)); + SDL_strlcpy(name_no_extension, filename, SDL_arraysize(name_no_extension)); char *p = SDL_strchr( name_no_extension, '.' ); if ( p ) *p = 0; @@ -1385,7 +1385,7 @@ void cf_create_default_path_string( char *path, int pathtype, const char *filena if (localize) { // create copy of path char temp_path[MAX_PATH_LEN]; - SDL_strlcpy(temp_path, path, sizeof(temp_path)); + SDL_strlcpy(temp_path, path, SDL_arraysize(temp_path)); // localize the path lcl_add_dir_to_path_with_filename(path, MAX_PATH_LEN); @@ -1395,7 +1395,7 @@ void cf_create_default_path_string( char *path, int pathtype, const char *filena if (fp) { fclose(fp); } else { - SDL_strlcpy(path, temp_path, sizeof(temp_path)); + SDL_strlcpy(path, temp_path, SDL_arraysize(temp_path)); } } } diff --git a/src/cmdline/cmdline.cpp b/src/cmdline/cmdline.cpp index a1eba00..8517450 100644 --- a/src/cmdline/cmdline.cpp +++ b/src/cmdline/cmdline.cpp @@ -339,7 +339,7 @@ static void parm_stuff_args(cmdline_parm *parm, char *cmdline) char buffer[1024] = { 0 }; char *dest = buffer; - while ((*cmdline != 0) && (*cmdline != '-') && ((size_t)(dest-buffer) < sizeof(buffer))) { + while ((*cmdline != 0) && (*cmdline != '-') && ((size_t)(dest-buffer) < SDL_arraysize(buffer))) { *dest++ = *cmdline++; } @@ -380,14 +380,14 @@ static void os_parse_parms(char *cmdline) for (parmp = GET_FIRST(&Parm_list); parmp !=END_OF_LIST(&Parm_list); parmp = GET_NEXT(parmp) ) { // check with space to make sure we get the correct option name - SDL_snprintf(pname, sizeof(pname)-1, "%s ", parmp->name); + SDL_snprintf(pname, SDL_arraysize(pname)-1, "%s ", parmp->name); cmdline_offset = strstr(cmdline, pname); if (cmdline_offset) { cmdline_offset += strlen(parmp->name); } else if (parmp->name2 != NULL) { // check with space to make sure we get the correct option name - SDL_snprintf(pname, sizeof(pname)-1, "%s ", parmp->name2); + SDL_snprintf(pname, SDL_arraysize(pname)-1, "%s ", parmp->name2); cmdline_offset = strstr(cmdline, pname); if (cmdline_offset) { @@ -523,13 +523,13 @@ static void os_init_cmdline(const char *cmdline) mprintf(("Command line: ")); - SDL_snprintf(cmdname, sizeof(cmdname), "%s%s%scmdline.cfg", Cfile_user_dir, Pathtypes[CF_TYPE_DATA].path, DIR_SEPARATOR_STR); + SDL_snprintf(cmdname, SDL_arraysize(cmdname), "%s%s%scmdline.cfg", Cfile_user_dir, Pathtypes[CF_TYPE_DATA].path, DIR_SEPARATOR_STR); fp = fopen (cmdname, "rt"); if ( !fp ) { // if not already found check exec directory - SDL_snprintf(cmdname, sizeof(cmdname), "%s%s%scmdline.cfg", Cfile_root_dir, Pathtypes[CF_TYPE_DATA].path, DIR_SEPARATOR_STR); + SDL_snprintf(cmdname, SDL_arraysize(cmdname), "%s%s%scmdline.cfg", Cfile_root_dir, Pathtypes[CF_TYPE_DATA].path, DIR_SEPARATOR_STR); fp = fopen (cmdname, "rt"); } @@ -538,7 +538,7 @@ static void os_init_cmdline(const char *cmdline) if ( fp ) { char buf[1024] = { 0 }, *p; - while (fgets(buf, sizeof(buf), fp) != NULL) { + while (fgets(buf, SDL_arraysize(buf), fp) != NULL) { // replace the newline character with a NUL: if ( (p = strrchr(buf, '\n')) != NULL ) { *p = '\0'; @@ -546,7 +546,7 @@ static void os_init_cmdline(const char *cmdline) // make sure that we have a trailing space for option finding to // work properly with single args - SDL_strlcat(buf, " ", sizeof(buf)); + SDL_strlcat(buf, " ", SDL_arraysize(buf)); mprintf(("%s", buf)); diff --git a/src/controlconfig/controlsconfig.cpp b/src/controlconfig/controlsconfig.cpp index 84a7f6f..43e4900 100644 --- a/src/controlconfig/controlsconfig.cpp +++ b/src/controlconfig/controlsconfig.cpp @@ -1775,7 +1775,7 @@ void control_config_do_frame(float frametime) Ui_window.process(0); if (k == SDLK_ESCAPE) { - SDL_strlcpy(bound_string, XSTR( "Canceled", 206), sizeof(bound_string)); + SDL_strlcpy(bound_string, XSTR( "Canceled", 206), SDL_arraysize(bound_string)); bound_timestamp = timestamp(2500); control_config_do_cancel(); @@ -1790,7 +1790,7 @@ void control_config_do_frame(float frametime) if (bind) { if (Axis_override >= 0) { control_config_bind_axis(z, Axis_override); - SDL_strlcpy(bound_string, Joy_axis_text[Axis_override], sizeof(bound_string)); + SDL_strlcpy(bound_string, Joy_axis_text[Axis_override], SDL_arraysize(bound_string)); gr_force_fit_string(bound_string, 39, Conflict_wnd_coords[gr_screen.res][CONTROL_W_COORD]); bound_timestamp = timestamp(2500); control_config_conflict_check(); @@ -1826,7 +1826,7 @@ void control_config_do_frame(float frametime) } if (k == SDLK_ESCAPE) { - SDL_strlcpy(bound_string, XSTR( "Canceled", 206), sizeof(bound_string)); + SDL_strlcpy(bound_string, XSTR( "Canceled", 206), SDL_arraysize(bound_string)); bound_timestamp = timestamp(2500); control_config_do_cancel(); @@ -1856,7 +1856,7 @@ void control_config_do_frame(float frametime) SDL_assert(!(z & JOY_AXIS)); control_config_bind_key(z, k); - SDL_strlcpy(bound_string, textify_scancode(k), sizeof(bound_string)); + SDL_strlcpy(bound_string, textify_scancode(k), SDL_arraysize(bound_string)); gr_force_fit_string(bound_string, 39, Conflict_wnd_coords[gr_screen.res][CONTROL_W_COORD]); bound_timestamp = timestamp(2500); control_config_conflict_check(); @@ -1870,7 +1870,7 @@ void control_config_do_frame(float frametime) SDL_assert(!(z & JOY_AXIS)); control_config_bind_joy(z, i); - SDL_strlcpy(bound_string, Joy_button_text[i], sizeof(bound_string)); + SDL_strlcpy(bound_string, Joy_button_text[i], SDL_arraysize(bound_string)); gr_force_fit_string(bound_string, 39, Conflict_wnd_coords[gr_screen.res][CONTROL_W_COORD]); bound_timestamp = timestamp(2500); control_config_conflict_check(); @@ -1893,7 +1893,7 @@ void control_config_do_frame(float frametime) SDL_assert(!(z & JOY_AXIS)); control_config_bind_joy(z, i); - SDL_strlcpy(bound_string, Joy_button_text[i], sizeof(bound_string)); + SDL_strlcpy(bound_string, Joy_button_text[i], SDL_arraysize(bound_string)); gr_force_fit_string(bound_string, 39, Conflict_wnd_coords[gr_screen.res][CONTROL_W_COORD]); bound_timestamp = timestamp(2500); control_config_conflict_check(); @@ -2163,7 +2163,7 @@ void control_config_do_frame(float frametime) // setup the conflict string char conflict_str[512] = ""; - SDL_strlcpy(conflict_str, XSTR("Conflict!", 205), sizeof(conflict_str)); + SDL_strlcpy(conflict_str, XSTR("Conflict!", 205), SDL_arraysize(conflict_str)); int sw, sh; gr_get_string_size(&sw, &sh, conflict_str); @@ -2239,7 +2239,7 @@ void control_config_do_frame(float frametime) gr_get_string_size(&w, NULL, str); gr_printf(x - w / 2, y - font_height, str); - SDL_strlcpy(buf, XSTR(Control_config[i].text, CONTROL_CONFIG_XSTR + i), sizeof(buf)); + SDL_strlcpy(buf, XSTR(Control_config[i].text, CONTROL_CONFIG_XSTR + i), SDL_arraysize(buf)); gr_force_fit_string(buf, 255, Conflict_wnd_coords[gr_screen.res][CONTROL_W_COORD]); gr_get_string_size(&w, NULL, buf); gr_printf(x - w / 2, y, buf); @@ -2286,7 +2286,7 @@ void control_config_do_frame(float frametime) gr_set_color_fast(c); if (Cc_lines[line].label) { - SDL_strlcpy(buf, Cc_lines[line].label, sizeof(buf)); + SDL_strlcpy(buf, Cc_lines[line].label, SDL_arraysize(buf)); gr_force_fit_string(buf, 255, Control_list_ctrl_w[gr_screen.res]); gr_printf(Control_list_coords[gr_screen.res][CONTROL_X_COORD], y, buf); } @@ -2303,7 +2303,7 @@ void control_config_do_frame(float frametime) } else { if (k >= 0) { - SDL_strlcpy(buf, textify_scancode(k), sizeof(buf)); + SDL_strlcpy(buf, textify_scancode(k), SDL_arraysize(buf)); if (Conflicts[z].key >= 0) { if (c == &Color_text_normal) gr_set_color_fast(&Color_text_error); @@ -2334,7 +2334,7 @@ void control_config_do_frame(float frametime) } if (j >= 0) { - SDL_strlcpy(buf, Joy_button_text[j], sizeof(buf)); + SDL_strlcpy(buf, Joy_button_text[j], SDL_arraysize(buf)); if (Conflicts[z].joy >= 0) { if (c == &Color_text_normal) gr_set_color_fast(&Color_text_error); diff --git a/src/controlconfig/controlsconfigcommon.cpp b/src/controlconfig/controlsconfigcommon.cpp index 6b4f2d0..f025e89 100644 --- a/src/controlconfig/controlsconfigcommon.cpp +++ b/src/controlconfig/controlsconfigcommon.cpp @@ -1080,27 +1080,27 @@ const char *textify_scancode(int code) *text = 0; if (code & KEY_ALTED) { if(Lcl_gr){ - SDL_strlcat(text, "Alt-", sizeof(text)); + SDL_strlcat(text, "Alt-", SDL_arraysize(text)); } else if(Lcl_fr){ - SDL_strlcat(text, "Alt-", sizeof(text)); + SDL_strlcat(text, "Alt-", SDL_arraysize(text)); } else { - SDL_strlcat(text, "Alt-", sizeof(text)); + SDL_strlcat(text, "Alt-", SDL_arraysize(text)); } } if (code & KEY_SHIFTED) { if(Lcl_gr){ - SDL_strlcat(text, "Shift-", sizeof(text)); + SDL_strlcat(text, "Shift-", SDL_arraysize(text)); } else if(Lcl_fr){ - SDL_strlcat(text, "Maj.-", sizeof(text)); + SDL_strlcat(text, "Maj.-", SDL_arraysize(text)); } else { - SDL_strlcat(text, "Shift-", sizeof(text)); + SDL_strlcat(text, "Shift-", SDL_arraysize(text)); } } code = SDL_GetScancodeFromKey(code & KEY_MASK); - SDL_strlcat(text, Scan_code_text[code], sizeof(text)); + SDL_strlcat(text, Scan_code_text[code], SDL_arraysize(text)); return text; } //XSTR:ON diff --git a/src/cutscene/cutscenes.cpp b/src/cutscene/cutscenes.cpp index af0ccc9..53d099b 100644 --- a/src/cutscene/cutscenes.cpp +++ b/src/cutscene/cutscenes.cpp @@ -399,14 +399,14 @@ void cutscenes_screen_play() SDL_assert( (Selected_line >= 0) && (Selected_line < Num_files) ); which_cutscene = Cutscene_list[Selected_line]; - SDL_strlcpy(name, Cutscenes[which_cutscene].filename, sizeof(name)); + SDL_strlcpy(name, Cutscenes[which_cutscene].filename, SDL_arraysize(name)); full_name = cf_add_ext(name, NOX(".mve")); int rval = movie_play(full_name); if ( !rval ) { char str[256]; - SDL_snprintf(str, sizeof(str), XSTR( "Unable to play movie %s.", 204), Cutscenes[which_cutscene].name ); + SDL_snprintf(str, SDL_arraysize(str), XSTR( "Unable to play movie %s.", 204), Cutscenes[which_cutscene].name ); popup(0, 1, POPUP_OK, str ); } } diff --git a/src/debugconsole/console.cpp b/src/debugconsole/console.cpp index 3b4a591..1299c54 100644 --- a/src/debugconsole/console.cpp +++ b/src/debugconsole/console.cpp @@ -262,7 +262,7 @@ void scanner_downshift_word() int offset = 'a' - 'A'; char * tp; - SDL_strlcpy( scanner_word_string, scanner_token_string, sizeof(scanner_word_string) ); + SDL_strlcpy( scanner_word_string, scanner_token_string, SDL_arraysize(scanner_word_string) ); tp = scanner_word_string; do { @@ -618,7 +618,7 @@ void dc_printf(const char *format, ...) va_list args; va_start(args, format); - SDL_vsnprintf(tmp, sizeof(tmp), format, args); + SDL_vsnprintf(tmp, SDL_arraysize(tmp), format, args); va_end(args); char *p = tmp; @@ -682,7 +682,7 @@ void debug_console( void (*_func)() ) case SDLK_F3: if ( last_oldcommand > -1 ) { - SDL_strlcpy( command_line, oldcommand_line[last_oldcommand], sizeof(command_line) ); + SDL_strlcpy( command_line, oldcommand_line[last_oldcommand], SDL_arraysize(command_line) ); command_line_pos = strlen(command_line); command_line[command_line_pos] = 0; } @@ -694,7 +694,7 @@ void debug_console( void (*_func)() ) command_scroll = last_oldcommand; if ( command_scroll > -1 ) { - SDL_strlcpy( command_line, oldcommand_line[command_scroll], sizeof(command_line) ); + SDL_strlcpy( command_line, oldcommand_line[command_scroll], SDL_arraysize(command_line) ); command_line_pos = strlen(command_line); command_line[command_line_pos] = 0; } @@ -707,7 +707,7 @@ void debug_console( void (*_func)() ) if (command_scroll>last_oldcommand) command_scroll = -1; if ( command_scroll > -1 ) { - SDL_strlcpy( command_line, oldcommand_line[command_scroll], sizeof(command_line) ); + SDL_strlcpy( command_line, oldcommand_line[command_scroll], SDL_arraysize(command_line) ); command_line_pos = strlen(command_line); command_line[command_line_pos] = 0; } @@ -728,13 +728,13 @@ void debug_console( void (*_func)() ) if ( !found ) { if ( last_oldcommand < DEBUG_HISTORY-1 ) { last_oldcommand++; - SDL_strlcpy( oldcommand_line[last_oldcommand], command_line, sizeof(oldcommand_line[0]) ); + SDL_strlcpy( oldcommand_line[last_oldcommand], command_line, SDL_arraysize(oldcommand_line[0]) ); } else { int i; for (i=0; isubmodel[sm].name, total); + SDL_snprintf(str, SDL_arraysize(str), "Submodel %s total : %d faces\n", pm->submodel[sm].name, total); cfputs(str, out); *out_total += total + sub_total; @@ -6554,7 +6554,7 @@ void game_spew_pof_info() } counted = 0; for(idx=0; idx= 0){ pm = model_get(model_num); @@ -6572,16 +6572,16 @@ void game_spew_pof_info() total = submodel_get_num_polys(model_num, i); model_total += total; - SDL_snprintf(str, sizeof(str), "Submodel %s total : %d faces\n", pm->submodel[i].name, total); + SDL_snprintf(str, SDL_arraysize(str), "Submodel %s total : %d faces\n", pm->submodel[i].name, total); cfputs(str, out); } - SDL_snprintf(str, sizeof(str), "Model total %d\n", model_total); + SDL_snprintf(str, SDL_arraysize(str), "Model total %d\n", model_total); cfputs(str, out); // now go through and do it by LOD cfputs("BY LOD\n\n", out); for(i=0; in_detail_levels; i++){ - SDL_snprintf(str, sizeof(str), "LOD %d\n", i); + SDL_snprintf(str, SDL_arraysize(str), "LOD %d\n", i); cfputs(str, out); // submodels @@ -6592,14 +6592,14 @@ void game_spew_pof_info() game_spew_pof_info_sub(model_num, pm, j, out, &total, &destroyed_total); } - SDL_snprintf(str, sizeof(str), "Submodel %s total : %d faces\n", pm->submodel[pm->detail[i]].name, root_total); + SDL_snprintf(str, SDL_arraysize(str), "Submodel %s total : %d faces\n", pm->submodel[pm->detail[i]].name, root_total); cfputs(str, out); - SDL_snprintf(str, sizeof(str), "TOTAL: %d\n", total + root_total); + SDL_snprintf(str, SDL_arraysize(str), "TOTAL: %d\n", total + root_total); cfputs(str, out); - SDL_snprintf(str, sizeof(str), "TOTAL not counting destroyed faces %d\n", (total + root_total) - destroyed_total); + SDL_snprintf(str, SDL_arraysize(str), "TOTAL not counting destroyed faces %d\n", (total + root_total) - destroyed_total); cfputs(str, out); - SDL_snprintf(str, sizeof(str), "TOTAL destroyed faces %d\n\n", destroyed_total); + SDL_snprintf(str, SDL_arraysize(str), "TOTAL destroyed faces %d\n\n", destroyed_total); cfputs(str, out); } cfputs("------------------------------------------------------------------------\n\n", out); @@ -7128,7 +7128,7 @@ void game_show_event_debug(float frametime) z = Event_debug_index[k]; if (z & EVENT_DEBUG_EVENT) { z &= 0x7fff; - SDL_snprintf(buf, sizeof(buf), NOX("%s%s (%s) %s%d %d"), (Mission_events[z].flags & MEF_CURRENT) ? NOX("* ") : "", + SDL_snprintf(buf, SDL_arraysize(buf), NOX("%s%s (%s) %s%d %d"), (Mission_events[z].flags & MEF_CURRENT) ? NOX("* ") : "", Mission_events[z].name, Mission_events[z].result ? NOX("True") : NOX("False"), (Mission_events[z].chain_delay < 0) ? "" : NOX("x "), Mission_events[z].repeat_count, Mission_events[z].interval); @@ -7139,31 +7139,31 @@ void game_show_event_debug(float frametime) while (i--) buf[i] = ' '; - SDL_strlcat(buf, Sexp_nodes[z & 0x7fff].text, sizeof(buf)); + SDL_strlcat(buf, Sexp_nodes[z & 0x7fff].text, SDL_arraysize(buf)); switch (Sexp_nodes[z & 0x7fff].value) { case SEXP_TRUE: - SDL_strlcat(buf, NOX(" (True)"), sizeof(buf)); + SDL_strlcat(buf, NOX(" (True)"), SDL_arraysize(buf)); break; case SEXP_FALSE: - SDL_strlcat(buf, NOX(" (False)"), sizeof(buf)); + SDL_strlcat(buf, NOX(" (False)"), SDL_arraysize(buf)); break; case SEXP_KNOWN_TRUE: - SDL_strlcat(buf, NOX(" (Always true)"), sizeof(buf)); + SDL_strlcat(buf, NOX(" (Always true)"), SDL_arraysize(buf)); break; case SEXP_KNOWN_FALSE: - SDL_strlcat(buf, NOX(" (Always false)"), sizeof(buf)); + SDL_strlcat(buf, NOX(" (Always false)"), SDL_arraysize(buf)); break; case SEXP_CANT_EVAL: - SDL_strlcat(buf, NOX(" (Can't eval)"), sizeof(buf)); + SDL_strlcat(buf, NOX(" (Can't eval)"), SDL_arraysize(buf)); break; case SEXP_NAN: case SEXP_NAN_FOREVER: - SDL_strlcat(buf, NOX(" (Not a number)"), sizeof(buf)); + SDL_strlcat(buf, NOX(" (Not a number)"), SDL_arraysize(buf)); break; } } @@ -7214,7 +7214,7 @@ void Time_model( int modelnum ) int bmp_num = pm->original_textures[i]; if ( bmp_num > -1 ) { - bm_get_palette(pm->original_textures[i], pal, filename, sizeof(filename) ); + bm_get_palette(pm->original_textures[i], pal, filename, SDL_arraysize(filename) ); int w,h; bm_get_info( pm->original_textures[i],&w, &h ); diff --git a/src/gamehelp/gameplayhelp.cpp b/src/gamehelp/gameplayhelp.cpp index db7642b..bfca36b 100644 --- a/src/gamehelp/gameplayhelp.cpp +++ b/src/gamehelp/gameplayhelp.cpp @@ -292,20 +292,20 @@ void gameplay_help_blit_control_line(int x, int y, int id) buf[0] = 0; if ( ci->key_id >= 0 ) { - SDL_strlcpy(buf, textify_scancode(ci->key_id), sizeof(buf)); + SDL_strlcpy(buf, textify_scancode(ci->key_id), SDL_arraysize(buf)); has_key=1; } if ( ci->joy_id >= 0 ) { if ( has_key ) { - SDL_strlcat(buf, XSTR( ", ", 129), sizeof(buf)); + SDL_strlcat(buf, XSTR( ", ", 129), SDL_arraysize(buf)); } - SDL_strlcat(buf, Joy_button_text[ci->joy_id], sizeof(buf)); + SDL_strlcat(buf, Joy_button_text[ci->joy_id], SDL_arraysize(buf)); has_joy=1; } if ( !has_key && !has_joy ) { - SDL_strlcpy(buf, XSTR( "no binding", 130), sizeof(buf)); + SDL_strlcpy(buf, XSTR( "no binding", 130), SDL_arraysize(buf)); } gr_string(x,y,buf); @@ -329,7 +329,7 @@ void gameplay_help_set_title(const char *title) gr_set_color_fast(&Color_bright); gr_printf(0x8000,sy,title); - SDL_snprintf(buf, sizeof(buf), XSTR( "Page %d of %d", 132), Current_help_page+1, Gp_last_screen+1); + SDL_snprintf(buf, SDL_arraysize(buf), XSTR( "Page %d of %d", 132), Current_help_page+1, Gp_last_screen+1); gr_printf(0x8000,sy+gr_get_font_height()+2,buf); gr_set_color_fast(&Color_normal); } diff --git a/src/gamesnd/eventmusic.cpp b/src/gamesnd/eventmusic.cpp index 91f2c6c..7eadb55 100644 --- a/src/gamesnd/eventmusic.cpp +++ b/src/gamesnd/eventmusic.cpp @@ -1119,7 +1119,7 @@ void event_music_parse_musictbl() char *token; int count = 0; token = strtok( line_buf, NOX(" ,\t")); - SDL_strlcpy(fname, token, sizeof(fname)); + SDL_strlcpy(fname, token, SDL_arraysize(fname)); while ( token != NULL ) { token = strtok( NULL, NOX(" ,\t") ); if ( token == NULL ) { @@ -1157,13 +1157,13 @@ void event_music_parse_musictbl() required_string("$Name:"); stuff_string(fname, F_PATHNAME, NULL); SDL_assert( strlen(fname) < (NAME_LENGTH-1) ); - SDL_strlcpy( Spooled_music[Num_music_files].name, fname, sizeof(Spooled_music[0].name) ); + SDL_strlcpy( Spooled_music[Num_music_files].name, fname, SDL_arraysize(Spooled_music[0].name) ); required_string("$Filename:"); stuff_string(fname, F_PATHNAME, NULL); if ( SDL_strcasecmp(fname, NOX("none.wav")) ) { SDL_assert( strlen(fname) < (MAX_FILENAME_LEN-1) ); - SDL_strlcpy( Spooled_music[Num_music_files].filename, fname, sizeof(Spooled_music[0].filename) ); + SDL_strlcpy( Spooled_music[Num_music_files].filename, fname, SDL_arraysize(Spooled_music[0].filename) ); } Num_music_files++; diff --git a/src/globalincs/systemvars.cpp b/src/globalincs/systemvars.cpp index 0e29fa5..c372240 100644 --- a/src/globalincs/systemvars.cpp +++ b/src/globalincs/systemvars.cpp @@ -428,7 +428,7 @@ DCF(monitor,"Monitors game performace") } else { Monitor_inited = 1; - SDL_strlcpy( Monitor_filename, Dc_arg, sizeof(Monitor_filename) ); + SDL_strlcpy( Monitor_filename, Dc_arg, SDL_arraysize(Monitor_filename) ); // Reset them all int i; diff --git a/src/globalincs/version.cpp b/src/globalincs/version.cpp index 0c58ae9..dbbb91b 100644 --- a/src/globalincs/version.cpp +++ b/src/globalincs/version.cpp @@ -78,8 +78,8 @@ int version_compare(const char *filename, int *u_major, int *u_minor, int *u_bui // grab the last line in file which isn't empty and isn't a comment char buffer[MAX_LINE_LENGTH+1], verbuffer[MAX_LINE_LENGTH+1]; - SDL_strlcpy(verbuffer, "", sizeof(verbuffer)); - SDL_strlcpy(buffer, "", sizeof(buffer)); + SDL_strlcpy(verbuffer, "", SDL_arraysize(verbuffer)); + SDL_strlcpy(buffer, "", SDL_arraysize(buffer)); while ( !feof(f) ) { // Read the line into a temporary buffer fgets(buffer, MAX_LINE_LENGTH, f); @@ -95,7 +95,7 @@ int version_compare(const char *filename, int *u_major, int *u_minor, int *u_bui if (buffer[0] == VERSION_FILE_COMMENT_CHAR) continue; // Line is a good one, so save it... - SDL_strlcpy(verbuffer, buffer, sizeof(verbuffer)); + SDL_strlcpy(verbuffer, buffer, SDL_arraysize(verbuffer)); } fclose(f); diff --git a/src/graphics/2d.cpp b/src/graphics/2d.cpp index 21d3640..4bdef20 100644 --- a/src/graphics/2d.cpp +++ b/src/graphics/2d.cpp @@ -605,7 +605,7 @@ void gr_set_palette( const char *name, ubyte * palette, int restrict_font_to_128 { char *p; palette_flush(); - SDL_strlcpy( Gr_current_palette_name, name, sizeof(Gr_current_palette_name) ); + SDL_strlcpy( Gr_current_palette_name, name, SDL_arraysize(Gr_current_palette_name) ); p = SDL_strchr( Gr_current_palette_name, '.' ); if ( p ) *p = 0; gr_screen.signature = Gr_signature++; @@ -636,7 +636,7 @@ void gr_set_gamma(float gamma) // save new value to cfg file char tmp_gamma_string[10]; - SDL_snprintf( tmp_gamma_string, sizeof(tmp_gamma_string), "%.2f", gamma); + SDL_snprintf( tmp_gamma_string, SDL_arraysize(tmp_gamma_string), "%.2f", gamma); os_config_write_string("Video", "Gamma", tmp_gamma_string); // call renderer specific functionality, if needed diff --git a/src/graphics/font.cpp b/src/graphics/font.cpp index 8c17987..ff3cc19 100644 --- a/src/graphics/font.cpp +++ b/src/graphics/font.cpp @@ -373,9 +373,9 @@ void gr_print_timestamp(int x, int y, int timestamp) int w, c; // format the time information into strings - SDL_snprintf(h, sizeof(h), "%.1d", (timestamp / 3600000) % 10); - SDL_snprintf(m, sizeof(m), "%.2d", (timestamp / 60000) % 60); - SDL_snprintf(s, sizeof(s), "%.2d", (timestamp / 1000) % 60); + SDL_snprintf(h, SDL_arraysize(h), "%.1d", (timestamp / 3600000) % 10); + SDL_snprintf(m, SDL_arraysize(m), "%.2d", (timestamp / 60000) % 60); + SDL_snprintf(s, SDL_arraysize(s), "%.2d", (timestamp / 1000) % 60); gr_get_string_size(&w, NULL, "0"); gr_get_string_size(&c, NULL, ":"); @@ -482,7 +482,7 @@ void __cdecl gr_printf( int x, int y, const char * format, ... ) if ( !Current_font ) return; va_start(args, format); - SDL_vsnprintf(grx_printf_text, sizeof(grx_printf_text), format, args); + SDL_vsnprintf(grx_printf_text, SDL_arraysize(grx_printf_text), format, args); va_end(args); gr_string(x,y,grx_printf_text); diff --git a/src/graphics/grgl1.cpp b/src/graphics/grgl1.cpp index 848cdc8..9298e65 100644 --- a/src/graphics/grgl1.cpp +++ b/src/graphics/grgl1.cpp @@ -381,8 +381,8 @@ void gr_opengl1_print_screen(const char *filename) char tmp[MAX_FILENAME_LEN]; ubyte *buf = NULL; - SDL_strlcpy( tmp, filename, sizeof(tmp) ); - SDL_strlcat( tmp, NOX(".tga"), sizeof(tmp) ); + SDL_strlcpy( tmp, filename, SDL_arraysize(tmp) ); + SDL_strlcat( tmp, NOX(".tga"), SDL_arraysize(tmp) ); buf = (ubyte*)malloc(GL_viewport_w * GL_viewport_h * 3); diff --git a/src/hud/hud.cpp b/src/hud/hud.cpp index 39a6059..9d40a6d 100644 --- a/src/hud/hud.cpp +++ b/src/hud/hud.cpp @@ -1452,9 +1452,9 @@ void hud_render_multi_ping() if((Netgame.server != NULL) && (Netgame.server->s_info.ping.ping_avg > 0)){ // get the string if(Netgame.server->s_info.ping.ping_avg >= 1000){ - SDL_strlcpy(ping_str, XSTR("> 1 sec",628), sizeof(ping_str)); + SDL_strlcpy(ping_str, XSTR("> 1 sec",628), SDL_arraysize(ping_str)); } else { - SDL_snprintf(ping_str, sizeof(ping_str), XSTR("%d ms", 629), Netgame.server->s_info.ping.ping_avg); + SDL_snprintf(ping_str, SDL_arraysize(ping_str), XSTR("%d ms", 629), Netgame.server->s_info.ping.ping_avg); } // blit the string out @@ -1826,7 +1826,7 @@ void hud_show_damage_popup() if ( screen_integrity == 0 ) { screen_integrity = 1; } - SDL_snprintf(buf, sizeof(buf), XSTR( "%d%%", 219), screen_integrity); + SDL_snprintf(buf, SDL_arraysize(buf), XSTR( "%d%%", 219), screen_integrity); hud_num_make_mono(buf); gr_get_string_size(&w, &h, buf); if ( screen_integrity < 30 ) { @@ -1922,7 +1922,7 @@ void hud_show_damage_popup() } gr_string(sx, sy, hud_targetbox_truncate_subsys_name(hud_subsys_list[best_index].name, MAX_NAME_LEN)); - SDL_snprintf(buf, sizeof(buf), XSTR( "%d%%", 219), best_str); + SDL_snprintf(buf, SDL_arraysize(buf), XSTR( "%d%%", 219), best_str); hud_num_make_mono(buf); gr_get_string_size(&w, &h, buf); gr_string(Hull_integ_val_coords[gr_screen.res][0] - w, sy, buf); @@ -1950,7 +1950,7 @@ void hud_anim_init(hud_anim *ha, int sx, int sy, const char *filename) ha->time_elapsed = 0.0f; ha->sx = sx; ha->sy = sy; - SDL_strlcpy(ha->name, filename, sizeof(ha->name)); + SDL_strlcpy(ha->name, filename, SDL_arraysize(ha->name)); } // call to unload the targetbox static animation @@ -2057,7 +2057,7 @@ void hud_start_text_flash(const char *txt, int t) { // bogus if(txt == NULL){ - SDL_strlcpy(Hud_text_flash, "", sizeof(Hud_text_flash)); + SDL_strlcpy(Hud_text_flash, "", SDL_arraysize(Hud_text_flash)); return; } @@ -2066,7 +2066,7 @@ void hud_start_text_flash(const char *txt, int t) return; } - SDL_strlcpy(Hud_text_flash, txt, sizeof(Hud_text_flash)); + SDL_strlcpy(Hud_text_flash, txt, SDL_arraysize(Hud_text_flash)); hud_targetbox_start_flash(TBOX_FLASH_CMEASURE, t); } @@ -2143,7 +2143,7 @@ void hud_show_kills_gauge() return; } - SDL_snprintf(num_kills_string, sizeof(num_kills_string), "%d", Player->stats.m_kill_count_ok); + SDL_snprintf(num_kills_string, SDL_arraysize(num_kills_string), "%d", Player->stats.m_kill_count_ok); gr_get_string_size(&w, &h, num_kills_string); if (Lcl_gr) { @@ -2448,17 +2448,17 @@ void hud_support_view_blit() (ship_get_subsystem_strength(Player_ship, SUBSYSTEM_SENSORS) < 1.0 ) || (ship_get_subsystem_strength(Player_ship, SUBSYSTEM_WEAPONS) < 1.0 ) || (ship_get_subsystem_strength(Player_ship, SUBSYSTEM_COMMUNICATION) < 1.0 ) ) { - SDL_strlcpy(outstr, XSTR( "repairing", 227), sizeof(outstr)); + SDL_strlcpy(outstr, XSTR( "repairing", 227), SDL_arraysize(outstr)); } else { - SDL_strlcpy(outstr, XSTR( "rearming", 228), sizeof(outstr)); + SDL_strlcpy(outstr, XSTR( "rearming", 228), SDL_arraysize(outstr)); } gr_string(0x8000, Support_text_val_coords[gr_screen.res][1], outstr); } else if (Player_ai->ai_flags & AIF_REPAIR_OBSTRUCTED) { - SDL_strlcpy(outstr, XSTR( "obstructed", 229), sizeof(outstr)); + SDL_strlcpy(outstr, XSTR( "obstructed", 229), SDL_arraysize(outstr)); gr_string(0x8000, Support_text_val_coords[gr_screen.res][1], outstr); } else { if ( Hud_support_objnum == -1 ) { - SDL_strlcpy(outstr, XSTR( "warping in", 230), sizeof(outstr)); + SDL_strlcpy(outstr, XSTR( "warping in", 230), SDL_arraysize(outstr)); gr_string(0x8000, Support_text_val_coords[gr_screen.res][1], outstr); } else { ai_info *aip; @@ -2466,11 +2466,11 @@ void hud_support_view_blit() // display "busy" when support ship isn't actually enroute to me aip = &Ai_info[Ships[Objects[Hud_support_objnum].instance].ai_index]; if ( aip->goal_objnum != OBJ_INDEX(Player_obj) ) { - SDL_strlcpy(outstr, XSTR( "busy", 231), sizeof(outstr)); + SDL_strlcpy(outstr, XSTR( "busy", 231), SDL_arraysize(outstr)); show_time = 0; } else { - SDL_strlcpy(outstr, XSTR( "dock in:", 232), sizeof(outstr)); + SDL_strlcpy(outstr, XSTR( "dock in:", 232), SDL_arraysize(outstr)); show_time = 1; } @@ -2931,11 +2931,11 @@ void hud_maybe_display_objective_message() case SECONDARY_GOAL: switch(Objective_display.goal_status) { case GOAL_FAILED: - SDL_snprintf(buf, sizeof(buf), XSTR( "failed (%d/%d)", 240), Objective_display.goal_nresolved, Objective_display.goal_ntotal); + SDL_snprintf(buf, SDL_arraysize(buf), XSTR( "failed (%d/%d)", 240), Objective_display.goal_nresolved, Objective_display.goal_ntotal); gr_string(0x8000, Objective_text_val_coords[gr_screen.res][1], buf); break; default: - SDL_snprintf(buf, sizeof(buf), XSTR( "complete (%d/%d)", 241), Objective_display.goal_nresolved, Objective_display.goal_ntotal); + SDL_snprintf(buf, SDL_arraysize(buf), XSTR( "complete (%d/%d)", 241), Objective_display.goal_nresolved, Objective_display.goal_ntotal); gr_string(0x8000, Objective_text_val_coords[gr_screen.res][1], buf); break; } @@ -3072,7 +3072,7 @@ void hud_maybe_render_multi_text() memset(txt,0,MULTI_MSG_MAX_TEXT_LEN+1); // if there is valid multiplayer message text to be displayed - if(multi_msg_message_text(txt, sizeof(txt))){ + if(multi_msg_message_text(txt, SDL_arraysize(txt))){ gr_set_color_fast(&Color_normal); gr_string(Multi_msg_coords[gr_screen.res][0], Multi_msg_coords[gr_screen.res][1], txt); } diff --git a/src/hud/hudbrackets.cpp b/src/hud/hudbrackets.cpp index 906690d..a85ebbb 100644 --- a/src/hud/hudbrackets.cpp +++ b/src/hud/hudbrackets.cpp @@ -642,7 +642,7 @@ void hud_target_show_dist_on_bracket(int x, int y, float distance) return; } - SDL_snprintf(text_dist, sizeof(text_dist), "%d", fl2i(distance+0.5f)); + SDL_snprintf(text_dist, SDL_arraysize(text_dist), "%d", fl2i(distance+0.5f)); hud_num_make_mono(text_dist); gr_get_string_size(&w,&h,text_dist); diff --git a/src/hud/hudconfig.cpp b/src/hud/hudconfig.cpp index 0f1b492..d2af369 100644 --- a/src/hud/hudconfig.cpp +++ b/src/hud/hudconfig.cpp @@ -1094,7 +1094,7 @@ void hud_config_init_ui() HC_select_all = 0; - SDL_strlcpy(HC_fname, "", sizeof(HC_fname)); + SDL_strlcpy(HC_fname, "", SDL_arraysize(HC_fname)); } int hud_config_show_flag_is_set(int i) @@ -1597,7 +1597,7 @@ void hud_config_button_do(int n) // save the file, maybe generating a new filename if(strlen(name) <= 0){ - SDL_snprintf(name, sizeof(name), "hud_%d.hcf", HC_num_files + 1); + SDL_snprintf(name, SDL_arraysize(name), "hud_%d.hcf", HC_num_files + 1); out = name; } else { out = cf_add_ext(name, ".hcf"); @@ -1982,7 +1982,7 @@ void hud_config_color_save(const char *name) cfputs(HC_gauge_descriptions(idx), out); cfputs("\n", out); cfputs("+RGBA: ", out); - SDL_snprintf(vals, sizeof(vals), "%d %d %d %d\n\n", HUD_config.clr[idx].red, HUD_config.clr[idx].green, HUD_config.clr[idx].blue, HUD_config.clr[idx].alpha); + SDL_snprintf(vals, SDL_arraysize(vals), "%d %d %d %d\n\n", HUD_config.clr[idx].red, HUD_config.clr[idx].green, HUD_config.clr[idx].blue, HUD_config.clr[idx].alpha); cfputs(vals, out); } diff --git a/src/hud/hudescort.cpp b/src/hud/hudescort.cpp index e8511c1..2ee8775 100644 --- a/src/hud/hudescort.cpp +++ b/src/hud/hudescort.cpp @@ -628,7 +628,7 @@ void hud_escort_show_icon(int index, object *objp) } // print out ship name - SDL_strlcpy(buf, sp->ship_name, sizeof(buf)); + SDL_strlcpy(buf, sp->ship_name, SDL_arraysize(buf)); gr_force_fit_string(buf, 255, 100); emp_hud_string( Escort_gauge_text_coords[gr_screen.res][index][0][0], Escort_gauge_text_coords[gr_screen.res][index][0][1], EG_ESCORT1 + index, buf); @@ -669,7 +669,7 @@ void hud_escort_show_icon_dogfight(int index) } // print out player name - SDL_strlcpy(buf, Net_players[np_index].player->callsign, sizeof(buf)); + SDL_strlcpy(buf, Net_players[np_index].player->callsign, SDL_arraysize(buf)); gr_force_fit_string(buf, 255, 100 - stat_shift); emp_hud_string( Escort_gauge_text_coords[gr_screen.res][index][0][0], Escort_gauge_text_coords[gr_screen.res][index][0][1], EG_ESCORT1 + index, buf); diff --git a/src/hud/hudmessage.cpp b/src/hud/hudmessage.cpp index c1cd8b7..bbd2f6b 100644 --- a/src/hud/hudmessage.cpp +++ b/src/hud/hudmessage.cpp @@ -848,7 +848,7 @@ void HUD_fixed_printf(float duration, const char * format, ...) } va_start(args, format); - SDL_vsnprintf(tmp, sizeof(tmp), format, args); + SDL_vsnprintf(tmp, SDL_arraysize(tmp), format, args); va_end(args); msg_length = strlen(tmp); @@ -947,7 +947,7 @@ void HUD_printf(const char *format, ...) } va_start(args, format); - SDL_vsnprintf(tmp, sizeof(tmp), format, args); + SDL_vsnprintf(tmp, SDL_arraysize(tmp), format, args); va_end(args); hud_sourced_print(HUD_SOURCE_COMPUTER, tmp); @@ -990,7 +990,7 @@ void HUD_sourced_printf(int source, const char *format, ...) } va_start(args, format); - SDL_vsnprintf(tmp, sizeof(tmp), format, args); + SDL_vsnprintf(tmp, SDL_arraysize(tmp), format, args); va_end(args); hud_sourced_print(source, tmp); @@ -1108,7 +1108,7 @@ void hud_add_msg_to_scrollback(const char *text, int source, int t) w = 0; SDL_assert(msg_len < HUD_MSG_LENGTH_MAX); - SDL_strlcpy(buf, text, sizeof(buf)); + SDL_strlcpy(buf, text, SDL_arraysize(buf)); ptr = strstr(buf, NOX(": ")); if (ptr) { gr_get_string_size(&w, NULL, buf, ptr - buf); diff --git a/src/hud/hudreticle.cpp b/src/hud/hudreticle.cpp index 2d62752..6f28340 100644 --- a/src/hud/hudreticle.cpp +++ b/src/hud/hudreticle.cpp @@ -538,7 +538,7 @@ void hud_render_throttle_speed(float current_speed, int y_end) x_pos = Hud_reticle_center[gr_screen.res][0] - x_pos; // draw current speed at (x_pos, y_end); - SDL_snprintf(buf, sizeof(buf), "%d", fl2i(current_speed+0.5f)); + SDL_snprintf(buf, SDL_arraysize(buf), "%d", fl2i(current_speed+0.5f)); hud_num_make_mono(buf); gr_get_string_size(&w, &h, buf); sx = x_pos - w - 2; diff --git a/src/hud/hudshield.cpp b/src/hud/hudshield.cpp index 5644152..9dad3be 100644 --- a/src/hud/hudshield.cpp +++ b/src/hud/hudshield.cpp @@ -719,7 +719,7 @@ void hud_show_mini_ship_integrity(object *objp, int x_force, int y_force) nx += fl2i( HUD_offset_x ); ny += fl2i( HUD_offset_y ); - SDL_snprintf(text_integrity, sizeof(text_integrity), "%d", numeric_integrity); + SDL_snprintf(text_integrity, SDL_arraysize(text_integrity), "%d", numeric_integrity); if ( numeric_integrity < 100 ) { hud_num_make_mono(text_integrity); } diff --git a/src/hud/hudsquadmsg.cpp b/src/hud/hudsquadmsg.cpp index e1fb24c..143f3ea 100644 --- a/src/hud/hudsquadmsg.cpp +++ b/src/hud/hudsquadmsg.cpp @@ -677,7 +677,7 @@ int hud_squadmsg_count_ships( int add_to_menu ) count++; if ( add_to_menu ) { SDL_assert ( Num_menu_items < MAX_MENU_ITEMS ); - SDL_strlcpy( MsgItems[Num_menu_items].text, shipp->ship_name, sizeof(MsgItems[0].text) ); + SDL_strlcpy( MsgItems[Num_menu_items].text, shipp->ship_name, SDL_arraysize(MsgItems[0].text) ); MsgItems[Num_menu_items].instance = SHIP_INDEX(shipp); MsgItems[Num_menu_items].active = 1; Num_menu_items++; @@ -767,7 +767,7 @@ int hud_squadmsg_count_wings( int add_to_menu ) count++; if ( add_to_menu ) { SDL_assert ( Num_menu_items < MAX_MENU_ITEMS ); - SDL_strlcpy( MsgItems[Num_menu_items].text, Wings[wingnum].name, sizeof(MsgItems[0].text) ); + SDL_strlcpy( MsgItems[Num_menu_items].text, Wings[wingnum].name, SDL_arraysize(MsgItems[0].text) ); MsgItems[Num_menu_items].instance = wingnum; MsgItems[Num_menu_items].active = 1; Num_menu_items++; @@ -788,7 +788,7 @@ int hud_squadmsg_count_wings( int add_to_menu ) count++; if ( add_to_menu ) { SDL_assert ( Num_menu_items < MAX_MENU_ITEMS ); - SDL_strlcpy( MsgItems[Num_menu_items].text, Wings[i].name, sizeof(MsgItems[0].text) ); + SDL_strlcpy( MsgItems[Num_menu_items].text, Wings[i].name, SDL_arraysize(MsgItems[0].text) ); MsgItems[Num_menu_items].instance = i; MsgItems[Num_menu_items].active = 1; Num_menu_items++; @@ -1936,7 +1936,7 @@ void hud_squadmsg_type_select( ) // Add the items for (i=0; iname, sizeof(MsgItems[0].text) ); + SDL_strlcpy( MsgItems[Num_menu_items].text, rp->name, SDL_arraysize(MsgItems[0].text) ); MsgItems[Num_menu_items].instance = i; MsgItems[Num_menu_items].active = 0; @@ -2268,7 +2268,7 @@ void hud_squadmsg_ship_command() // the order will be activated if the bit is set for the ship. if ( default_orders & Comm_orders[i].value ) { SDL_assert ( Num_menu_items < MAX_MENU_ITEMS ); - SDL_strlcpy( MsgItems[Num_menu_items].text, comm_order_menu_text(i), sizeof(MsgItems[0].text) ); + SDL_strlcpy( MsgItems[Num_menu_items].text, comm_order_menu_text(i), SDL_arraysize(MsgItems[0].text) ); MsgItems[Num_menu_items].instance = Comm_orders[i].value; MsgItems[Num_menu_items].active = 0; // check the bit to see if the command is active @@ -2311,7 +2311,7 @@ void hud_squadmsg_ship_command() if ( !all_accept ) { // either modify the text if a partial accept, or grey it out if no one accepts if ( partial_accept ) { - SDL_strlcat( MsgItems[Num_menu_items].text, XSTR( "(*)", 320), sizeof(MsgItems[0].text) ); + SDL_strlcat( MsgItems[Num_menu_items].text, XSTR( "(*)", 320), SDL_arraysize(MsgItems[0].text) ); } else { MsgItems[Num_menu_items].active = 0; } @@ -2365,7 +2365,7 @@ void hud_squadmsg_wing_command() // to be available in the wing. if ( default_orders & Comm_orders[i].value ) { SDL_assert ( Num_menu_items < MAX_MENU_ITEMS ); - SDL_strlcpy( MsgItems[Num_menu_items].text, comm_order_menu_text(i), sizeof(MsgItems[0].text) ); + SDL_strlcpy( MsgItems[Num_menu_items].text, comm_order_menu_text(i), SDL_arraysize(MsgItems[0].text) ); MsgItems[Num_menu_items].instance = Comm_orders[i].value; MsgItems[Num_menu_items].active = 0; diff --git a/src/hud/hudtarget.cpp b/src/hud/hudtarget.cpp index 3edf3d1..a993ec5 100644 --- a/src/hud/hudtarget.cpp +++ b/src/hud/hudtarget.cpp @@ -4396,7 +4396,7 @@ void hud_draw_offscreen_indicator(vertex* target_point, vector *tpos, float dist ypos = (float)floor(ypos); if ( hud_gauge_active(HUD_OFFSCREEN_RANGE) && (distance > 0) ) { - SDL_snprintf(buf, sizeof(buf), "%d", fl2i(distance+0.5f)); + SDL_snprintf(buf, SDL_arraysize(buf), "%d", fl2i(distance+0.5f)); hud_num_make_mono(buf); gr_get_string_size(&w, &h, buf); } else { @@ -4530,7 +4530,7 @@ void hud_show_weapon_energy_gauge() if ( percent_left < 0.1 ) { gr_set_color_fast(&Color_bright_red); } - SDL_snprintf(buf, sizeof(buf), XSTR( "%d%%", 326), fl2i(percent_left*100+0.5f)); + SDL_snprintf(buf, SDL_arraysize(buf), XSTR( "%d%%", 326), fl2i(percent_left*100+0.5f)); hud_num_make_mono(buf); gr_string(Weapon_energy_text_coords[gr_screen.res][0], Weapon_energy_text_coords[gr_screen.res][1], buf); } @@ -4622,9 +4622,9 @@ void hud_show_secondary_weapon(int count, ship_weapon *sw, int dual_fire) // HACK - make Cluster Bomb fit on the HUD. if(!SDL_strcasecmp(wip->name,"cluster bomb")){ - SDL_strlcpy(weapon_name, NOX("Cluster"), sizeof(weapon_name)); + SDL_strlcpy(weapon_name, NOX("Cluster"), SDL_arraysize(weapon_name)); } else { - SDL_strlcpy(weapon_name, wip->name, sizeof(weapon_name)); + SDL_strlcpy(weapon_name, wip->name, SDL_arraysize(weapon_name)); } hud_end_string_at_first_hash_symbol(weapon_name); @@ -4649,7 +4649,7 @@ void hud_show_secondary_weapon(int count, ship_weapon *sw, int dual_fire) } // print out the ammo right justified - SDL_snprintf(ammo_str, sizeof(ammo_str), "%d", sw->secondary_bank_ammo[i]); + SDL_snprintf(ammo_str, SDL_arraysize(ammo_str), "%d", sw->secondary_bank_ammo[i]); hud_num_make_mono(ammo_str); gr_get_string_size(&w, &h, ammo_str); @@ -4773,9 +4773,9 @@ void hud_show_weapons() // draw bottom of border GR_AABITMAP(Weapon_gauges[2].first_frame, Weapon_gauge_primary_coords[gr_screen.res][1][0], Weapon_gauge_primary_coords[gr_screen.res][1][1]); - SDL_strlcpy(name, Weapon_info[sw->primary_bank_weapons[0]].name, sizeof(name)); + SDL_strlcpy(name, Weapon_info[sw->primary_bank_weapons[0]].name, SDL_arraysize(name)); if (Lcl_gr) { - lcl_translate_wep_name(name, sizeof(name)); + lcl_translate_wep_name(name, SDL_arraysize(name)); } // maybe modify name here to fit @@ -4797,9 +4797,9 @@ void hud_show_weapons() // draw bottom of border GR_AABITMAP(Weapon_gauges[2].first_frame, Weapon_gauge_primary_coords[gr_screen.res][2][0], Weapon_gauge_primary_coords[gr_screen.res][2][1]); - SDL_strlcpy(name, Weapon_info[sw->primary_bank_weapons[0]].name, sizeof(name)); + SDL_strlcpy(name, Weapon_info[sw->primary_bank_weapons[0]].name, SDL_arraysize(name)); if (Lcl_gr) { - lcl_translate_wep_name(name, sizeof(name)); + lcl_translate_wep_name(name, SDL_arraysize(name)); } // maybe modify name here to fit @@ -4814,9 +4814,9 @@ void hud_show_weapons() } emp_hud_printf(Weapon_pname_coords[gr_screen.res][0][0], Weapon_pname_coords[gr_screen.res][0][1], EG_WEAPON_P1, "%s", name); - SDL_strlcpy(name, Weapon_info[sw->primary_bank_weapons[1]].name, sizeof(name)); + SDL_strlcpy(name, Weapon_info[sw->primary_bank_weapons[1]].name, SDL_arraysize(name)); if (Lcl_gr) { - lcl_translate_wep_name(name, sizeof(name)); + lcl_translate_wep_name(name, SDL_arraysize(name)); } // maybe modify name here to fit if ( hud_gauge_maybe_flash(HUD_WEAPONS_GAUGE) == 1 ) { diff --git a/src/hud/hudtargetbox.cpp b/src/hud/hudtargetbox.cpp index bb4eb55..56b64d0 100644 --- a/src/hud/hudtargetbox.cpp +++ b/src/hud/hudtargetbox.cpp @@ -722,20 +722,20 @@ void hud_targetbox_show_extra_ship_info(ship *target_shipp, ai_info *target_aip) // AL 12-26-97: only show orders and time to target for friendly ships if ( (Player_ship->team == target_shipp->team) && !(ship_get_SIF(target_shipp) & SIF_NOT_FLYABLE) ) { extra_data_shown=1; - if ( ship_return_orders(outstr, sizeof(outstr), target_shipp) ) { + if ( ship_return_orders(outstr, SDL_arraysize(outstr), target_shipp) ) { gr_force_fit_string(outstr, 255, 162); has_orders = 1; } else { - SDL_strlcpy(outstr, XSTR( "no orders", 337), sizeof(outstr)); + SDL_strlcpy(outstr, XSTR( "no orders", 337), SDL_arraysize(outstr)); } emp_hud_string(Targetbox_coords[gr_screen.res][TBOX_EXTRA_ORDERS][0], Targetbox_coords[gr_screen.res][TBOX_EXTRA_ORDERS][1], EG_TBOX_EXTRA1, outstr); } if ( has_orders ) { - SDL_strlcpy(outstr, XSTR( "time to: ", 338), sizeof(outstr)); - if ( ship_return_time_to_goal(tmpbuf, sizeof(tmpbuf), target_shipp) ) { - SDL_strlcat(outstr, tmpbuf, sizeof(outstr)); + SDL_strlcpy(outstr, XSTR( "time to: ", 338), SDL_arraysize(outstr)); + if ( ship_return_time_to_goal(tmpbuf, SDL_arraysize(tmpbuf), target_shipp) ) { + SDL_strlcat(outstr, tmpbuf, SDL_arraysize(outstr)); emp_hud_string(Targetbox_coords[gr_screen.res][TBOX_EXTRA_TIME][0], Targetbox_coords[gr_screen.res][TBOX_EXTRA_TIME][1], EG_TBOX_EXTRA2, outstr); } @@ -745,7 +745,7 @@ void hud_targetbox_show_extra_ship_info(ship *target_shipp, ai_info *target_aip) // Print out dock status if ( target_aip->ai_flags & AIF_DOCKED ) { if ( target_aip->dock_objnum >= 0 ) { - SDL_snprintf(outstr, sizeof(outstr), XSTR( "Docked: %s", 339), Ships[Objects[target_aip->dock_objnum].instance].ship_name); + SDL_snprintf(outstr, SDL_arraysize(outstr), XSTR( "Docked: %s", 339), Ships[Objects[target_aip->dock_objnum].instance].ship_name); gr_force_fit_string(outstr, 255, 173); hud_targetbox_maybe_flash(TBOX_FLASH_DOCKED); @@ -806,7 +806,7 @@ void hud_render_target_jump_node(object *target_objp) hx = fl2i(HUD_offset_x); hy = fl2i(HUD_offset_y); - SDL_snprintf(outstr, sizeof(outstr), XSTR( "d: %.0f", 340), dist); + SDL_snprintf(outstr, SDL_arraysize(outstr), XSTR( "d: %.0f", 340), dist); hud_num_make_mono(outstr); gr_get_string_size(&w,&h,outstr); @@ -866,26 +866,26 @@ void hud_render_target_asteroid(object *target_objp) case ASTEROID_TYPE_SMALL: case ASTEROID_TYPE_MEDIUM: case ASTEROID_TYPE_BIG: - SDL_strlcpy(hud_name, NOX("asteroid"), sizeof(hud_name)); + SDL_strlcpy(hud_name, NOX("asteroid"), SDL_arraysize(hud_name)); break; #ifndef MAKE_FS1 case DEBRIS_TERRAN_SMALL: case DEBRIS_TERRAN_MEDIUM: case DEBRIS_TERRAN_LARGE: - SDL_strlcpy(hud_name, NOX("terran debris"), sizeof(hud_name)); + SDL_strlcpy(hud_name, NOX("terran debris"), SDL_arraysize(hud_name)); break; case DEBRIS_VASUDAN_SMALL: case DEBRIS_VASUDAN_MEDIUM: case DEBRIS_VASUDAN_LARGE: - SDL_strlcpy(hud_name, NOX("vasudan debris"), sizeof(hud_name)); + SDL_strlcpy(hud_name, NOX("vasudan debris"), SDL_arraysize(hud_name)); break; case DEBRIS_SHIVAN_SMALL: case DEBRIS_SHIVAN_MEDIUM: case DEBRIS_SHIVAN_LARGE: - SDL_strlcpy(hud_name, NOX("shivan debris"), sizeof(hud_name)); + SDL_strlcpy(hud_name, NOX("shivan debris"), SDL_arraysize(hud_name)); break; #endif @@ -949,7 +949,7 @@ void hud_render_target_ship_info(object *target_objp) target_sip = &Ship_info[target_shipp->ship_info_index]; target_aip = &Ai_info[target_shipp->ai_index]; - SDL_strlcpy( outstr, target_shipp->ship_name, sizeof(outstr) ); + SDL_strlcpy( outstr, target_shipp->ship_name, SDL_arraysize(outstr) ); if ( hud_gauge_maybe_flash(HUD_TARGET_MONITOR) == 1 ) { hud_set_iff_color(target_objp, 1); @@ -969,10 +969,10 @@ void hud_render_target_ship_info(object *target_objp) // maybe do some translation if (Lcl_gr) { - lcl_translate_targetbox_name(outstr, sizeof(outstr)); + lcl_translate_targetbox_name(outstr, SDL_arraysize(outstr)); } else if(Lcl_pl) { - lcl_translate_targetbox_name_pl(outstr, sizeof(outstr)); + lcl_translate_targetbox_name_pl(outstr, SDL_arraysize(outstr)); } emp_hud_string(Targetbox_coords[gr_screen.res][TBOX_NAME][0], Targetbox_coords[gr_screen.res][TBOX_NAME][1], EG_TBOX_NAME, outstr); @@ -981,19 +981,19 @@ void hud_render_target_ship_info(object *target_objp) // if this ship has an alternate type name if(target_shipp->alt_type_index >= 0){ - mission_parse_lookup_alt_index(target_shipp->alt_type_index, temp_name, sizeof(temp_name)); + mission_parse_lookup_alt_index(target_shipp->alt_type_index, temp_name, SDL_arraysize(temp_name)); } else { - SDL_strlcpy(temp_name, Ship_info[base_index].name, sizeof(temp_name)); + SDL_strlcpy(temp_name, Ship_info[base_index].name, SDL_arraysize(temp_name)); if ( strstr(Ship_info[base_index].name, NOX("#")) ) { hud_end_string_at_first_hash_symbol(temp_name); } } if (Lcl_gr) { - lcl_translate_targetbox_name(temp_name, sizeof(temp_name)); + lcl_translate_targetbox_name(temp_name, SDL_arraysize(temp_name)); } else if(Lcl_pl) { - lcl_translate_targetbox_name_pl(temp_name, sizeof(temp_name)); + lcl_translate_targetbox_name_pl(temp_name, SDL_arraysize(temp_name)); } emp_hud_printf(Targetbox_coords[gr_screen.res][TBOX_CLASS][0], Targetbox_coords[gr_screen.res][TBOX_CLASS][1], EG_TBOX_CLASS, temp_name); @@ -1012,7 +1012,7 @@ void hud_render_target_ship_info(object *target_objp) } } // Print out right-justified integrity - SDL_snprintf(outstr, sizeof(outstr), XSTR( "%d%%", 341), screen_integrity); + SDL_snprintf(outstr, SDL_arraysize(outstr), XSTR( "%d%%", 341), screen_integrity); gr_get_string_size(&w,&h,outstr); if ( hud_gauge_maybe_flash(HUD_TARGET_MONITOR) == 1 ) { @@ -1049,17 +1049,17 @@ void hud_render_target_ship_info(object *target_objp) // hud_set_default_color(); // get turret subsys name if (Player_ai->targeted_subsys->system_info->type == SUBSYSTEM_TURRET) { - get_turret_subsys_name(Player_ai->targeted_subsys->system_info, outstr, sizeof(outstr)); + get_turret_subsys_name(Player_ai->targeted_subsys->system_info, outstr, SDL_arraysize(outstr)); } else { - SDL_snprintf(outstr, sizeof(outstr), "%s", Player_ai->targeted_subsys->system_info->name); + SDL_snprintf(outstr, SDL_arraysize(outstr), "%s", Player_ai->targeted_subsys->system_info->name); } - hud_targetbox_truncate_subsys_name(outstr, sizeof(outstr)); + hud_targetbox_truncate_subsys_name(outstr, SDL_arraysize(outstr)); gr_printf(Target_window_coords[gr_screen.res][0]+2, Target_window_coords[gr_screen.res][1]+Target_window_coords[gr_screen.res][3]-h, outstr); // AL 23-3-98: Fighter bays are a special case. Player cannot destroy them, so don't // show the subsystem strength if ( SDL_strncasecmp(NOX("fighter"), Player_ai->targeted_subsys->system_info->name, 7) ) { - SDL_snprintf(outstr, sizeof(outstr), XSTR( "%d%%", 341),screen_integrity); + SDL_snprintf(outstr, SDL_arraysize(outstr), XSTR( "%d%%", 341),screen_integrity); gr_get_string_size(&w,&h,outstr); gr_printf(Target_window_coords[gr_screen.res][0]+Target_window_coords[gr_screen.res][2]-w-1, Target_window_coords[gr_screen.res][1]+Target_window_coords[gr_screen.res][3] - h, "%s", outstr); } @@ -1070,9 +1070,9 @@ void hud_render_target_ship_info(object *target_objp) // print out 'disabled' on the monitor if the target is disabled if ( (target_shipp->flags & SF_DISABLED) || (ship_subsys_disrupted(target_shipp, SUBSYSTEM_ENGINE)) ) { if ( target_shipp->flags & SF_DISABLED ) { - SDL_strlcpy(outstr, XSTR( "DISABLED", 342), sizeof(outstr)); + SDL_strlcpy(outstr, XSTR( "DISABLED", 342), SDL_arraysize(outstr)); } else { - SDL_strlcpy(outstr, XSTR( "DISRUPTED", 343), sizeof(outstr)); + SDL_strlcpy(outstr, XSTR( "DISRUPTED", 343), SDL_arraysize(outstr)); } gr_get_string_size(&w,&h,outstr); gr_printf(Target_window_coords[gr_screen.res][0]+Target_window_coords[gr_screen.res][2]/2 - w/2 - 1, Target_window_coords[gr_screen.res][1]+Target_window_coords[gr_screen.res][3] - 2*h, "%s", outstr); @@ -1108,17 +1108,17 @@ void hud_blit_target_integrity(int disabled,int force_obj_num) // print out status of ship if ( (Ships[objp->instance].flags & SF_DISABLED) || (ship_subsys_disrupted(&Ships[objp->instance], SUBSYSTEM_ENGINE)) ) { - SDL_strlcpy(buf,XSTR( "dis", 344), sizeof(buf)); + SDL_strlcpy(buf,XSTR( "dis", 344), SDL_arraysize(buf)); current_ts = TS_DIS; } else { if ( Pl_target_integrity > 0.9 ) { - SDL_strlcpy(buf, XSTR( "ok", 345), sizeof(buf)); + SDL_strlcpy(buf, XSTR( "ok", 345), SDL_arraysize(buf)); current_ts = TS_OK; } else if ( Pl_target_integrity > 0.2 ) { - SDL_strlcpy(buf, XSTR( "dmg", 346), sizeof(buf)); + SDL_strlcpy(buf, XSTR( "dmg", 346), SDL_arraysize(buf)); current_ts = TS_DMG; } else { - SDL_strlcpy(buf, XSTR( "crt", 347), sizeof(buf)); + SDL_strlcpy(buf, XSTR( "crt", 347), SDL_arraysize(buf)); current_ts = TS_CRT; } } @@ -1392,7 +1392,7 @@ void hud_render_target_debris(object *target_objp) char *printable_ship_class = Ship_info[base_index].name; if ( strstr(Ship_info[base_index].name, NOX("#")) ) { char temp_name[NAME_LENGTH]; - SDL_strlcpy(temp_name, Ship_info[base_index].name, sizeof(temp_name)); + SDL_strlcpy(temp_name, Ship_info[base_index].name, SDL_arraysize(temp_name)); hud_end_string_at_first_hash_symbol(temp_name); printable_ship_class = temp_name; } @@ -1479,7 +1479,7 @@ void hud_render_target_weapon(object *target_objp) hud_set_gauge_color(HUD_TARGET_MONITOR); // print out the weapon class name - SDL_snprintf( outstr, sizeof(outstr), "%s", target_wip->name ); + SDL_snprintf( outstr, SDL_arraysize(outstr), "%s", target_wip->name ); gr_get_string_size(&w,&h,outstr); // drop name past the # sign @@ -1495,9 +1495,9 @@ void hud_render_target_weapon(object *target_objp) dist = vm_vec_dist(&target_objp->pos, &wp->homing_object->pos); speed = vm_vec_mag(&target_objp->phys_info.vel); if ( speed > 0 ) { - SDL_snprintf(outstr, sizeof(outstr), NOX("impact: %.1f sec"), dist/speed); + SDL_snprintf(outstr, SDL_arraysize(outstr), NOX("impact: %.1f sec"), dist/speed); } else { - SDL_strlcpy(outstr, XSTR( "unknown", 349), sizeof(outstr)); + SDL_strlcpy(outstr, XSTR( "unknown", 349), SDL_arraysize(outstr)); } emp_hud_string(Targetbox_coords[gr_screen.res][TBOX_CLASS][0], Targetbox_coords[gr_screen.res][TBOX_CLASS][1], EG_TBOX_CLASS, outstr); @@ -1565,7 +1565,7 @@ void hud_cargo_scan_update(object *targetp, float frametime) // display cargo inspection status if ( targetp->type == OBJ_SHIP ) { - if ( player_inspect_cargo(frametime, outstr, sizeof(outstr)) ) { + if ( player_inspect_cargo(frametime, outstr, SDL_arraysize(outstr)) ) { if ( hud_gauge_active(HUD_TARGET_MONITOR) ) { if ( Player->cargo_inspect_time > 0 ) { hud_targetbox_start_flash(TBOX_FLASH_CARGO); @@ -1633,7 +1633,7 @@ void hud_show_target_data(float frametime) hy = fl2i(HUD_offset_y); // print out the target distance and speed - SDL_snprintf(outstr, sizeof(outstr), XSTR( "d: %.0f%s", 350), Player_ai->current_target_distance, modifiers[Player_ai->current_target_dist_trend]); + SDL_snprintf(outstr, SDL_arraysize(outstr), XSTR( "d: %.0f%s", 350), Player_ai->current_target_distance, modifiers[Player_ai->current_target_dist_trend]); hud_num_make_mono(outstr); gr_get_string_size(&w,&h,outstr); @@ -1666,7 +1666,7 @@ void hud_show_target_data(float frametime) } } - SDL_snprintf(outstr, sizeof(outstr), XSTR( "s: %.0f%s", 351), spd, (spd>1)?modifiers[Player_ai->current_target_speed_trend]:""); + SDL_snprintf(outstr, SDL_arraysize(outstr), XSTR( "s: %.0f%s", 351), spd, (spd>1)?modifiers[Player_ai->current_target_speed_trend]:""); hud_num_make_mono(outstr); emp_hud_string(Targetbox_coords[gr_screen.res][TBOX_SPEED][0]+hx, Targetbox_coords[gr_screen.res][TBOX_SPEED][1]+hy, EG_TBOX_SPEED, outstr); @@ -1689,25 +1689,25 @@ void hud_show_target_data(float frametime) if ( shipp->ai_index >= 0 ) { ai_info *aip = &Ai_info[shipp->ai_index]; - SDL_snprintf(outstr, sizeof(outstr), "AI: %s", Ai_behavior_names[aip->mode]); + SDL_snprintf(outstr, SDL_arraysize(outstr), "AI: %s", Ai_behavior_names[aip->mode]); switch (aip->mode) { case AIM_CHASE: SDL_assert(aip->submode <= SM_BIG_PARALLEL); // Must be <= largest chase submode value. // sprintf(outstr,"AI: %s",Submode_text[aip->submode]); - SDL_snprintf(outstr2,sizeof(outstr2)," / %s",Submode_text[aip->submode]); - SDL_strlcat(outstr, outstr2, sizeof(outstr)); + SDL_snprintf(outstr2,SDL_arraysize(outstr2)," / %s",Submode_text[aip->submode]); + SDL_strlcat(outstr, outstr2, SDL_arraysize(outstr)); break; case AIM_STRAFE: SDL_assert(aip->submode <= AIS_STRAFE_POSITION); // Must be <= largest chase submode value. // sprintf(outstr,"AI: %s",Strafe_submode_text[aip->submode-AIS_STRAFE_ATTACK]); - SDL_snprintf(outstr2,sizeof(outstr2)," / %s",Strafe_submode_text[aip->submode-AIS_STRAFE_ATTACK]); - SDL_strlcat(outstr, outstr2, sizeof(outstr)); + SDL_snprintf(outstr2,SDL_arraysize(outstr2)," / %s",Strafe_submode_text[aip->submode-AIS_STRAFE_ATTACK]); + SDL_strlcat(outstr, outstr2, SDL_arraysize(outstr)); break; case AIM_WAYPOINTS: // gr_printf(sx, sy, "Wpnum: %i",aip->wp_index); - SDL_snprintf(outstr2,sizeof(outstr2)," / Wpnum: %i",aip->wp_index); - SDL_strlcat(outstr, outstr2, sizeof(outstr)); + SDL_snprintf(outstr2,SDL_arraysize(outstr2)," / Wpnum: %i",aip->wp_index); + SDL_strlcat(outstr, outstr2, SDL_arraysize(outstr)); break; default: break; @@ -1727,9 +1727,9 @@ void hud_show_target_data(float frametime) vector v2t; if (aip->target_objnum == Player_obj-Objects) - SDL_strlcpy(target_str, "Player!", sizeof(target_str)); + SDL_strlcpy(target_str, "Player!", SDL_arraysize(target_str)); else - SDL_snprintf(target_str, sizeof(target_str), "%s", Ships[Objects[aip->target_objnum].instance].ship_name); + SDL_snprintf(target_str, SDL_arraysize(target_str), "%s", Ships[Objects[aip->target_objnum].instance].ship_name); // gr_printf(TARGET_WINDOW_X1+TARGET_WINDOW_WIDTH+2, TARGET_WINDOW_Y1+4*h, "Target: %s", target_str); gr_printf(sx, sy, "Targ: %s", target_str); @@ -1750,7 +1750,7 @@ void hud_show_target_data(float frametime) sy += dy; if ( aip->targeted_subsys != NULL ) { - SDL_snprintf(outstr, sizeof(outstr), "Subsys: %s", aip->targeted_subsys->system_info->name); + SDL_snprintf(outstr, SDL_arraysize(outstr), "Subsys: %s", aip->targeted_subsys->system_info->name); gr_printf(sx, sy, outstr); } } @@ -1758,11 +1758,11 @@ void hud_show_target_data(float frametime) // print out energy transfer information on the ship sy = 70; - SDL_snprintf(outstr,sizeof(outstr),"MAX G/E: %.0f/%.0f",shipp->weapon_energy,shipp->current_max_speed); + SDL_snprintf(outstr,SDL_arraysize(outstr),"MAX G/E: %.0f/%.0f",shipp->weapon_energy,shipp->current_max_speed); gr_printf(sx, sy, outstr); sy += dy; - SDL_snprintf(outstr,sizeof(outstr),"G/S/E: %.2f/%.2f/%.2f",Energy_levels[shipp->weapon_recharge_index],Energy_levels[shipp->shield_recharge_index],Energy_levels[shipp->engine_recharge_index]); + SDL_snprintf(outstr,SDL_arraysize(outstr),"G/S/E: %.2f/%.2f/%.2f",Energy_levels[shipp->weapon_recharge_index],Energy_levels[shipp->shield_recharge_index],Energy_levels[shipp->engine_recharge_index]); gr_printf(sx, sy, outstr); sy += dy; @@ -1842,21 +1842,21 @@ void hud_show_target_data(float frametime) sy = 100; dy = gr_get_font_height(); - SDL_snprintf(outstr,sizeof(outstr),"Num primaries: %d", swp->num_primary_banks); + SDL_snprintf(outstr,SDL_arraysize(outstr),"Num primaries: %d", swp->num_primary_banks); gr_printf(sx,sy,outstr); sy += dy; for ( i = 0; i < swp->num_primary_banks; i++ ) { - SDL_snprintf(outstr,sizeof(outstr),"%d. %s", i+1, Weapon_info[swp->primary_bank_weapons[i]].name); + SDL_snprintf(outstr,SDL_arraysize(outstr),"%d. %s", i+1, Weapon_info[swp->primary_bank_weapons[i]].name); gr_printf(sx,sy,outstr); sy += dy; } sy += dy; - SDL_snprintf(outstr,sizeof(outstr),"Num secondaries: %d", swp->num_secondary_banks); + SDL_snprintf(outstr,SDL_arraysize(outstr),"Num secondaries: %d", swp->num_secondary_banks); gr_printf(sx,sy,outstr); sy += dy; for ( i = 0; i < swp->num_secondary_banks; i++ ) { - SDL_snprintf(outstr,sizeof(outstr),"%d. %s", i+1, Weapon_info[swp->secondary_bank_weapons[i]].name); + SDL_snprintf(outstr,SDL_arraysize(outstr),"%d. %s", i+1, Weapon_info[swp->secondary_bank_weapons[i]].name); gr_printf(sx,sy,outstr); sy += dy; } diff --git a/src/inetfile/cftp.cpp b/src/inetfile/cftp.cpp index f46ae29..151b20a 100644 --- a/src/inetfile/cftp.cpp +++ b/src/inetfile/cftp.cpp @@ -131,19 +131,19 @@ CFtpGet::CFtpGet(char *URL,char *localfile,char *Username,char *Password) if(Username) { - SDL_strlcpy(m_szUserName, Username, sizeof(m_szUserName)); + SDL_strlcpy(m_szUserName, Username, SDL_arraysize(m_szUserName)); } else { - SDL_strlcpy(m_szUserName, "anonymous", sizeof(m_szUserName)); + SDL_strlcpy(m_szUserName, "anonymous", SDL_arraysize(m_szUserName)); } if(Password) { - SDL_strlcpy(m_szPassword, Password, sizeof(m_szPassword)); + SDL_strlcpy(m_szPassword, Password, SDL_arraysize(m_szPassword)); } else { - SDL_strlcpy(m_szPassword, "pxouser@pxo.net", sizeof(m_szPassword)); + SDL_strlcpy(m_szPassword, "pxouser@pxo.net", SDL_arraysize(m_szPassword)); } m_ListenSock = socket(AF_INET, SOCK_STREAM, 0); if(INVALID_SOCKET == m_ListenSock) @@ -217,7 +217,7 @@ CFtpGet::CFtpGet(char *URL,char *localfile,char *Username,char *Password) { filestart = pURL+i+1; dirstart = pURL+i+1; - SDL_strlcpy(m_szFilename, filestart, sizeof(m_szFilename)); + SDL_strlcpy(m_szFilename, filestart, SDL_arraysize(m_szFilename)); } else { @@ -233,9 +233,9 @@ CFtpGet::CFtpGet(char *URL,char *localfile,char *Username,char *Password) } else { - int len = min((filestart-dirstart)+1, (int)sizeof(m_szDir)); + int len = min((filestart-dirstart)+1, (int)SDL_arraysize(m_szDir)); SDL_strlcpy(m_szDir, dirstart, len); - len = min((dirstart-pURL), (int)sizeof(m_szHost)); + len = min((dirstart-pURL), (int)SDL_arraysize(m_szHost)); SDL_strlcpy(m_szHost, pURL, len); } //At this point we should have a nice host,dir and filename @@ -327,7 +327,7 @@ unsigned int CFtpGet::GetFile() char szCommandString[200]; int rcode; - SDL_strlcpy(szCommandString, "TYPE I\r\n", sizeof(szCommandString)); + SDL_strlcpy(szCommandString, "TYPE I\r\n", SDL_arraysize(szCommandString)); rcode = SendFTPCommand(szCommandString); if(rcode >=400) { @@ -338,7 +338,7 @@ unsigned int CFtpGet::GetFile() return 0; if(m_szDir[0]) { - SDL_snprintf(szCommandString, sizeof(szCommandString), "CWD %s\r\n", m_szDir); + SDL_snprintf(szCommandString, SDL_arraysize(szCommandString), "CWD %s\r\n", m_szDir); rcode = SendFTPCommand(szCommandString); if(rcode >=400) { @@ -355,7 +355,7 @@ unsigned int CFtpGet::GetFile() } if(m_Aborting) return 0; - SDL_snprintf(szCommandString, sizeof(szCommandString), "RETR %s\r\n", m_szFilename); + SDL_snprintf(szCommandString, SDL_arraysize(szCommandString), "RETR %s\r\n", m_szFilename); rcode = SendFTPCommand(szCommandString); if(rcode >=400) { @@ -431,7 +431,7 @@ unsigned int CFtpGet::IssuePort() // Format the PORT command with the correct numbers. #ifndef PLAT_UNIX - SDL_snprintf(szCommandString, sizeof(szCommandString), "PORT %d,%d,%d,%d,%d,%d\r\n", + SDL_snprintf(szCommandString, SDL_arraysize(szCommandString), "PORT %d,%d,%d,%d,%d,%d\r\n", listenaddr.sin_addr.S_un.S_un_b.s_b1, listenaddr.sin_addr.S_un.S_un_b.s_b2, listenaddr.sin_addr.S_un.S_un_b.s_b3, @@ -439,7 +439,7 @@ unsigned int CFtpGet::IssuePort() nLocalPort & 0xFF, nLocalPort >> 8); #else - SDL_snprintf(szCommandString, sizeof(szCommandString), "PORT %d,%d,%d,%d,%d,%d\r\n", + SDL_snprintf(szCommandString, SDL_arraysize(szCommandString), "PORT %d,%d,%d,%d,%d,%d\r\n", (listenaddr.sin_addr.s_addr >> 0) & 0xFF, (listenaddr.sin_addr.s_addr >> 8) & 0xFF, (listenaddr.sin_addr.s_addr >> 16) & 0xFF, @@ -504,14 +504,14 @@ int CFtpGet::LoginHost() char szLoginString[200]; int rcode; - SDL_snprintf(szLoginString, sizeof(szLoginString), "USER %s\r\n" ,m_szUserName); + SDL_snprintf(szLoginString, SDL_arraysize(szLoginString), "USER %s\r\n" ,m_szUserName); rcode = SendFTPCommand(szLoginString); if(rcode >=400) { m_State = FTP_STATE_LOGIN_ERROR; return 0; } - SDL_snprintf(szLoginString, sizeof(szLoginString), "PASS %s\r\n" ,m_szPassword); + SDL_snprintf(szLoginString, SDL_arraysize(szLoginString), "PASS %s\r\n" ,m_szPassword); rcode = SendFTPCommand(szLoginString); if(rcode >=400) { @@ -571,7 +571,7 @@ unsigned int CFtpGet::ReadFTPServerReply() } else { chunk[1] = 0; - SDL_strlcat(recv_buffer, chunk, sizeof(recv_buffer)); + SDL_strlcat(recv_buffer, chunk, SDL_arraysize(recv_buffer)); } SDL_Delay(1); diff --git a/src/inetfile/chttpget.cpp b/src/inetfile/chttpget.cpp index f1b2d0d..ece61f9 100644 --- a/src/inetfile/chttpget.cpp +++ b/src/inetfile/chttpget.cpp @@ -190,7 +190,7 @@ void ChttpGet::GetFile(char *URL,char *localfile) m_Aborting = false; m_Aborted = false; - SDL_strlcpy(m_URL, URL, sizeof(m_URL)); + SDL_strlcpy(m_URL, URL, SDL_arraysize(m_URL)); LOCALFILE = fopen(localfile,"wb"); if(NULL == LOCALFILE) @@ -241,7 +241,7 @@ void ChttpGet::GetFile(char *URL,char *localfile) { filestart = pURL+i+1; dirstart = pURL+i+1; - SDL_strlcpy(m_szFilename, filestart, sizeof(m_szFilename)); + SDL_strlcpy(m_szFilename, filestart, SDL_arraysize(m_szFilename)); } else { @@ -257,8 +257,8 @@ void ChttpGet::GetFile(char *URL,char *localfile) } else { - SDL_strlcpy(m_szDir, dirstart, sizeof(m_szDir));//,(filestart-dirstart)); - int len = min((dirstart-pURL), (int)sizeof(m_szHost)); + SDL_strlcpy(m_szDir, dirstart, SDL_arraysize(m_szDir));//,(filestart-dirstart)); + int len = min((dirstart-pURL), (int)SDL_arraysize(m_szHost)); SDL_strlcpy(m_szHost, pURL, len); } @@ -326,7 +326,7 @@ void ChttpGet::WorkerThread() LOCALFILE = NULL; return; } - SDL_snprintf(szCommand,sizeof(szCommand),"GET %s%s HTTP/1.1\nAccept: */*\nAccept-Encoding: deflate\nHost: %s\n\n\n",m_ProxyEnabled?"":"/",m_ProxyEnabled?m_URL:m_szDir,m_szHost); + SDL_snprintf(szCommand,SDL_arraysize(szCommand),"GET %s%s HTTP/1.1\nAccept: */*\nAccept-Encoding: deflate\nHost: %s\n\n\n",m_ProxyEnabled?"":"/",m_ProxyEnabled?m_URL:m_szDir,m_szHost); send(m_DataSock,szCommand,strlen(szCommand),0); p = GetHTTPLine(); if(SDL_strncasecmp("HTTP/",p,5)==0) @@ -598,7 +598,7 @@ char *ChttpGet::GetHTTPLine() } else { chunk[1] = '\0'; - SDL_strlcat(recv_buffer, chunk, sizeof(recv_buffer)); + SDL_strlcat(recv_buffer, chunk, SDL_arraysize(recv_buffer)); } SDL_Delay(1); diff --git a/src/io/keycontrol.cpp b/src/io/keycontrol.cpp index 9ab8794..508018c 100644 --- a/src/io/keycontrol.cpp +++ b/src/io/keycontrol.cpp @@ -713,7 +713,7 @@ void debug_cycle_targeted_ship(int delta) sip = &Ship_info[si_index]; // if it has test in the name, jump over it - SDL_strlcpy(name, sip->name, sizeof(name)); + SDL_strlcpy(name, sip->name, SDL_arraysize(name)); SDL_strlwr(name); if ( strstr(name,NOX("test")) != NULL ) continue; diff --git a/src/io/timer.cpp b/src/io/timer.cpp index 5614f3b..76a29dc 100644 --- a/src/io/timer.cpp +++ b/src/io/timer.cpp @@ -299,7 +299,7 @@ void timing_frame_start() Timing_frame.start = timer_get_microseconds(); for(idx=0; idx max_len){ @@ -913,7 +913,7 @@ void lcl_ext_localize(char *in, char *out, int max_len, int *id) } // attempt to find the string - if(lcl_ext_lookup(lookup_str, sizeof(lookup_str), str_id)){ + if(lcl_ext_lookup(lookup_str, SDL_arraysize(lookup_str), str_id)){ // copy to the outgoing string SDL_assert(strlen(lookup_str) <= (unsigned int)(max_len - 1)); @@ -1179,7 +1179,7 @@ int lcl_ext_lookup_sub(char *text, char *out, const int max_out, int id) // scanning for a line of text case TS_SCANNING: // if the first word is #end, we're done with the file altogether - SDL_strlcpy(text_copy, text, sizeof(text_copy)); + SDL_strlcpy(text_copy, text, SDL_arraysize(text_copy)); tok = strtok(text_copy, " \n"); if((tok != NULL) && !SDL_strcasecmp(tok, "#end")){ return 3; @@ -1300,11 +1300,11 @@ void lcl_ext_setup_pointers() // seek to the currently active language memset(language_string, 0, 128); - SDL_strlcpy(language_string, "#", sizeof(language_string)); + SDL_strlcpy(language_string, "#", SDL_arraysize(language_string)); if(!SDL_strcasecmp(DEFAULT_LANGUAGE, Lcl_languages[Lcl_current_lang].lang_name)){ - SDL_strlcat(language_string, "default", sizeof(language_string)); + SDL_strlcat(language_string, "default", SDL_arraysize(language_string)); } else { - SDL_strlcat(language_string, Lcl_languages[Lcl_current_lang].lang_name, sizeof(language_string)); + SDL_strlcat(language_string, Lcl_languages[Lcl_current_lang].lang_name, SDL_arraysize(language_string)); } memset(line, 0, 1024); @@ -1569,14 +1569,14 @@ void lcl_translate_brief_icon_name(char *name, const int max_len) } else if ((pos = strstr(name, "Transport")) != NULL) { pos += 9; // strlen of "transport" - SDL_strlcpy(buf, "Transporter", sizeof(buf)); - SDL_strlcat(buf, pos, sizeof(buf)); + SDL_strlcpy(buf, "Transporter", SDL_arraysize(buf)); + SDL_strlcat(buf, pos, SDL_arraysize(buf)); SDL_strlcpy(name, buf, max_len); } else if ((pos = strstr(name, "Jump Node")) != NULL) { pos += 9; // strlen of "jump node" - SDL_strlcpy(buf, "Sprungknoten", sizeof(buf)); - SDL_strlcat(buf, pos, sizeof(buf)); + SDL_strlcpy(buf, "Sprungknoten", SDL_arraysize(buf)); + SDL_strlcat(buf, pos, SDL_arraysize(buf)); SDL_strlcpy(name, buf, max_len); } else if (!SDL_strcasecmp(name, "Orion under repair")) { @@ -1716,14 +1716,14 @@ void lcl_translate_brief_icon_name_pl(char *name, const int max_len) } else if ((pos = strstr(name, "Transport")) != NULL) { pos += 9; // strlen of "transport" - SDL_strlcpy(buf, "Transporter", sizeof(buf)); - SDL_strlcat(buf, pos, sizeof(buf)); + SDL_strlcpy(buf, "Transporter", SDL_arraysize(buf)); + SDL_strlcat(buf, pos, SDL_arraysize(buf)); SDL_strlcpy(name, buf, max_len); } else if ((pos = strstr(name, "Jump Node")) != NULL) { pos += 9; // strlen of "jump node" - SDL_strlcpy(buf, "W\xEAze\xB3 skokowy", sizeof(buf)); - SDL_strlcat(buf, pos, sizeof(buf)); + SDL_strlcpy(buf, "W\xEAze\xB3 skokowy", SDL_arraysize(buf)); + SDL_strlcat(buf, pos, SDL_arraysize(buf)); SDL_strlcpy(name, buf, max_len); } else if (!SDL_strcasecmp(name, "Orion under repair")) { @@ -1757,32 +1757,32 @@ void lcl_translate_targetbox_name(char *name, const int max_len) if ((pos = strstr(name, "Sentry")) != NULL) { pos += 6; // strlen of "sentry" - SDL_strlcpy(buf, "Sperrgesch\x81tz", sizeof(buf)); - SDL_strlcat(buf, pos, sizeof(buf)); + SDL_strlcpy(buf, "Sperrgesch\x81tz", SDL_arraysize(buf)); + SDL_strlcat(buf, pos, SDL_arraysize(buf)); SDL_strlcpy(name, buf, max_len); } else if ((pos = strstr(name, "Support")) != NULL) { pos += 7; // strlen of "support" - SDL_strlcpy(buf, "Versorger", sizeof(buf)); - SDL_strlcat(buf, pos, sizeof(buf)); + SDL_strlcpy(buf, "Versorger", SDL_arraysize(buf)); + SDL_strlcat(buf, pos, SDL_arraysize(buf)); SDL_strlcpy(name, buf, max_len); } else if ((pos = strstr(name, "Unknown")) != NULL) { pos += 7; // strlen of "unknown" - SDL_strlcpy(buf, "Unbekannt", sizeof(buf)); - SDL_strlcat(buf, pos, sizeof(buf)); + SDL_strlcpy(buf, "Unbekannt", SDL_arraysize(buf)); + SDL_strlcat(buf, pos, SDL_arraysize(buf)); SDL_strlcpy(name, buf, max_len); } else if ((pos = strstr(name, "Drone")) != NULL) { pos += 5; // strlen of "drone" - SDL_strlcpy(buf, "Drohne", sizeof(buf)); - SDL_strlcat(buf, pos, sizeof(buf)); + SDL_strlcpy(buf, "Drohne", SDL_arraysize(buf)); + SDL_strlcat(buf, pos, SDL_arraysize(buf)); SDL_strlcpy(name, buf, max_len); } else if ((pos = strstr(name, "Jump Node")) != NULL) { pos += 9; // strlen of "jump node" - SDL_strlcpy(buf, "Sprungknoten", sizeof(buf)); - SDL_strlcat(buf, pos, sizeof(buf)); + SDL_strlcpy(buf, "Sprungknoten", SDL_arraysize(buf)); + SDL_strlcat(buf, pos, SDL_arraysize(buf)); SDL_strlcpy(name, buf, max_len); } else if (!SDL_strcasecmp(name, "Instructor")) { @@ -1809,32 +1809,32 @@ void lcl_translate_targetbox_name_pl(char *name, const int max_len) if ((pos = strstr(name, "Sentry")) != NULL) { pos += 6; // strlen of "sentry" - SDL_strlcpy(buf, "Stra\xBFnik", sizeof(buf)); - SDL_strlcat(buf, pos, sizeof(buf)); + SDL_strlcpy(buf, "Stra\xBFnik", SDL_arraysize(buf)); + SDL_strlcat(buf, pos, SDL_arraysize(buf)); SDL_strlcpy(name, buf, max_len); } else if ((pos = strstr(name, "Support")) != NULL) { pos += 7; // strlen of "support" - SDL_strlcpy(buf, "Wsparcie", sizeof(buf)); - SDL_strlcat(buf, pos, sizeof(buf)); + SDL_strlcpy(buf, "Wsparcie", SDL_arraysize(buf)); + SDL_strlcat(buf, pos, SDL_arraysize(buf)); SDL_strlcpy(name, buf, max_len); } else if ((pos = strstr(name, "Unknown")) != NULL) { pos += 7; // strlen of "unknown" - SDL_strlcpy(buf, "Nieznany", sizeof(buf)); - SDL_strlcat(buf, pos, sizeof(buf)); + SDL_strlcpy(buf, "Nieznany", SDL_arraysize(buf)); + SDL_strlcat(buf, pos, SDL_arraysize(buf)); SDL_strlcpy(name, buf, max_len); } else if ((pos = strstr(name, "Drone")) != NULL) { pos += 5; // strlen of "drone" - SDL_strlcpy(buf, "Sonda", sizeof(buf)); - SDL_strlcat(buf, pos, sizeof(buf)); + SDL_strlcpy(buf, "Sonda", SDL_arraysize(buf)); + SDL_strlcat(buf, pos, SDL_arraysize(buf)); SDL_strlcpy(name, buf, max_len); } else if ((pos = strstr(name, "Jump Node")) != NULL) { pos += 9; // strlen of "jump node" - SDL_strlcpy(buf, "W\xEAze\xB3 skokowy", sizeof(buf)); - SDL_strlcat(buf, pos, sizeof(buf)); + SDL_strlcpy(buf, "W\xEAze\xB3 skokowy", SDL_arraysize(buf)); + SDL_strlcat(buf, pos, SDL_arraysize(buf)); SDL_strlcpy(name, buf, max_len); } else if (!SDL_strcasecmp(name, "Instructor")) { diff --git a/src/menuui/barracks.cpp b/src/menuui/barracks.cpp index f3a2496..e5b382b 100644 --- a/src/menuui/barracks.cpp +++ b/src/menuui/barracks.cpp @@ -640,7 +640,7 @@ int barracks_new_pilot_selected() int i; barracks_init_stats(&Cur_pilot->stats); for (i=0; iimage_filename, sizeof(stripped)); + SDL_strlcpy(stripped, Cur_pilot->image_filename, SDL_arraysize(stripped)); barracks_strip_pcx(stripped); if (!SDL_strcasecmp(stripped, Pilot_image_names[i])) { break; @@ -648,7 +648,7 @@ int barracks_new_pilot_selected() } Pic_number = i; for ( i=0; isquad_filename, sizeof(stripped)); + SDL_strlcpy(stripped, Cur_pilot->squad_filename, SDL_arraysize(stripped)); barracks_strip_pcx(stripped); if (!SDL_strcasecmp(stripped, Pilot_squad_image_names[i])) { break; @@ -747,8 +747,8 @@ int barracks_pilot_accepted() // when we store the LastPlayer key, we have to mark it as being single or multiplayer, so we know where to look for him // (since we could have a single and a multiplayer pilot with the same callsign) // we'll distinguish them by putting an M and the end of the multiplayer callsign and a P at the end of a single player - SDL_strlcpy(str, Cur_pilot->callsign, sizeof(str)); - SDL_strlcat(str, is_pilot_multi(Cur_pilot) ? NOX("M") : NOX("S"), sizeof(str)); + SDL_strlcpy(str, Cur_pilot->callsign, SDL_arraysize(str)); + SDL_strlcat(str, is_pilot_multi(Cur_pilot) ? NOX("M") : NOX("S"), SDL_arraysize(str)); os_config_write_string( NULL, "LastPlayer", str ); return 0; } @@ -826,7 +826,7 @@ void barracks_prev_pic() // copy pilot pic filename into pilot struct if ((Pic_number >= 0) && (Pic_number < Num_pilot_images)) { - SDL_strlcpy(Cur_pilot->image_filename, Pilot_image_names[Pic_number], sizeof(Cur_pilot->image_filename)); + SDL_strlcpy(Cur_pilot->image_filename, Pilot_image_names[Pic_number], SDL_arraysize(Cur_pilot->image_filename)); } // play scroll sound @@ -850,7 +850,7 @@ void barracks_next_pic() // copy pilot pic filename into pilot struct if ((Pic_number >= 0) && (Pic_number < Num_pilot_images)){ - SDL_strlcpy(Cur_pilot->image_filename, Pilot_image_names[Pic_number], sizeof(Cur_pilot->image_filename)); + SDL_strlcpy(Cur_pilot->image_filename, Pilot_image_names[Pic_number], SDL_arraysize(Cur_pilot->image_filename)); } // play scroll sound @@ -874,7 +874,7 @@ void barracks_prev_squad_pic() // copy pilot pic filename into pilot struct if ((Pic_squad_number >= 0) && (Pic_squad_number < Num_pilot_squad_images)) { - SDL_strlcpy(Cur_pilot->squad_filename, Pilot_squad_image_names[Pic_squad_number], sizeof(Cur_pilot->squad_filename)); + SDL_strlcpy(Cur_pilot->squad_filename, Pilot_squad_image_names[Pic_squad_number], SDL_arraysize(Cur_pilot->squad_filename)); } // play scroll sound @@ -898,7 +898,7 @@ void barracks_next_squad_pic() // copy pilot pic filename into pilot struct if ((Pic_squad_number >= 0) && (Pic_squad_number < Num_pilot_squad_images)){ - SDL_strlcpy(Cur_pilot->squad_filename, Pilot_squad_image_names[Pic_squad_number], sizeof(Cur_pilot->squad_filename)); + SDL_strlcpy(Cur_pilot->squad_filename, Pilot_squad_image_names[Pic_squad_number], SDL_arraysize(Cur_pilot->squad_filename)); } // play scroll sound @@ -924,7 +924,7 @@ void barracks_delete_pilot() active = 1; } - SDL_strlcpy(buf, Pilots[Selected_line], sizeof(buf)); + SDL_strlcpy(buf, Pilots[Selected_line], SDL_arraysize(buf)); for (int i=Selected_line; icallsign, Player_sel_mode == PLAYER_SELECT_MODE_MULTI)) { z = popup(0, 2, POPUP_CANCEL, POPUP_OK, temp); if (z != 1) break; } - SDL_strlcpy(old_pic, Cur_pilot->image_filename, sizeof(old_pic)); - SDL_strlcpy(old_squad_pic, Cur_pilot->squad_filename, sizeof(old_squad_pic)); - SDL_strlcpy(old_squad, Cur_pilot->squad_name, sizeof(old_squad)); + SDL_strlcpy(old_pic, Cur_pilot->image_filename, SDL_arraysize(old_pic)); + SDL_strlcpy(old_squad_pic, Cur_pilot->squad_filename, SDL_arraysize(old_squad_pic)); + SDL_strlcpy(old_squad, Cur_pilot->squad_name, SDL_arraysize(old_squad)); init_new_pilot(Cur_pilot, 0); - SDL_strlcpy(Cur_pilot->image_filename, old_pic, sizeof(Cur_pilot->image_filename)); - SDL_strlcpy(Cur_pilot->squad_filename, old_squad_pic, sizeof(Cur_pilot->squad_filename)); - SDL_strlcpy(Cur_pilot->squad_name, old_squad, sizeof(Cur_pilot->squad_name)); + SDL_strlcpy(Cur_pilot->image_filename, old_pic, SDL_arraysize(Cur_pilot->image_filename)); + SDL_strlcpy(Cur_pilot->squad_filename, old_squad_pic, SDL_arraysize(Cur_pilot->squad_filename)); + SDL_strlcpy(Cur_pilot->squad_name, old_squad, SDL_arraysize(Cur_pilot->squad_name)); if (Player_sel_mode == PLAYER_SELECT_MODE_SINGLE) { Cur_pilot->flags |= PLAYER_FLAGS_IS_MULTI; write_pilot_file(); @@ -1313,7 +1313,7 @@ void barracks_accept_new_pilot_callsign() for (i=1; icallsign, buf, sizeof(Cur_pilot->callsign)); + SDL_strlcpy(Cur_pilot->callsign, buf, SDL_arraysize(Cur_pilot->callsign)); init_new_pilot(Cur_pilot, !Clone_flag); // again, make sure we set his flags correctly to ensure that he gets saved to the proper directory and gets @@ -1373,7 +1373,7 @@ void barracks_draw_pilot_pic() // print number of the current pic char buf[40]; - SDL_snprintf(buf, sizeof(buf), XSTR( "%d of %d", 71), Pic_number + 1, Num_pilot_images); + SDL_snprintf(buf, SDL_arraysize(buf), XSTR( "%d of %d", 71), Pic_number + 1, Num_pilot_images); gr_printf(Barracks_image_number_coords[gr_screen.res][BARRACKS_X_COORD], Barracks_image_number_coords[gr_screen.res][BARRACKS_Y_COORD], buf); } } else { @@ -1398,7 +1398,7 @@ void barracks_draw_squad_pic() // print number of current squad pic if(Player_sel_mode != PLAYER_SELECT_MODE_SINGLE){ - SDL_snprintf(buf, sizeof(buf), XSTR( "%d of %d", 71), Pic_squad_number+1, Num_pilot_squad_images); + SDL_snprintf(buf, SDL_arraysize(buf), XSTR( "%d of %d", 71), Pic_squad_number+1, Num_pilot_squad_images); gr_printf(Barracks_squad_number_coords[gr_screen.res][BARRACKS_X_COORD], Barracks_squad_number_coords[gr_screen.res][BARRACKS_Y_COORD], buf); } } diff --git a/src/menuui/credits.cpp b/src/menuui/credits.cpp index ec453c4..5c3da3a 100644 --- a/src/menuui/credits.cpp +++ b/src/menuui/credits.cpp @@ -729,9 +729,9 @@ void credits_do_frame(float frametime) char buf[40]; if (gr_screen.res == GR_1024) { - SDL_snprintf(buf, sizeof(buf), NOX("2_CrIm%.2d"), Credits_artwork_index); + SDL_snprintf(buf, SDL_arraysize(buf), NOX("2_CrIm%.2d"), Credits_artwork_index); } else { - SDL_snprintf(buf, sizeof(buf), NOX("CrIm%.2d"), Credits_artwork_index); + SDL_snprintf(buf, SDL_arraysize(buf), NOX("CrIm%.2d"), Credits_artwork_index); } Credits_bmps[Credits_artwork_index] = bm_load(buf); } @@ -740,9 +740,9 @@ void credits_do_frame(float frametime) char buf[40]; if (gr_screen.res == GR_1024) { - SDL_snprintf(buf, sizeof(buf), NOX("2_CrIm%.2d"), Credits_artwork_index); + SDL_snprintf(buf, SDL_arraysize(buf), NOX("2_CrIm%.2d"), Credits_artwork_index); } else { - SDL_snprintf(buf, sizeof(buf), NOX("CrIm%.2d"), next); + SDL_snprintf(buf, SDL_arraysize(buf), NOX("CrIm%.2d"), next); } Credits_bmps[next] = bm_load(buf); } diff --git a/src/menuui/mainhallmenu.cpp b/src/menuui/mainhallmenu.cpp index d1ad292..398c27c 100644 --- a/src/menuui/mainhallmenu.cpp +++ b/src/menuui/mainhallmenu.cpp @@ -826,7 +826,7 @@ void main_hall_init(int main_hall_num) // create the snazzy interface and load up the info from the table snazzy_menu_init(); - read_menu_tbl(NOX("MAIN HALL"), temp, sizeof(temp), whee, sizeof(whee), Main_hall_region, &Main_hall_num_options, 0); + read_menu_tbl(NOX("MAIN HALL"), temp, SDL_arraysize(temp), whee, SDL_arraysize(whee), Main_hall_region, &Main_hall_num_options, 0); // assign the proper main hall data SDL_assert((main_hall_num >= 0) && (main_hall_num < NUM_MAIN_HALLS)); @@ -939,7 +939,7 @@ void main_hall_init(int main_hall_num) */ Main_hall_region_linger_stamp = -1; - SDL_strlcpy(Main_hall_campaign_cheat, "", sizeof(Main_hall_campaign_cheat)); + SDL_strlcpy(Main_hall_campaign_cheat, "", SDL_arraysize(Main_hall_campaign_cheat)); // zero out the door sounds for(idx=0;idxnum_door_sounds;idx++){ @@ -1175,10 +1175,10 @@ void main_hall_do(float frametime) } else { if (Num_recent_missions > 0) { - SDL_strlcpy( Game_current_mission_filename, Recent_missions[0], sizeof(Game_current_mission_filename) ); + SDL_strlcpy( Game_current_mission_filename, Recent_missions[0], SDL_arraysize(Game_current_mission_filename) ); } else { mission_load_up_campaign(); - SDL_strlcpy( Game_current_mission_filename, Campaign.missions[0].name, sizeof(Game_current_mission_filename) ); + SDL_strlcpy( Game_current_mission_filename, Campaign.missions[0].name, SDL_arraysize(Game_current_mission_filename) ); } Campaign.current_mission = -1; @@ -1198,7 +1198,7 @@ void main_hall_do(float frametime) char temp[100]; game_increase_skill_level(); - SDL_snprintf(temp, sizeof(temp), XSTR( "Skill level set to %s.", 370), Skill_level_names(Game_skill_level)); + SDL_snprintf(temp, SDL_arraysize(temp), XSTR( "Skill level set to %s.", 370), Skill_level_names(Game_skill_level)); main_hall_set_notify_string(temp); break; @@ -1797,7 +1797,7 @@ void main_hall_handle_random_intercom_sounds() // set the notification string with its decay timeout void main_hall_set_notify_string(const char *str) { - SDL_strlcpy(Main_hall_notify_text, str, sizeof(Main_hall_notify_text)); + SDL_strlcpy(Main_hall_notify_text, str, SDL_arraysize(Main_hall_notify_text)); Main_hall_notify_stamp = timestamp(MAIN_HALL_NOTIFY_TIME); } @@ -1807,7 +1807,7 @@ void main_hall_notify_do() if(Main_hall_notify_stamp != -1){ // if the text time has expired if(timestamp_elapsed(Main_hall_notify_stamp)){ - SDL_strlcpy(Main_hall_notify_text, "", sizeof(Main_hall_notify_text)); + SDL_strlcpy(Main_hall_notify_text, "", SDL_arraysize(Main_hall_notify_text)); Main_hall_notify_stamp = -1; } else { int w,h; @@ -1867,7 +1867,7 @@ void main_hall_blit_version() int w; // format the version string - get_version_string(version_string, sizeof(version_string)); + get_version_string(version_string, SDL_arraysize(version_string)); // get the length of the string gr_get_string_size(&w,NULL,version_string); @@ -1938,7 +1938,7 @@ void main_hall_process_help_stuff() } // otherwise print out the message - SDL_strlcpy(str, XSTR( "Press F1 for help", 371), sizeof(str)); + SDL_strlcpy(str, XSTR( "Press F1 for help", 371), SDL_arraysize(str)); gr_get_string_size(&w, &h, str); int y_anim_offset = Main_hall_f1_text_frame; diff --git a/src/menuui/mainhalltemp.cpp b/src/menuui/mainhalltemp.cpp index 6c8ede9..5f6edba 100644 --- a/src/menuui/mainhalltemp.cpp +++ b/src/menuui/mainhalltemp.cpp @@ -171,10 +171,10 @@ void mht_do() } if (Num_recent_missions > 0) { - SDL_strlcpy( Game_current_mission_filename, Recent_missions[0], sizeof(Game_current_mission_filename) ); + SDL_strlcpy( Game_current_mission_filename, Recent_missions[0], SDL_arraysize(Game_current_mission_filename) ); } else { mission_load_up_campaign(); - SDL_strlcpy( Game_current_mission_filename, Campaign.missions[0].name, sizeof(Game_current_mission_filename) ); + SDL_strlcpy( Game_current_mission_filename, Campaign.missions[0].name, SDL_arraysize(Game_current_mission_filename) ); } Campaign.current_mission = -1; diff --git a/src/menuui/optionsmenu.cpp b/src/menuui/optionsmenu.cpp index ecc15fe..c8cc754 100644 --- a/src/menuui/optionsmenu.cpp +++ b/src/menuui/optionsmenu.cpp @@ -803,7 +803,7 @@ void options_play_voice_clip() void options_add_notify(const char *str) { - SDL_strlcpy(Options_notify_string, str, sizeof(Options_notify_string)); + SDL_strlcpy(Options_notify_string, str, SDL_arraysize(Options_notify_string)); Options_notify_stamp = timestamp(OPTIONS_NOTIFY_TIME); } diff --git a/src/menuui/optionsmenumulti.cpp b/src/menuui/optionsmenumulti.cpp index bdba251..f30824e 100644 --- a/src/menuui/optionsmenumulti.cpp +++ b/src/menuui/optionsmenumulti.cpp @@ -936,7 +936,7 @@ void options_multi_add_notify(const char *str) // copy the string memset(Om_notify_string,0,255); if(str != NULL){ - SDL_strlcpy(Om_notify_string, str, sizeof(Om_notify_string)); + SDL_strlcpy(Om_notify_string, str, SDL_arraysize(Om_notify_string)); } // set the timestamp @@ -971,7 +971,7 @@ void options_multi_notify_process() y_start = OM_NOTIFY_Y; gr_set_color_fast(&Color_bright); for(idx=0;idxplayer->callsign, sizeof(str)); + SDL_strlcpy(str, Om_vox_players[idx]->player->callsign, SDL_arraysize(str)); gr_force_fit_string(str, CALLSIGN_LEN+1, Om_vox_plist_coords[gr_screen.res][2]); // blit the callsign diff --git a/src/menuui/playermenu.cpp b/src/menuui/playermenu.cpp index 0001208..2266d45 100644 --- a/src/menuui/playermenu.cpp +++ b/src/menuui/playermenu.cpp @@ -1009,8 +1009,8 @@ void player_select_delete_pilot() // tack on the full path and the pilot file extension // build up the path name length // make sure we do this based upon whether we're in single or multiplayer mode - SDL_strlcpy( filename, Pilots[Player_select_pilot], sizeof(filename) ); - SDL_strlcat( filename, NOX(".plr"), sizeof(filename) ); + SDL_strlcpy( filename, Pilots[Player_select_pilot], SDL_arraysize(filename) ); + SDL_strlcat( filename, NOX(".plr"), SDL_arraysize(filename) ); // attempt to delete the pilot if (Player_select_mode == PLAYER_SELECT_MODE_SINGLE) { @@ -1080,7 +1080,7 @@ int player_select_get_last_pilot_info() if(last_player == NULL){ return 0; } else { - SDL_strlcpy(Player_select_last_pilot, last_player, sizeof(Player_select_last_pilot)); + SDL_strlcpy(Player_select_last_pilot, last_player, SDL_arraysize(Player_select_last_pilot)); } // determine if he was a single or multi-player based upon the last character in his callsign @@ -1318,7 +1318,7 @@ void player_select_process_input(int k) Player->flags |= PLAYER_FLAGS_STRUCTURE_IN_USE; } - SDL_strlcpy(Player->callsign, buf, sizeof(Player->callsign)); + SDL_strlcpy(Player->callsign, buf, SDL_arraysize(Player->callsign)); init_new_pilot(Player, !Player_select_clone_flag); // set him as being a multiplayer pilot if we're in the correct mode @@ -1373,19 +1373,19 @@ void player_select_display_copyright() gr_set_color_fast(&Color_bright); if (Lcl_gr) { - SDL_snprintf(Copyright_msg1, sizeof(Copyright_msg1), XSTR("Descent: FreeSpace - The Great War, Copyright %c 1998, Volition, Inc.", 384), '\xA8'); + SDL_snprintf(Copyright_msg1, SDL_arraysize(Copyright_msg1), XSTR("Descent: FreeSpace - The Great War, Copyright %c 1998, Volition, Inc.", 384), '\xA8'); } else { - SDL_snprintf(Copyright_msg1, sizeof(Copyright_msg1), XSTR("Descent: FreeSpace - The Great War, Copyright %c 1998, Volition, Inc.", 384), '\x83'); + SDL_snprintf(Copyright_msg1, SDL_arraysize(Copyright_msg1), XSTR("Descent: FreeSpace - The Great War, Copyright %c 1998, Volition, Inc.", 384), '\x83'); } - SDL_snprintf(Copyright_msg2, sizeof(Copyright_msg2), XSTR("All Rights Reserved", 385)); + SDL_snprintf(Copyright_msg2, SDL_arraysize(Copyright_msg2), XSTR("All Rights Reserved", 385)); #else gr_set_color_fast(&Color_white); - SDL_snprintf(Copyright_msg1, sizeof(Copyright_msg1), NOX("FreeSpace 2")); + SDL_snprintf(Copyright_msg1, SDL_arraysize(Copyright_msg1), NOX("FreeSpace 2")); if (Lcl_gr) { - SDL_snprintf(Copyright_msg2, sizeof(Copyright_msg2), XSTR("Copyright %c 1999, Volition, Inc. All rights reserved.", 385), '\xA8'); + SDL_snprintf(Copyright_msg2, SDL_arraysize(Copyright_msg2), XSTR("Copyright %c 1999, Volition, Inc. All rights reserved.", 385), '\xA8'); } else { - SDL_snprintf(Copyright_msg2, sizeof(Copyright_msg2), XSTR("Copyright %c 1999, Volition, Inc. All rights reserved.", 385), '\x83'); + SDL_snprintf(Copyright_msg2, SDL_arraysize(Copyright_msg2), XSTR("Copyright %c 1999, Volition, Inc. All rights reserved.", 385), '\x83'); } #endif // MAKE_FS1 @@ -1435,14 +1435,14 @@ int player_select_pilot_file_filter(const char *filename) void player_select_set_bottom_text(const char *txt) { if (txt) { - SDL_strlcpy(Player_select_bottom_text, txt, sizeof(Player_select_bottom_text)); + SDL_strlcpy(Player_select_bottom_text, txt, SDL_arraysize(Player_select_bottom_text)); } } void player_select_set_middle_text(const char *txt) { if (txt) { - SDL_strlcpy(Player_select_middle_text, txt, sizeof(Player_select_middle_text)); + SDL_strlcpy(Player_select_middle_text, txt, SDL_arraysize(Player_select_middle_text)); } } @@ -1463,7 +1463,7 @@ void player_select_eval_very_first_pilot() if((Player_select_num_pilots == 1) && (Player_select_initial_count == 0)){ // set up the data Player_select_very_first_pilot = 1; - SDL_strlcpy(Player_select_very_first_pilot_callsign, Pilots[Player_select_pilot], sizeof(Player_select_very_first_pilot_callsign)); + SDL_strlcpy(Player_select_very_first_pilot_callsign, Pilots[Player_select_pilot], SDL_arraysize(Player_select_very_first_pilot_callsign)); } } } @@ -1591,7 +1591,7 @@ void player_tips_popup() char all_txt[2048]; do { - SDL_snprintf(all_txt, sizeof(all_txt), XSTR("NEW USER TIP\n\n%s", 1565), Player_tips[tip]); + SDL_snprintf(all_txt, SDL_arraysize(all_txt), XSTR("NEW USER TIP\n\n%s", 1565), Player_tips[tip]); ret = popup(PF_NO_SPECIAL_BUTTONS | PF_TITLE | PF_TITLE_WHITE, 3, XSTR("&Ok", 669), XSTR("&Next", 1444), XSTR("Don't show me this again", 1443), all_txt); // now what? diff --git a/src/menuui/readyroom.cpp b/src/menuui/readyroom.cpp index 1fc925b..a4442a1 100644 --- a/src/menuui/readyroom.cpp +++ b/src/menuui/readyroom.cpp @@ -609,14 +609,14 @@ int build_standalone_mission_list_do_frame() if (Num_standalone_missions > 0) { // sanity check if (strlen(Mission_filenames[Num_standalone_missions_with_info]) < MAX_FILENAME_LEN - 4) { // sanity check? - SDL_strlcpy(filename, Mission_filenames[Num_standalone_missions_with_info], sizeof(filename)); + SDL_strlcpy(filename, Mission_filenames[Num_standalone_missions_with_info], SDL_arraysize(filename)); // update popup - SDL_snprintf(str, sizeof(str), XSTR("Single Mission\n\n%s",989), filename); + SDL_snprintf(str, SDL_arraysize(str), XSTR("Single Mission\n\n%s",989), filename); popup_change_text(str); // tack on an extension - SDL_strlcat(filename, FS_MISSION_FILE_EXT, sizeof(filename)); + SDL_strlcat(filename, FS_MISSION_FILE_EXT, SDL_arraysize(filename)); if (!get_mission_info(filename)) { Standalone_mission_names[Num_standalone_missions_with_info] = strdup(The_mission.name); Standalone_mission_flags[Num_standalone_missions_with_info] = The_mission.game_type; @@ -667,7 +667,7 @@ int build_campaign_mission_list_do_frame() } // change popup - SDL_snprintf(str, sizeof(str), XSTR("Campaign Mission\n\n%s",990), Campaign.missions[Num_campaign_missions_with_info].name); + SDL_snprintf(str, SDL_arraysize(str), XSTR("Campaign Mission\n\n%s",990), Campaign.missions[Num_campaign_missions_with_info].name); popup_change_text(str); // Set global variable so we we'll have list available next time @@ -733,7 +733,7 @@ void sim_room_build_listing() // determine some extra information int flags = 0; memset(full_filename, 0, 256); - SDL_strlcpy(full_filename, cf_add_ext(Mission_filenames[i], FS_MISSION_FILE_EXT), sizeof(full_filename)); + SDL_strlcpy(full_filename, cf_add_ext(Mission_filenames[i], FS_MISSION_FILE_EXT), SDL_arraysize(full_filename)); fs_builtin_mission *fb = game_find_builtin_mission(full_filename); if((fb != NULL) && (fb->flags & FSB_FROM_VOLITION)){ flags |= READYROOM_FLAG_FROM_VOLITION; @@ -765,7 +765,7 @@ void sim_room_build_listing() // determine some extra information int flags = 0; memset(full_filename, 0, 256); - SDL_strlcpy(full_filename, cf_add_ext(Campaign.missions[i].name, FS_MISSION_FILE_EXT), sizeof(full_filename)); + SDL_strlcpy(full_filename, cf_add_ext(Campaign.missions[i].name, FS_MISSION_FILE_EXT), SDL_arraysize(full_filename)); fs_builtin_mission *fb = game_find_builtin_mission(full_filename); if((fb != NULL) && (fb->flags & FSB_FROM_VOLITION)){ flags |= READYROOM_FLAG_FROM_VOLITION; @@ -1018,7 +1018,7 @@ void sim_room_commit() return; } - SDL_strlcpy(Game_current_mission_filename, sim_room_lines[Selected_line].filename, sizeof(Game_current_mission_filename)); + SDL_strlcpy(Game_current_mission_filename, sim_room_lines[Selected_line].filename, SDL_arraysize(Game_current_mission_filename)); Game_mode &= ~(GM_CAMPAIGN_MODE); // be sure this bit is clear @@ -1167,13 +1167,13 @@ void sim_room_init() Scroll_offset = Selected_line = 0; - SDL_strlcpy(Cur_campaign, Player->current_campaign, sizeof(Cur_campaign)); + SDL_strlcpy(Cur_campaign, Player->current_campaign, SDL_arraysize(Cur_campaign)); mission_load_up_campaign(); mission_campaign_next_mission(); Num_campaigns = Num_campaign_missions = 0; Get_file_list_filter = sim_room_campaign_mission_filter; - SDL_snprintf(wild_card, sizeof(wild_card), "*%s", FS_CAMPAIGN_FILE_EXT); + SDL_snprintf(wild_card, SDL_arraysize(wild_card), "*%s", FS_CAMPAIGN_FILE_EXT); Num_campaigns = cf_get_file_list(MAX_CAMPAIGNS, Campaign_file_names, CF_TYPE_MISSIONS, wild_card, CF_SORT_NAME); Hash_table_inited = 0; @@ -1191,7 +1191,7 @@ void sim_room_init() gr_flip(); Get_file_list_filter = sim_room_standalone_mission_filter; - SDL_snprintf(wild_card, sizeof(wild_card), "*%s", FS_MISSION_FILE_EXT); + SDL_snprintf(wild_card, SDL_arraysize(wild_card), "*%s", FS_MISSION_FILE_EXT); Num_standalone_missions = cf_get_file_list(MAX_MISSIONS, Mission_filenames, CF_TYPE_MISSIONS, wild_card, CF_SORT_NAME); Num_campaign_missions_with_info = Num_standalone_missions_with_info = Standalone_mission_names_inited = Campaign_names_inited = Campaign_mission_names_inited = 0; @@ -1393,18 +1393,18 @@ void sim_room_do_frame(float frametime) gr_set_font(FONT1); if (Player->readyroom_listing_mode == MODE_CAMPAIGNS) { gr_set_color_fast(&Color_text_heading); - SDL_strlcpy(buf, Campaign.name, sizeof(buf)); + SDL_strlcpy(buf, Campaign.name, SDL_arraysize(buf)); gr_force_fit_string(buf, 255, list_w1); gr_printf(list_x1, Mission_list_coords[gr_screen.res][1], buf); if (Campaign.filename) { - SDL_snprintf(buf, sizeof(buf), NOX("%s%s"), Campaign.filename, FS_CAMPAIGN_FILE_EXT); + SDL_snprintf(buf, SDL_arraysize(buf), NOX("%s%s"), Campaign.filename, FS_CAMPAIGN_FILE_EXT); gr_force_fit_string(buf, 255, list_w2); gr_printf(list_x2, Mission_list_coords[gr_screen.res][1], buf); // blit the proper icons if necessary char full_name[256]; - SDL_strlcpy(full_name, cf_add_ext(Campaign.filename,FS_CAMPAIGN_FILE_EXT), sizeof(full_name)); + SDL_strlcpy(full_name, cf_add_ext(Campaign.filename,FS_CAMPAIGN_FILE_EXT), SDL_arraysize(full_name)); fs_builtin_mission *fb = game_find_builtin_mission(full_name); if(fb != NULL){ // sim_room_blit_icons(0, Mission_list_coords[gr_screen.res][1], fb, 0); @@ -1430,12 +1430,12 @@ void sim_room_do_frame(float frametime) else gr_set_color_fast(&Color_text_normal); - SDL_strlcpy(buf, sim_room_lines[line].name, sizeof(buf)); + SDL_strlcpy(buf, sim_room_lines[line].name, SDL_arraysize(buf)); gr_force_fit_string(buf, 255, list_x1 + list_w1 - sim_room_lines[line].x); gr_printf(sim_room_lines[line].x, y, buf); if (sim_room_lines[line].filename) { - SDL_strlcpy(buf, sim_room_lines[line].filename, sizeof(buf)); + SDL_strlcpy(buf, sim_room_lines[line].filename, SDL_arraysize(buf)); gr_force_fit_string(buf, 255, list_w2); gr_printf(list_x2, y, buf); } @@ -1705,7 +1705,7 @@ void campaign_room_commit() mission_campaign_savefile_delete(Campaign_file_names[Selected_campaign_index]); mission_campaign_load(Campaign_file_names[Selected_campaign_index]); - SDL_strlcpy(Player->current_campaign, Campaign.filename, sizeof(Player->current_campaign)); // track new campaign for player + SDL_strlcpy(Player->current_campaign, Campaign.filename, SDL_arraysize(Player->current_campaign)); // track new campaign for player } if (mission_campaign_next_mission()) { // is campaign and next mission valid? @@ -1831,7 +1831,7 @@ void campaign_room_init() Num_campaigns = 0; Get_file_list_filter = campaign_room_campaign_filter; - SDL_snprintf(wild_card, sizeof(wild_card), "*%s", FS_CAMPAIGN_FILE_EXT); + SDL_snprintf(wild_card, SDL_arraysize(wild_card), "*%s", FS_CAMPAIGN_FILE_EXT); Num_campaigns = cf_get_file_list(MAX_CAMPAIGNS, Campaign_file_names, CF_TYPE_MISSIONS, wild_card, CF_SORT_NAME); for (i=0; imask = mask; region->key = key; - SDL_strlcpy(region->text, text, sizeof(region->text)); + SDL_strlcpy(region->text, text, SDL_arraysize(region->text)); region->click_sound = click_sound; } @@ -433,7 +433,7 @@ void read_menu_tbl(const char* menu_name, char* bkg_filename, const int max_bkg_ return; } *p2 = 0; - SDL_strlcpy(regions[*num_regions].text, ++p1, sizeof(regions[0].text)); + SDL_strlcpy(regions[*num_regions].text, ++p1, SDL_arraysize(regions[0].text)); p2++; // get the tokens mask number diff --git a/src/menuui/techmenu.cpp b/src/menuui/techmenu.cpp index 89454d3..5658b7c 100644 --- a/src/menuui/techmenu.cpp +++ b/src/menuui/techmenu.cpp @@ -769,9 +769,9 @@ void tech_common_render() gr_set_color_fast(&Color_text_normal); } - SDL_strlcpy(buf, Current_list[z].name, sizeof(buf)); + SDL_strlcpy(buf, Current_list[z].name, SDL_arraysize(buf)); if (Lcl_gr) { - lcl_translate_ship_name(buf, sizeof(buf)); + lcl_translate_ship_name(buf, SDL_arraysize(buf)); } gr_force_fit_string(buf, 255, Tech_list_coords[gr_screen.res][SHIP_W_COORD]); @@ -1450,9 +1450,9 @@ int techroom_load_ani(anim **animpp, char *name) // hi-res support // (i dont think there are any hi-res anims for these tho) if (gr_screen.res == GR_1024) { - SDL_strlcat(anim_filename, name, sizeof(anim_filename)); + SDL_strlcat(anim_filename, name, SDL_arraysize(anim_filename)); } else { - SDL_strlcpy(anim_filename, name, sizeof(anim_filename)); + SDL_strlcpy(anim_filename, name, SDL_arraysize(anim_filename)); } while(1) { @@ -1520,8 +1520,8 @@ void techroom_intel_init() #else if (optional_string("$Terran Tech Description:")) { stuff_string(Intel_info[Intel_info_size].desc, F_MULTITEXT, NULL, TECH_INTEL_DESC_LEN); - SDL_strlcpy(Intel_info[Intel_info_size].name, "Terran", sizeof(Intel_info[0].name)); - SDL_strlcpy(Intel_info[Intel_info_size].anim_filename, Intel_anim_filenames[0], sizeof(Intel_info[0].anim_filename)); + SDL_strlcpy(Intel_info[Intel_info_size].name, "Terran", SDL_arraysize(Intel_info[0].name)); + SDL_strlcpy(Intel_info[Intel_info_size].anim_filename, Intel_anim_filenames[0], SDL_arraysize(Intel_info[0].anim_filename)); Intel_info[Intel_info_size].in_tech_db = 1; Intel_info_size++; @@ -1530,8 +1530,8 @@ void techroom_intel_init() if (optional_string("$Vasudan Tech Description:")) { stuff_string(Intel_info[Intel_info_size].desc, F_MULTITEXT, NULL, TECH_INTEL_DESC_LEN); - SDL_strlcpy(Intel_info[Intel_info_size].name, "Vasudan", sizeof(Intel_info[0].name)); - SDL_strlcpy(Intel_info[Intel_info_size].anim_filename, Intel_anim_filenames[1], sizeof(Intel_info[0].anim_filename)); + SDL_strlcpy(Intel_info[Intel_info_size].name, "Vasudan", SDL_arraysize(Intel_info[0].name)); + SDL_strlcpy(Intel_info[Intel_info_size].anim_filename, Intel_anim_filenames[1], SDL_arraysize(Intel_info[0].anim_filename)); Intel_info[Intel_info_size].in_tech_db = 1; Intel_info_size++; @@ -1540,8 +1540,8 @@ void techroom_intel_init() if (optional_string("$Shivan Tech Description:")) { stuff_string(Intel_info[Intel_info_size].desc, F_MULTITEXT, NULL, TECH_INTEL_DESC_LEN); - SDL_strlcpy(Intel_info[Intel_info_size].name, "Shivan", sizeof(Intel_info[0].name)); - SDL_strlcpy(Intel_info[Intel_info_size].anim_filename, Intel_anim_filenames[2], sizeof(Intel_info[0].anim_filename)); + SDL_strlcpy(Intel_info[Intel_info_size].name, "Shivan", SDL_arraysize(Intel_info[0].name)); + SDL_strlcpy(Intel_info[Intel_info_size].anim_filename, Intel_anim_filenames[2], SDL_arraysize(Intel_info[0].anim_filename)); // FIXME: shouldn't always be in the intel database but no choice at this point // there are only about 4 missions before they show up anyway so it may not be worth it Intel_info[Intel_info_size].in_tech_db = 1; diff --git a/src/menuui/trainingmenu.cpp b/src/menuui/trainingmenu.cpp index 1875d3e..032168a 100644 --- a/src/menuui/trainingmenu.cpp +++ b/src/menuui/trainingmenu.cpp @@ -148,8 +148,8 @@ void training_menu_init() snazzy_menu_init(); - read_menu_tbl(NOX("TRAINING MENU"), background_img_filename, sizeof(background_img_filename), - background_mask_filename, sizeof(background_mask_filename), region, &num_training); + read_menu_tbl(NOX("TRAINING MENU"), background_img_filename, SDL_arraysize(background_img_filename), + background_mask_filename, SDL_arraysize(background_mask_filename), region, &num_training); // load in the background bitmap (filenames are hard-coded temporarily) trainingMenuBitmap = bm_load(background_img_filename); diff --git a/src/mission/missionbriefcommon.cpp b/src/mission/missionbriefcommon.cpp index 39a989a..4ceb0ab 100644 --- a/src/mission/missionbriefcommon.cpp +++ b/src/mission/missionbriefcommon.cpp @@ -1358,14 +1358,14 @@ void brief_render_icon(int stage_num, int icon_num, float frametime, int selecte else { if (Lcl_gr) { char buf[128]; - SDL_strlcpy(buf, bi->label, sizeof(buf)); - lcl_translate_brief_icon_name(buf, sizeof(buf)); + SDL_strlcpy(buf, bi->label, SDL_arraysize(buf)); + lcl_translate_brief_icon_name(buf, SDL_arraysize(buf)); gr_get_string_size(&w, &h, buf); gr_printf(bc - fl2i(w/2.0f), by - h, buf); } else if(Lcl_pl) { char buf[128]; - SDL_strlcpy(buf, bi->label, sizeof(buf)); - lcl_translate_brief_icon_name_pl(buf, sizeof(buf)); + SDL_strlcpy(buf, bi->label, SDL_arraysize(buf)); + lcl_translate_brief_icon_name_pl(buf, SDL_arraysize(buf)); gr_get_string_size(&w, &h, buf); gr_printf(bc - fl2i(w/2.0f), by - h, buf); } else { @@ -1544,7 +1544,7 @@ void brief_blit_stage_num(int stage_num, int stage_max) #else gr_set_color_fast(&Color_text_heading); #endif - SDL_snprintf(buf, sizeof(buf), XSTR( "Stage %d of %d", 394), stage_num + 1, stage_max); + SDL_snprintf(buf, SDL_arraysize(buf), XSTR( "Stage %d of %d", 394), stage_num + 1, stage_max); if (Game_mode & GM_MULTIPLAYER) { gr_printf(Brief_stage_text_coords_multi[gr_screen.res][0], Brief_stage_text_coords_multi[gr_screen.res][1], buf); } else { @@ -2160,12 +2160,12 @@ void brief_set_new_stage(vector *pos, matrix *orient, int time, int stage_num) if (not_objv) { if(Briefing->stages[stage_num].new_text == NULL){ - SDL_strlcpy(msg, "", sizeof(msg)); + SDL_strlcpy(msg, "", SDL_arraysize(msg)); } else { - SDL_strlcpy(msg, Briefing->stages[stage_num].new_text, sizeof(msg)); + SDL_strlcpy(msg, Briefing->stages[stage_num].new_text, SDL_arraysize(msg)); } } else { - SDL_strlcpy(msg, XSTR( "Please review your objectives for this mission.", 395), sizeof(msg)); + SDL_strlcpy(msg, XSTR( "Please review your objectives for this mission.", 395), SDL_arraysize(msg)); } if (gr_screen.res == GR_640) { diff --git a/src/mission/missioncampaign.cpp b/src/mission/missioncampaign.cpp index a92de10..e314bc1 100644 --- a/src/mission/missioncampaign.cpp +++ b/src/mission/missioncampaign.cpp @@ -282,9 +282,9 @@ int mission_campaign_get_info(const char *filename, char *name, int *type, int * // open localization lcl_ext_open(); - SDL_strlcpy(fname, filename, sizeof(fname)); + SDL_strlcpy(fname, filename, SDL_arraysize(fname)); if ((strlen(fname) < 4) || SDL_strcasecmp(fname + strlen(fname) - 4, FS_CAMPAIGN_FILE_EXT)){ - SDL_strlcat(fname, FS_CAMPAIGN_FILE_EXT, sizeof(fname)); + SDL_strlcat(fname, FS_CAMPAIGN_FILE_EXT, SDL_arraysize(fname)); } SDL_assert(strlen(fname) < MAX_FILENAME_LEN); @@ -449,7 +449,7 @@ int mission_campaign_load( const char *filename, int load_savefile ) // nodes previously used by another campaign. mission_campaign_close(); - SDL_strlcpy( Campaign.filename, filename, sizeof(Campaign.filename) ); + SDL_strlcpy( Campaign.filename, filename, SDL_arraysize(Campaign.filename) ); // only initialize the sexpression stuff when Fred isn't running. It'll screw things up major // if it does @@ -462,14 +462,14 @@ int mission_campaign_load( const char *filename, int load_savefile ) memset( &Campaign, 0, sizeof(Campaign) ); // copy filename to campaign structure minus the extension - len = min(strlen(filename) - 4 + 1, sizeof(Campaign.filename)); + len = min(strlen(filename) - 4 + 1, SDL_arraysize(Campaign.filename)); SDL_strlcpy(Campaign.filename, filename, len); required_string("$Name:"); stuff_string( name, F_NAME, NULL ); //Store campaign name in the global struct - SDL_strlcpy( Campaign.name, name, sizeof(Campaign.name) ); + SDL_strlcpy( Campaign.name, name, SDL_arraysize(Campaign.name) ); required_string( "$Type:" ); stuff_string( type, F_NAME, NULL ); @@ -647,12 +647,12 @@ int mission_campaign_load_by_name( const char *filename ) SDL_strlcpy(real_filename, filename, MAX_FILENAME_LEN); if(strlen(real_filename) > 4){ - SDL_strlcpy(test, real_filename+(strlen(real_filename)-4), sizeof(test)); + SDL_strlcpy(test, real_filename+(strlen(real_filename)-4), SDL_arraysize(test)); if(strcmp(test, FS_CAMPAIGN_FILE_EXT)!=0){ - SDL_strlcat(real_filename, FS_CAMPAIGN_FILE_EXT, sizeof(real_filename)); + SDL_strlcat(real_filename, FS_CAMPAIGN_FILE_EXT, SDL_arraysize(real_filename)); } } else { - SDL_strlcat(real_filename, FS_CAMPAIGN_FILE_EXT, sizeof(real_filename)); + SDL_strlcat(real_filename, FS_CAMPAIGN_FILE_EXT, SDL_arraysize(real_filename)); } } else { Error(LOCATION,"Tried to load campaign file with illegal length/extension!"); @@ -673,7 +673,7 @@ int mission_campaign_load_by_name( const char *filename ) int mission_campaign_load_by_name_csfe( const char *filename, const char *callsign ) { Game_mode |= GM_NORMAL; - SDL_strlcpy(Player->callsign, callsign, sizeof(Player->callsign)); + SDL_strlcpy(Player->callsign, callsign, SDL_arraysize(Player->callsign)); return mission_campaign_load_by_name( filename); } @@ -693,7 +693,7 @@ void mission_campaign_savefile_generate_root(char *filename, const int max_len) // build up the filename for the save file. There could be a problem with filename length, // but this problem can get fixed in several ways -- ignore the problem for now though. - base_filename(Campaign.filename, base, sizeof(base)); + base_filename(Campaign.filename, base, SDL_arraysize(base)); SDL_assert ( (int)(strlen(base) + strlen(Player->callsign)) < max_len ); SDL_snprintf( filename, max_len, NOX("%s.%s."), Player->callsign, base ); @@ -710,11 +710,11 @@ int mission_campaign_savefile_save() int i,j, mission_count; memset(filename, 0, sizeof(filename)); - mission_campaign_savefile_generate_root(filename, sizeof(filename)); + mission_campaign_savefile_generate_root(filename, SDL_arraysize(filename)); // name the file differently depending on whether we're in single player or multiplayer mode // single player : *.csg - SDL_strlcat( filename, NOX("csg"), sizeof(filename) ); + SDL_strlcat( filename, NOX("csg"), SDL_arraysize(filename) ); fp = cfopen(filename,"wb", CFILE_NORMAL, CF_TYPE_SINGLE_PLAYERS); @@ -776,11 +776,11 @@ int mission_campaign_savefile_save() // out to disk. Write out a seperate file to do this. We will only read it in if we actually // find the file. memset(filename, 0, sizeof(filename)); - mission_campaign_savefile_generate_root(filename, sizeof(filename)); + mission_campaign_savefile_generate_root(filename, SDL_arraysize(filename)); // name the file differently depending on whether we're in single player or multiplayer mode // single player : *.csg - SDL_strlcat( filename, NOX("css"), sizeof(filename) ); + SDL_strlcat( filename, NOX("css"), SDL_arraysize(filename) ); fp = cfopen(filename,"wb", CFILE_NORMAL, CF_TYPE_SINGLE_PLAYERS); @@ -822,7 +822,7 @@ int campaign_savefile_save(const char *pname) else Game_mode |= GM_MULTIPLAYER; - SDL_strlcpy(Player->callsign, pname, sizeof(Player->callsign)); + SDL_strlcpy(Player->callsign, pname, SDL_arraysize(Player->callsign)); //memcpy(&Campaign, camp, sizeof(campaign)); return mission_campaign_savefile_save(); } @@ -838,20 +838,20 @@ void mission_campaign_savefile_delete( const char *cfilename, int is_multi ) { char filename[MAX_PATH_LEN], base[MAX_FILENAME_LEN]; - base_filename(cfilename, base, sizeof(base)); + base_filename(cfilename, base, SDL_arraysize(base)); if ( Player->flags & PLAYER_FLAGS_IS_MULTI ) { return; // no such thing as a multiplayer campaign savefile } - SDL_snprintf( filename, sizeof(filename), NOX("%s.%s.csg"), Player->callsign, base ); + SDL_snprintf( filename, SDL_arraysize(filename), NOX("%s.%s.csg"), Player->callsign, base ); cf_delete( filename, CF_TYPE_SINGLE_PLAYERS ); } void campaign_delete_save( const char *cfn, const char *pname) { - SDL_strlcpy(Player->callsign, pname, sizeof(Player->callsign)); + SDL_strlcpy(Player->callsign, pname, SDL_arraysize(Player->callsign)); mission_campaign_savefile_delete(cfn); } @@ -873,7 +873,7 @@ void mission_campaign_delete_all_savefiles( const char *pilot_name, int is_multi ext = NOX(".csg"); dir_type = CF_TYPE_SINGLE_PLAYERS; - SDL_snprintf(spec, sizeof(spec), NOX("%s.*%s"), pilot_name, ext); + SDL_snprintf(spec, SDL_arraysize(spec), NOX("%s.*%s"), pilot_name, ext); // HACK HACK HACK HACK!!!! cf_get_file_list is not reentrant. Pretty dumb because it should // be. I have to save any file filters @@ -883,8 +883,8 @@ void mission_campaign_delete_all_savefiles( const char *pilot_name, int is_multi Get_file_list_filter = filter_save; for (i=0; icallsign)) < sizeof(filename) ); + base_filename(cfilename, base, SDL_arraysize(base)); + SDL_assert ( (strlen(base) + strlen(Player->callsign)) < SDL_arraysize(filename) ); if(Game_mode & GM_MULTIPLAYER) - SDL_snprintf( filename, sizeof(filename), NOX("%s.%s.msg"), Player->callsign, base ); + SDL_snprintf( filename, SDL_arraysize(filename), NOX("%s.%s.msg"), Player->callsign, base ); else - SDL_snprintf( filename, sizeof(filename), NOX("%s.%s.csg"), Player->callsign, base ); + SDL_snprintf( filename, SDL_arraysize(filename), NOX("%s.%s.csg"), Player->callsign, base ); fp = cfopen(filename, "rb", CFILE_NORMAL, CF_TYPE_SINGLE_PLAYERS ); if ( !fp ) @@ -946,7 +946,7 @@ void mission_campaign_savefile_load( const char *cfilename ) // read in the filename of the campaign and compare the filenames to be sure that // we are reading data that really belongs to this campaign. I think that this check // is redundant. - cfread_string_len( filename, sizeof(filename), fp ); + cfread_string_len( filename, SDL_arraysize(filename), fp ); /*if ( SDL_strcasecmp( filename, cfilename) ) { // Used to be !SDL_strcasecmp. How did this ever work? --MK, 11/9/97 Warning(LOCATION, "Campaign save file appears corrupt because of mismatching filenames."); cfclose(fp); @@ -1030,7 +1030,7 @@ void mission_campaign_savefile_load( const char *cfilename ) // now, try and read in the campaign stats saved information. This code was added for the 1.03 patch // since the stats data was never written out to disk. We try and open the file, and if we cannot find // it, then simply return - SDL_snprintf( filename, sizeof(filename), NOX("%s.%s.css"), Player->callsign, base ); + SDL_snprintf( filename, SDL_arraysize(filename), NOX("%s.%s.css"), Player->callsign, base ); fp = cfopen(filename, "rb", CFILE_NORMAL, CF_TYPE_SINGLE_PLAYERS ); if ( !fp ) @@ -1069,7 +1069,7 @@ void campaign_savefile_load(const char *fname, const char *pname) } else Game_mode |= GM_MULTIPLAYER; - SDL_strlcpy(Player->callsign, pname, sizeof(Player->callsign)); + SDL_strlcpy(Player->callsign, pname, SDL_arraysize(Player->callsign)); mission_campaign_savefile_load(fname); } @@ -1313,11 +1313,11 @@ void mission_campaign_store_goals_and_events() if ( strlen(Mission_goals[i].name) == 0 ) { char name[NAME_LENGTH]; - SDL_snprintf(name, sizeof(name), NOX("Goal #%d"), i); + SDL_snprintf(name, SDL_arraysize(name), NOX("Goal #%d"), i); //Warning(LOCATION, "Mission goal in mission %s must have a +Name field! using %s for campaign save file\n", mission->name, name); - SDL_strlcpy( mission->goals[i].name, name, sizeof(mission->goals[0].name)); + SDL_strlcpy( mission->goals[i].name, name, SDL_arraysize(mission->goals[0].name)); } else - SDL_strlcpy( mission->goals[i].name, Mission_goals[i].name, sizeof(mission->goals[0].name) ); + SDL_strlcpy( mission->goals[i].name, Mission_goals[i].name, SDL_arraysize(mission->goals[0].name) ); SDL_assert ( Mission_goals[i].satisfied != GOAL_INCOMPLETE ); // should be true or false at this point!!! mission->goals[i].status = (char)Mission_goals[i].satisfied; } @@ -1339,11 +1339,11 @@ void mission_campaign_store_goals_and_events() if ( strlen(Mission_events[i].name) == 0 ) { char name[NAME_LENGTH]; - SDL_snprintf(name, sizeof(name), NOX("Event #%d"), i); + SDL_snprintf(name, SDL_arraysize(name), NOX("Event #%d"), i); nprintf(("Warning", "Mission goal in mission %s must have a +Name field! using %s for campaign save file\n", mission->name, name)); - SDL_strlcpy( mission->events[i].name, name, sizeof(mission->events[0].name)); + SDL_strlcpy( mission->events[i].name, name, SDL_arraysize(mission->events[0].name)); } else - SDL_strlcpy( mission->events[i].name, Mission_events[i].name, sizeof(mission->events[0].name) ); + SDL_strlcpy( mission->events[i].name, Mission_events[i].name, SDL_arraysize(mission->events[0].name) ); // getting status for the events is a little different. If the formula value for the event entry // is -1, then we know the value of the result field will never change. If the formula is @@ -1623,7 +1623,7 @@ void read_mission_goal_list(int num) memset(Campaign.missions[num].goals, 0, count * sizeof(mgoal)); for (i=0; isetnum = i; - SDL_strlcpy( hkp->name, Ships[hitem->objp->instance].ship_name, sizeof(hkp->name) ); + SDL_strlcpy( hkp->name, Ships[hitem->objp->instance].ship_name, SDL_arraysize(hkp->name) ); hkp++; Num_hotkeys_saved++; } @@ -1366,7 +1366,7 @@ void mission_hotkey_do_frame(float frametime) // draw the big "F10" in the little box gr_set_font(FONT2); gr_set_color_fast(&Color_text_normal); - SDL_strlcpy(buf, Scan_code_text[Key_sets[Cur_hotkey]], sizeof(buf)); + SDL_strlcpy(buf, Scan_code_text[Key_sets[Cur_hotkey]], SDL_arraysize(buf)); gr_get_string_size(&w, &h, buf); gr_printf(Hotkey_function_name_coords[gr_screen.res][0] + (Hotkey_function_name_coords[gr_screen.res][2] - w) / 2, Hotkey_function_name_coords[gr_screen.res][1], buf); @@ -1460,7 +1460,7 @@ void mission_hotkey_do_frame(float frametime) } // draw ship/wing name - SDL_strlcpy(buf, Hotkey_lines[line].label, sizeof(buf)); + SDL_strlcpy(buf, Hotkey_lines[line].label, SDL_arraysize(buf)); if (Hotkey_lines[line].type == HOTKEY_LINE_SUBSHIP) { // indent gr_force_fit_string(buf, 255, Hotkey_list_coords[gr_screen.res][0] + Hotkey_list_coords[gr_screen.res][2] - (Hotkey_ship_x[gr_screen.res]+20)); diff --git a/src/mission/missionload.cpp b/src/mission/missionload.cpp index 69fccde..d2ec639 100644 --- a/src/mission/missionload.cpp +++ b/src/mission/missionload.cpp @@ -234,7 +234,7 @@ void ml_update_recent_missions(char *filename) for ( i = 0; i < Num_recent_missions; i++ ) { - SDL_strlcpy( tmp[i], Recent_missions[i], sizeof(tmp[0]) ); + SDL_strlcpy( tmp[i], Recent_missions[i], SDL_arraysize(tmp[0]) ); } // get a pointer to just the basename of the filename (including extension) @@ -246,12 +246,12 @@ void ml_update_recent_missions(char *filename) } SDL_assert(strlen(p) < MAX_FILENAME_LEN); - SDL_strlcpy( Recent_missions[0], p, sizeof(Recent_missions[0]) ); + SDL_strlcpy( Recent_missions[0], p, SDL_arraysize(Recent_missions[0]) ); j = 1; for ( i = 0; i < Num_recent_missions; i++ ) { if ( SDL_strcasecmp(Recent_missions[0], tmp[i]) ) { - SDL_strlcpy(Recent_missions[j++], tmp[i], sizeof(Recent_missions[0])); + SDL_strlcpy(Recent_missions[j++], tmp[i], SDL_arraysize(Recent_missions[0])); if ( j >= MAX_RECENT_MISSIONS ) { break; } @@ -273,14 +273,14 @@ int mission_load() mprintf(("MISSION LOAD: '%s'\n", Game_current_mission_filename)); - SDL_strlcpy(filename, Game_current_mission_filename, sizeof(filename)); + SDL_strlcpy(filename, Game_current_mission_filename, SDL_arraysize(filename)); ext = SDL_strchr(filename, '.'); if (ext) { mprintf(( "Hmmm... Extension passed to mission_load...\n" )); *ext = 0; // remove any extension! } - SDL_strlcat(filename, FS_MISSION_FILE_EXT, sizeof(filename)); + SDL_strlcat(filename, FS_MISSION_FILE_EXT, SDL_arraysize(filename)); // does the magical mission parsing // creates all objects, except for the player object diff --git a/src/mission/missionlog.cpp b/src/mission/missionlog.cpp index 016957a..9d501af 100644 --- a/src/mission/missionlog.cpp +++ b/src/mission/missionlog.cpp @@ -409,15 +409,15 @@ void mission_log_add_entry(int type, const char *pname, const char *sname, int i entry->type = type; if ( pname ) { SDL_assert (strlen(pname) < NAME_LENGTH); - SDL_strlcpy(entry->pname, pname, sizeof(entry->pname)); + SDL_strlcpy(entry->pname, pname, SDL_arraysize(entry->pname)); } else - SDL_strlcpy( entry->pname, EMPTY_LOG_NAME, sizeof(entry->pname) ); + SDL_strlcpy( entry->pname, EMPTY_LOG_NAME, SDL_arraysize(entry->pname) ); if ( sname ) { SDL_assert (strlen(sname) < NAME_LENGTH); - SDL_strlcpy(entry->sname, sname, sizeof(entry->sname)); + SDL_strlcpy(entry->sname, sname, SDL_arraysize(entry->sname)); } else - SDL_strlcpy( entry->sname, EMPTY_LOG_NAME, sizeof(entry->sname) ); + SDL_strlcpy( entry->sname, EMPTY_LOG_NAME, SDL_arraysize(entry->sname) ); entry->index = info_index; entry->flags = 0; @@ -603,11 +603,11 @@ void mission_log_add_entry_multi( int type, const char *pname, const char *sname entry->type = type; if ( pname ) { SDL_assert (strlen(pname) < NAME_LENGTH); - SDL_strlcpy(entry->pname, pname, sizeof(entry->pname)); + SDL_strlcpy(entry->pname, pname, SDL_arraysize(entry->pname)); } if ( sname ) { SDL_assert (strlen(sname) < NAME_LENGTH); - SDL_strlcpy(entry->sname, sname, sizeof(entry->sname)); + SDL_strlcpy(entry->sname, sname, SDL_arraysize(entry->sname)); } entry->index = index; @@ -818,7 +818,7 @@ void message_log_init_scrollback(int pw) message_log_add_segs(XSTR( " Kill: ", 405), LOG_COLOR_NORMAL); message_log_add_segs(entry->sname, c); if (entry->index >= 0) { - SDL_snprintf(text, sizeof(text), NOX(" (%d%%)"), entry->index); + SDL_snprintf(text, SDL_arraysize(text), NOX(" (%d%%)"), entry->index); message_log_add_segs(text, LOG_COLOR_BRIGHT); } } @@ -838,9 +838,9 @@ void message_log_init_scrollback(int pw) case LOG_WING_ARRIVE: if (entry->index > 1){ - SDL_snprintf(text, sizeof(text), XSTR( "Arrived (wave %d)", 407), entry->index); + SDL_snprintf(text, SDL_arraysize(text), XSTR( "Arrived (wave %d)", 407), entry->index); } else { - SDL_strlcpy(text, XSTR( "Arrived", 406), sizeof(text)); + SDL_strlcpy(text, XSTR( "Arrived", 406), SDL_arraysize(text)); } message_log_add_segs(text, LOG_COLOR_NORMAL); break; @@ -924,11 +924,11 @@ void message_log_init_scrollback(int pw) break; // don't display this line } - SDL_snprintf( text, sizeof(text), XSTR( "%s objective ", 419), Goal_type_text(type) ); + SDL_snprintf( text, SDL_arraysize(text), XSTR( "%s objective ", 419), Goal_type_text(type) ); if ( entry->type == LOG_GOAL_SATISFIED ) - SDL_strlcat(text, XSTR( "satisfied.", 420), sizeof(text)); + SDL_strlcat(text, XSTR( "satisfied.", 420), SDL_arraysize(text)); else - SDL_strlcat(text, XSTR( "failed.", 421), sizeof(text)); + SDL_strlcat(text, XSTR( "failed.", 421), SDL_arraysize(text)); message_log_add_segs(text, LOG_COLOR_BRIGHT, (entry->type == LOG_GOAL_SATISFIED?LOG_FLAG_GOAL_TRUE:LOG_FLAG_GOAL_FAILED) ); break; @@ -998,7 +998,7 @@ void mission_log_scrollback(int line, int list_x, int list_y, int list_w, int li break; } - SDL_strlcpy(buf, seg->text, sizeof(buf)); + SDL_strlcpy(buf, seg->text, SDL_arraysize(buf)); if (seg->x < ACTION_X) gr_force_fit_string(buf, 256, ACTION_X - OBJECT_X - 8); else diff --git a/src/mission/missionmessage.cpp b/src/mission/missionmessage.cpp index c22f836..f64c69f 100644 --- a/src/mission/missionmessage.cpp +++ b/src/mission/missionmessage.cpp @@ -1077,7 +1077,7 @@ void message_load_wave(int index, const char *filename) game_snd tmp_gs; memset(&tmp_gs, 0, sizeof(game_snd)); - SDL_strlcpy( tmp_gs.filename, filename, sizeof(tmp_gs.filename) ); + SDL_strlcpy( tmp_gs.filename, filename, SDL_arraysize(tmp_gs.filename) ); Message_waves[index].num = snd_load( &tmp_gs ); if ( Message_waves[index].num == -1 ) { nprintf (("messaging", "Cannot load message wave: %s. Will not play\n", Message_waves[index].name )); @@ -1114,7 +1114,7 @@ void message_play_wave( message_q *q ) } // if we need to bash the wave name because of "conversion" to terran command, do it here - SDL_strlcpy( filename, Message_waves[index].name, sizeof(filename) ); + SDL_strlcpy( filename, Message_waves[index].name, SDL_arraysize(filename) ); if ( q->flags & MQF_CONVERT_TO_COMMAND ) { char *p, new_filename[MAX_FILENAME_LEN]; @@ -1130,9 +1130,9 @@ void message_play_wave( message_q *q ) // prepend the command name, and then the rest of the filename. p++; - SDL_strlcpy( new_filename, COMMAND_WAVE_PREFIX, sizeof(new_filename) ); - SDL_strlcat( new_filename, p, sizeof(new_filename) ); - SDL_strlcpy( filename, new_filename, sizeof(filename) ); + SDL_strlcpy( new_filename, COMMAND_WAVE_PREFIX, SDL_arraysize(new_filename) ); + SDL_strlcat( new_filename, p, SDL_arraysize(new_filename) ); + SDL_strlcpy( filename, new_filename, SDL_arraysize(filename) ); } // load the sound file into memory @@ -1219,7 +1219,7 @@ void message_play_anim( message_q *q ) anim_info = &Message_avis[m->avi_info.index]; // get the filename. Strip off the extension since we won't need it anyway - SDL_strlcpy(ani_name, anim_info->name, sizeof(ani_name)); + SDL_strlcpy(ani_name, anim_info->name, SDL_arraysize(ani_name)); p = SDL_strchr(ani_name, '.'); // gets us to the extension if ( p ) { *p = '\0'; @@ -1239,7 +1239,7 @@ void message_play_anim( message_q *q ) // so the correct head plays. if ( q->flags & MQF_CONVERT_TO_COMMAND ) { persona_index = Command_persona; - SDL_strlcpy( ani_name, COMMAND_HEAD_PREFIX, sizeof(ani_name) ); + SDL_strlcpy( ani_name, COMMAND_HEAD_PREFIX, SDL_arraysize(ani_name) ); } if ( Personas[persona_index].flags & (PERSONA_FLAG_WINGMAN | PERSONA_FLAG_SUPPORT) ) { @@ -1250,18 +1250,18 @@ void message_play_anim( message_q *q ) } else { rand_index = (Missiontime % MAX_WINGMAN_HEADS); } - SDL_snprintf(ani_name, sizeof(ani_name), "%s%c", ani_name, 'a'+rand_index); + SDL_snprintf(ani_name, SDL_arraysize(ani_name), "%s%c", ani_name, 'a'+rand_index); subhead_selected = TRUE; } else if ( Personas[persona_index].flags & (PERSONA_FLAG_COMMAND | PERSONA_FLAG_LARGE) ) { // get a random head -- it's one of two. rand_index = (Missiontime % MAX_COMMAND_HEADS); - SDL_snprintf(ani_name, sizeof(ani_name), "%s%c", ani_name, 'a'+rand_index); + SDL_snprintf(ani_name, SDL_arraysize(ani_name), "%s%c", ani_name, 'a'+rand_index); subhead_selected = TRUE; } if (!subhead_selected) { // choose between a and b rand_index = (Missiontime % MAX_WINGMAN_HEADS); - SDL_snprintf(ani_name, sizeof(ani_name), "%s%c", ani_name, 'a'+rand_index); + SDL_snprintf(ani_name, SDL_arraysize(ani_name), "%s%c", ani_name, 'a'+rand_index); mprintf(("message '%s' with invalid head. Fix by assigning persona to the message.\n", m->name)); } nprintf(("Messaging", "playing head %s for %s\n", ani_name, q->who_from)); @@ -1570,7 +1570,7 @@ void message_queue_process() #ifndef NDEBUG // debug only -- if the message is a builtin message, put in parens whether or not the voice played if ( Playing_messages[Num_messages_playing].wave == -1 ) { - SDL_strlcat( buf, NOX("..(no wavefile for voice)"), sizeof(buf)); + SDL_strlcat( buf, NOX("..(no wavefile for voice)"), SDL_arraysize(buf)); snd_play(&Snds[SND_CUE_VOICE]); } #endif diff --git a/src/mission/missionparse.cpp b/src/mission/missionparse.cpp index 6afdf5e..e05cb7b 100644 --- a/src/mission/missionparse.cpp +++ b/src/mission/missionparse.cpp @@ -694,7 +694,7 @@ void parse_mission_info(mission *pm) if (optional_string("$Mission Desc:")) stuff_string(pm->mission_desc, F_MULTITEXT, NULL, MISSION_DESC_LENGTH); else - SDL_strlcpy(pm->mission_desc, NOX("No description\n"), sizeof(pm->mission_desc)); + SDL_strlcpy(pm->mission_desc, NOX("No description\n"), SDL_arraysize(pm->mission_desc)); pm->game_type = MISSION_TYPE_SINGLE; // default to single player only if ( optional_string("+Game Type:")) { @@ -806,8 +806,8 @@ void parse_mission_info(mission *pm) } // possible squadron reassignment - SDL_strlcpy(The_mission.squad_name, "", sizeof(The_mission.squad_name)); - SDL_strlcpy(The_mission.squad_filename, "", sizeof(The_mission.squad_filename)); + SDL_strlcpy(The_mission.squad_name, "", SDL_arraysize(The_mission.squad_name)); + SDL_strlcpy(The_mission.squad_filename, "", SDL_arraysize(The_mission.squad_filename)); if(optional_string("+SquadReassignName:")){ stuff_string(The_mission.squad_name, F_NAME, NULL); if(optional_string("+SquadReassignLogo:")){ @@ -816,8 +816,8 @@ void parse_mission_info(mission *pm) } // always clear out squad reassignments if not single player if(Game_mode & GM_MULTIPLAYER){ - SDL_strlcpy(The_mission.squad_name, "", sizeof(The_mission.squad_name)); - SDL_strlcpy(The_mission.squad_filename, "", sizeof(The_mission.squad_filename)); + SDL_strlcpy(The_mission.squad_name, "", SDL_arraysize(The_mission.squad_name)); + SDL_strlcpy(The_mission.squad_filename, "", SDL_arraysize(The_mission.squad_filename)); mprintf(("Ignoring squadron reassignment")); } // reassign the player @@ -1414,7 +1414,7 @@ int parse_create_object(p_object *objp) Ships[shipnum].group = objp->group; Ships[shipnum].team = objp->team; - SDL_strlcpy(Ships[shipnum].ship_name, objp->name, sizeof(Ships[0].ship_name)); + SDL_strlcpy(Ships[shipnum].ship_name, objp->name, SDL_arraysize(Ships[0].ship_name)); Ships[shipnum].escort_priority = objp->escort_priority; Ships[shipnum].special_exp_index = objp->special_exp_index; Ships[shipnum].respawn_priority = objp->respawn_priority; @@ -2462,7 +2462,7 @@ int parse_wing_create_ships( wing *wingp, int num_to_create, int force, int spec wingp->total_arrived_count++; if ( wingp->num_waves > 1 ){ - SDL_snprintf(objp->name, sizeof(objp->name), NOX("%s %d"), wingp->name, wingp->total_arrived_count); + SDL_snprintf(objp->name, SDL_arraysize(objp->name), NOX("%s %d"), wingp->name, wingp->total_arrived_count); } objnum = parse_create_object(objp); @@ -3161,7 +3161,7 @@ void parse_bitmap(mission *pm) if(Num_suns < MAX_STARFIELD_BITMAPS){ Suns[Num_suns] = b; - SDL_strlcpy(Suns[Num_suns].filename, b.filename, sizeof(b.filename)); + SDL_strlcpy(Suns[Num_suns].filename, b.filename, SDL_arraysize(b.filename)); Num_suns++; } } @@ -3236,7 +3236,7 @@ void parse_bitmaps(mission *pm) nebula_close(); // neb2 info - SDL_strlcpy(Neb2_texture_name, "Eraseme3", sizeof(Neb2_texture_name)); + SDL_strlcpy(Neb2_texture_name, "Eraseme3", SDL_arraysize(Neb2_texture_name)); Neb2_poof_flags = ((1<<0) | (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5)); if(optional_string("+Neb2:")){ stuff_string(Neb2_texture_name, F_NAME, NULL); @@ -3326,7 +3326,7 @@ void parse_bitmaps(mission *pm) // if we have room, store it if(Num_suns < MAX_STARFIELD_BITMAPS){ Suns[Num_suns] = b; - SDL_strlcpy(Suns[Num_suns].filename, b.filename, sizeof(b.filename)); + SDL_strlcpy(Suns[Num_suns].filename, b.filename, SDL_arraysize(b.filename)); Num_suns++; } } @@ -3367,7 +3367,7 @@ void parse_bitmaps(mission *pm) // if we have room, store it if(Num_starfield_bitmaps < MAX_STARFIELD_BITMAPS){ Starfield_bitmap_instance[Num_starfield_bitmaps] = b; - SDL_strlcpy(Starfield_bitmap_instance[Num_starfield_bitmaps].filename, b.filename, sizeof(b.filename)); + SDL_strlcpy(Starfield_bitmap_instance[Num_starfield_bitmaps].filename, b.filename, SDL_arraysize(b.filename)); Num_starfield_bitmaps++; } } @@ -3636,8 +3636,8 @@ void post_process_mission() if ( result ) { char sexp_str[8192], text[8192]; - convert_sexp_to_string( i, sexp_str, sizeof(sexp_str), SEXP_ERROR_CHECK_MODE); - SDL_snprintf(text, sizeof(text), "%s.\n\nIn sexpression: %s\n(Error appears to be: %s)", + convert_sexp_to_string( i, sexp_str, SDL_arraysize(sexp_str), SEXP_ERROR_CHECK_MODE); + SDL_snprintf(text, SDL_arraysize(text), "%s.\n\nIn sexpression: %s\n(Error appears to be: %s)", sexp_error_message(result), sexp_str, Sexp_nodes[bindex].text); if (!Fred_running) @@ -3871,7 +3871,7 @@ int parse_main(const char *mission_name, int flags) lcl_ext_close(); if (!Fred_running) - SDL_strlcpy(Mission_filename, mission_name, sizeof(Mission_filename)); + SDL_strlcpy(Mission_filename, mission_name, SDL_arraysize(Mission_filename)); return 0; } @@ -4980,7 +4980,7 @@ void mission_warp_in_support_ship( object *requester_objp ) // create a name for the ship. use "Support #". look for collisions until one isn't found anymore i = 1; do { - SDL_snprintf(pobj->name, sizeof(pobj->name), NOX("Support %d"), i); + SDL_snprintf(pobj->name, SDL_arraysize(pobj->name), NOX("Support %d"), i); if ( (ship_name_lookup(pobj->name) == -1) && (ship_find_exited_ship_by_name(pobj->name) == -1) ) break; i++; diff --git a/src/mission/missiontraining.cpp b/src/mission/missiontraining.cpp index dd6ded0..5d797ac 100644 --- a/src/mission/missiontraining.cpp +++ b/src/mission/missiontraining.cpp @@ -445,14 +445,14 @@ void training_obj_display() c = &Color_normal; if (Training_obj_lines[i + offset] & TRAINING_OBJ_LINES_KEY) { - message_translate_tokens(buf, sizeof(buf), Mission_events[z].objective_key_text); // remap keys + message_translate_tokens(buf, SDL_arraysize(buf), Mission_events[z].objective_key_text); // remap keys // gr_set_color_fast(&Color_normal); c = &Color_bright_green; } else { - SDL_strlcpy(buf, Mission_events[z].objective_text, sizeof(buf)); + SDL_strlcpy(buf, Mission_events[z].objective_text, SDL_arraysize(buf)); if (Mission_events[z].count){ int len = strlen(buf); - SDL_snprintf(buf + len, sizeof(buf) - len, NOX(" [%d]"), Mission_events[z].count); + SDL_snprintf(buf + len, SDL_arraysize(buf) - len, NOX(" [%d]"), Mission_events[z].count); } // if this is a multiplayer tvt game, and this is event is not for my team, don't display it @@ -856,7 +856,7 @@ void message_translate_tokens(char *buf, const int max_buflen, char *text) len = min(toke1 - text + 1, max_buflen); SDL_strlcpy(temp, text, len); // isolate token into seperate buffer - ptr = translate_msg_token(temp, sizeof(temp)); // try and translate key + ptr = translate_msg_token(temp, SDL_arraysize(temp)); // try and translate key if (ptr) { // was key translated properly? buf--; // erase the # SDL_strlcpy(buf, ptr, max_buflen); // put translated key in place of token @@ -935,7 +935,7 @@ int message_play_training_voice(int index) } else { game_snd tmp_gs; memset(&tmp_gs, 0, sizeof(game_snd)); - SDL_strlcpy(tmp_gs.filename, Message_waves[index].name, sizeof(tmp_gs.filename)); + SDL_strlcpy(tmp_gs.filename, Message_waves[index].name, SDL_arraysize(tmp_gs.filename)); Message_waves[index].num = snd_load(&tmp_gs); if (Message_waves[index].num < 0) { nprintf(("Warning", "Cannot load message wave: %s. Will not play\n", Message_waves[index].name)); @@ -973,9 +973,9 @@ void message_training_setup(int m, int length) return; } - message_translate_tokens(Training_buf, sizeof(Training_buf), Messages[m].message); + message_translate_tokens(Training_buf, SDL_arraysize(Training_buf), Messages[m].message); HUD_add_to_scrollback(Training_buf, HUD_SOURCE_TRAINING); - SDL_strlcpy(Training_text, Messages[m].message, sizeof(Training_text)); + SDL_strlcpy(Training_text, Messages[m].message, SDL_arraysize(Training_text)); if (message_play_training_voice(Messages[m].wave_info.index) < 0) { if (length > 0) @@ -1077,7 +1077,7 @@ void message_training_display() return; } - message_translate_tokens(Training_buf, sizeof(Training_buf), Training_text); + message_translate_tokens(Training_buf, SDL_arraysize(Training_buf), Training_text); training_process_msg(Training_text); Training_num_lines = split_str(Training_buf, TRAINING_LINE_WIDTH, Training_line_sizes, Training_lines, MAX_TRAINING_MSG_LINES); SDL_assert(Training_num_lines > 0); @@ -1157,7 +1157,7 @@ void training_process_msg(char *msg) int count; char *src, *dest, buf[8192]; - message_translate_tokens(buf, sizeof(buf), msg); + message_translate_tokens(buf, SDL_arraysize(buf), msg); count = 0; src = buf; dest = Training_buf; diff --git a/src/missionui/chatbox.cpp b/src/missionui/chatbox.cpp index 4c91c01..eda9473 100644 --- a/src/missionui/chatbox.cpp +++ b/src/missionui/chatbox.cpp @@ -645,7 +645,7 @@ void chatbox_set_mode(int mode_flags) // set up the display/init variables based upon what mode we chode switch(size){ case 0: - SDL_strlcpy(Chatbox_mask, Chatbox_small_bitmap_mask_fname[gr_screen.res], sizeof(Chatbox_mask)); + SDL_strlcpy(Chatbox_mask, Chatbox_small_bitmap_mask_fname[gr_screen.res], SDL_arraysize(Chatbox_mask)); Chatbox_x1 = Chatbox_small_coords[gr_screen.res][CHATBOX_X_COORD]; Chatbox_y1 = Chatbox_small_coords[gr_screen.res][CHATBOX_Y_COORD]; Chatbox_icon_x = Chatbox_small_display_coords[gr_screen.res][CHATBOX_X_COORD] - CHATBOX_TEAM_ICON_SPACE; @@ -661,7 +661,7 @@ void chatbox_set_mode(int mode_flags) break; case 1: - SDL_strlcpy(Chatbox_mask, Chatbox_big_bitmap_mask_fname[gr_screen.res], sizeof(Chatbox_mask)); + SDL_strlcpy(Chatbox_mask, Chatbox_big_bitmap_mask_fname[gr_screen.res], SDL_arraysize(Chatbox_mask)); Chatbox_x1 = Chatbox_big_coords[gr_screen.res][CHATBOX_X_COORD]; Chatbox_y1 = Chatbox_big_coords[gr_screen.res][CHATBOX_Y_COORD]; Chatbox_icon_x = Chatbox_big_display_coords[gr_screen.res][CHATBOX_X_COORD] - CHATBOX_TEAM_ICON_SPACE; @@ -1030,12 +1030,12 @@ void chatbox_add_line(const char *msg, int pid, int add_id) // maybe stick on who sent the message if(add_id){ if(MULTI_STANDALONE(Net_players[pid])){ - SDL_snprintf(msg_extra, sizeof(msg_extra), NOX("%s %s"), NOX(""), msg ); + SDL_snprintf(msg_extra, SDL_arraysize(msg_extra), NOX("%s %s"), NOX(""), msg ); } else { - SDL_snprintf(msg_extra, sizeof(msg_extra), NOX("%s: %s"), Net_players[pid].player->short_callsign, msg ); + SDL_snprintf(msg_extra, SDL_arraysize(msg_extra), NOX("%s: %s"), Net_players[pid].player->short_callsign, msg ); } } else { - SDL_strlcpy(msg_extra, msg, sizeof(msg_extra)); + SDL_strlcpy(msg_extra, msg, SDL_arraysize(msg_extra)); } SDL_assert(strlen(msg_extra) < (CHATBOX_STRING_LEN - 2)); diff --git a/src/missionui/missionbrief.cpp b/src/missionui/missionbrief.cpp index 6ef444a..8257da4 100644 --- a/src/missionui/missionbrief.cpp +++ b/src/missionui/missionbrief.cpp @@ -1557,7 +1557,7 @@ void brief_render(float frametime) #endif if (Game_mode & GM_MULTIPLAYER) { char buf[256]; - SDL_strlcpy(buf, The_mission.name, sizeof(buf)); + SDL_strlcpy(buf, The_mission.name, SDL_arraysize(buf)); gr_force_fit_string(buf, 255, Title_coords_multi[gr_screen.res][2]); #ifdef MAKE_FS1 // align from the end of the string instead of the beginning @@ -1653,23 +1653,23 @@ int brief_setup_closeup(brief_icon *bi) break; case ICON_ASTEROID_FIELD: #if !(defined(FS2_DEMO) || defined(FS1_DEMO)) - SDL_strlcpy(pof_filename, Asteroid_info[ASTEROID_TYPE_BIG].pof_files[0], sizeof(pof_filename)); - SDL_strlcpy(Closeup_icon->closeup_label, XSTR( "asteroid", 431), sizeof(Closeup_icon->closeup_label)); + SDL_strlcpy(pof_filename, Asteroid_info[ASTEROID_TYPE_BIG].pof_files[0], SDL_arraysize(pof_filename)); + SDL_strlcpy(Closeup_icon->closeup_label, XSTR( "asteroid", 431), SDL_arraysize(Closeup_icon->closeup_label)); (void) vm_vec_make(&Closeup_cam_pos, 0.0f, 0.0f, -334.0f); Closeup_zoom = 0.5f; #endif break; case ICON_JUMP_NODE: - SDL_strlcpy(pof_filename, NOX("subspacenode.pof"), sizeof(pof_filename)); - SDL_strlcpy(Closeup_icon->closeup_label, XSTR( "jump node", 432), sizeof(Closeup_icon->closeup_label)); + SDL_strlcpy(pof_filename, NOX("subspacenode.pof"), SDL_arraysize(pof_filename)); + SDL_strlcpy(Closeup_icon->closeup_label, XSTR( "jump node", 432), SDL_arraysize(Closeup_icon->closeup_label)); (void) vm_vec_make(&Closeup_cam_pos, 0.0f, 0.0f, -2700.0f); Closeup_zoom = 0.5f; Closeup_one_revolution_time = ONE_REV_TIME * 3; break; case ICON_UNKNOWN: case ICON_UNKNOWN_WING: - SDL_strlcpy(pof_filename, NOX("unknownship.pof"), sizeof(pof_filename)); - SDL_strlcpy(Closeup_icon->closeup_label, XSTR( "unknown", 433), sizeof(Closeup_icon->closeup_label)); + SDL_strlcpy(pof_filename, NOX("unknownship.pof"), SDL_arraysize(pof_filename)); + SDL_strlcpy(Closeup_icon->closeup_label, XSTR( "unknown", 433), SDL_arraysize(Closeup_icon->closeup_label)); (void) vm_vec_make(&Closeup_cam_pos, 0.0f, 0.0f, -22.0f); Closeup_zoom = 0.5f; break; @@ -1678,7 +1678,7 @@ int brief_setup_closeup(brief_icon *bi) SDL_assert( Closeup_icon->ship_class != -1 ); sip = &Ship_info[Closeup_icon->ship_class]; - SDL_strlcpy(Closeup_icon->closeup_label,sip->name, sizeof(Closeup_icon->closeup_label)); + SDL_strlcpy(Closeup_icon->closeup_label,sip->name, SDL_arraysize(Closeup_icon->closeup_label)); // cut any text off after (and including) '#' char brief_truncate_label(Closeup_icon->closeup_label); diff --git a/src/missionui/missioncmdbrief.cpp b/src/missionui/missioncmdbrief.cpp index f90c12a..5fc3047 100644 --- a/src/missionui/missioncmdbrief.cpp +++ b/src/missionui/missioncmdbrief.cpp @@ -640,7 +640,7 @@ void cmd_brief_ani_wave_init(int index) name = Cur_cmd_brief->stage[index].ani_filename; if (!name[0] || !SDL_strcasecmp(name, NOX("")) || !SDL_strcasecmp(name, NOX("none.ani"))) { name = NOX("CB_default"); - SDL_strlcpy(Cur_cmd_brief->stage[index].ani_filename, name, sizeof(Cur_cmd_brief->stage[0].ani_filename)); + SDL_strlcpy(Cur_cmd_brief->stage[index].ani_filename, name, SDL_arraysize(Cur_cmd_brief->stage[0].ani_filename)); } int load_attempts = 0; @@ -872,7 +872,7 @@ void cmd_brief_do_frame(float frametime) gr_set_font(FONT1); gr_set_color_fast(&Color_text_heading); - SDL_snprintf(buf, sizeof(buf), XSTR( "Stage %d of %d", 464), Cur_stage + 1, Cur_cmd_brief->num_stages); + SDL_snprintf(buf, SDL_arraysize(buf), XSTR( "Stage %d of %d", 464), Cur_stage + 1, Cur_cmd_brief->num_stages); gr_get_string_size(&w, NULL, buf); gr_string(Cmd_text_wnd_coords[gr_screen.res][CMD_X_COORD] + Cmd_text_wnd_coords[gr_screen.res][CMD_W_COORD] - w, Cmd_stage_y[gr_screen.res], buf); diff --git a/src/missionui/missiondebrief.cpp b/src/missionui/missiondebrief.cpp index 2a7c426..8e92bb5 100644 --- a/src/missionui/missiondebrief.cpp +++ b/src/missionui/missiondebrief.cpp @@ -1316,7 +1316,7 @@ void debrief_choose_promotion_voice() int i, j; if(Campaign.current_mission < 0){ - SDL_snprintf(Promotion_stage.voice, sizeof(Promotion_stage.voice), NOX("9_%s"), Ranks[Promoted].promotion_voice_base); + SDL_snprintf(Promotion_stage.voice, SDL_arraysize(Promotion_stage.voice), NOX("9_%s"), Ranks[Promoted].promotion_voice_base); return; } @@ -1328,7 +1328,7 @@ void debrief_choose_promotion_voice() for (j=0; jstats.m_badge_earned].voice_base); + SDL_snprintf(Badge_stage.voice, SDL_arraysize(Badge_stage.voice), NOX("9_%s"), Badge_info[Player->stats.m_badge_earned].voice_base); #else // default to FS1 guy - SDL_snprintf(Badge_stage.voice, sizeof(Badge_stage.voice), NOX("%s"), Badge_info[Player->stats.m_badge_earned].voice_base); + SDL_snprintf(Badge_stage.voice, SDL_arraysize(Badge_stage.voice), NOX("%s"), Badge_info[Player->stats.m_badge_earned].voice_base); #endif } if ((Campaign.missions[Campaign.current_mission].name) && (Campaign.filename)) { #ifdef MAKE_FS1 if ( Player->on_bastion ) { - SDL_snprintf(Badge_stage.voice, sizeof(Badge_stage.voice), NOX("%s"), Badge_info[Player->stats.m_badge_earned].voice_base2); + SDL_snprintf(Badge_stage.voice, SDL_arraysize(Badge_stage.voice), NOX("%s"), Badge_info[Player->stats.m_badge_earned].voice_base2); return; } else { - SDL_snprintf(Badge_stage.voice, sizeof(Badge_stage.voice), NOX("%s"), Badge_info[Player->stats.m_badge_earned].voice_base); + SDL_snprintf(Badge_stage.voice, SDL_arraysize(Badge_stage.voice), NOX("%s"), Badge_info[Player->stats.m_badge_earned].voice_base); return; } #else @@ -1376,7 +1376,7 @@ void debrief_choose_badge_voice() for (j=0; jstats.m_badge_earned].voice_base); + SDL_snprintf(Badge_stage.voice, SDL_arraysize(Badge_stage.voice), NOX("%d_%s"), Debrief_promotion_voice_mapping[i][j].persona_index, Badge_info[Player->stats.m_badge_earned].voice_base); return; } } @@ -1387,10 +1387,10 @@ void debrief_choose_badge_voice() #ifndef MAKE_FS1 // default to petrarch - SDL_snprintf(Badge_stage.voice, sizeof(Badge_stage.voice), NOX("9_%s"), Badge_info[Player->stats.m_badge_earned].voice_base); + SDL_snprintf(Badge_stage.voice, SDL_arraysize(Badge_stage.voice), NOX("9_%s"), Badge_info[Player->stats.m_badge_earned].voice_base); #else // default to FS1 guy - SDL_snprintf(Badge_stage.voice, sizeof(Badge_stage.voice), NOX("%s"), Badge_info[Player->stats.m_badge_earned].voice_base); + SDL_snprintf(Badge_stage.voice, SDL_arraysize(Badge_stage.voice), NOX("%s"), Badge_info[Player->stats.m_badge_earned].voice_base); #endif } @@ -1421,14 +1421,14 @@ void debrief_award_init() } else { ver = 0; } - SDL_snprintf(buf, sizeof(buf), NOX("%s%.2d"), Debrief_award_filename[gr_screen.res][DB_AWARD_WINGS], ver); + SDL_snprintf(buf, SDL_arraysize(buf), NOX("%s%.2d"), Debrief_award_filename[gr_screen.res][DB_AWARD_WINGS], ver); Wings_bitmap = bm_load(buf); #ifndef MAKE_FS1 } else if (Player->stats.m_medal_earned == 17) { // special hack for the soc crest Crest_bitmap = bm_load(Debrief_award_filename[gr_screen.res][DB_AWARD_SOC]); #endif } else { - SDL_snprintf(buf, sizeof(buf), NOX("%s%.2d"), Debrief_award_filename[gr_screen.res][DB_AWARD_MEDAL], Player->stats.m_medal_earned); + SDL_snprintf(buf, SDL_arraysize(buf), NOX("%s%.2d"), Debrief_award_filename[gr_screen.res][DB_AWARD_MEDAL], Player->stats.m_medal_earned); Medal_bitmap = bm_load(buf); } @@ -1440,7 +1440,7 @@ void debrief_award_init() // handle promotions if ( Player->stats.m_promotion_earned != -1 ) { Promoted = Player->stats.m_promotion_earned; - SDL_snprintf(buf, sizeof(buf), NOX("%s%.2d"), Debrief_award_filename[gr_screen.res][DB_AWARD_RANK], Promoted + 1); + SDL_snprintf(buf, SDL_arraysize(buf), NOX("%s%.2d"), Debrief_award_filename[gr_screen.res][DB_AWARD_RANK], Promoted + 1); Rank_bitmap = bm_load(buf); Promotion_stage.new_text = Ranks[Promoted].promotion_text; @@ -1458,7 +1458,7 @@ void debrief_award_init() // only grant badge if earned and allowed. (no_promotion really means no promotion and no badges) if ( Player->stats.m_badge_earned != -1 ) { i = Player->stats.m_badge_earned; - SDL_snprintf(buf, sizeof(buf), NOX("%s%.2d"), Debrief_award_filename[gr_screen.res][DB_AWARD_BADGE], i + 1); + SDL_snprintf(buf, SDL_arraysize(buf), NOX("%s%.2d"), Debrief_award_filename[gr_screen.res][DB_AWARD_BADGE], i + 1); Badge_bitmap = bm_load(buf); Badge_stage.new_text = Badge_info[i].promotion_text; @@ -1522,13 +1522,13 @@ void debrief_traitor_init() // DKA 9/13/99 Only 1 traitor msg for FS2 #ifdef MAKE_FS1 if ( Player->on_bastion ) { - SDL_strlcpy(stagep->voice, NOX("3_"), sizeof(stagep->voice)); + SDL_strlcpy(stagep->voice, NOX("3_"), SDL_arraysize(stagep->voice)); } else { - SDL_strlcpy(stagep->voice, NOX("1_"), sizeof(stagep->voice)); + SDL_strlcpy(stagep->voice, NOX("1_"), SDL_arraysize(stagep->voice)); } #endif - SDL_strlcat(stagep->voice, traitor_voice_file, sizeof(stagep->voice)); + SDL_strlcat(stagep->voice, traitor_voice_file, SDL_arraysize(stagep->voice)); required_string("$Recommendation text:"); if ( Fred_running ) { @@ -1583,7 +1583,7 @@ void debrief_multi_list_init() // switch stats display to this newly selected player set_player_stats(Multi_list[0].net_player_index); - SDL_strlcpy(Debrief_current_callsign, Multi_list[0].callsign, sizeof(Debrief_current_callsign)); + SDL_strlcpy(Debrief_current_callsign, Multi_list[0].callsign, SDL_arraysize(Debrief_current_callsign)); Debrief_player = Player; } @@ -1636,7 +1636,7 @@ void debrief_multi_list_draw() // switch stats display to this newly selected player set_player_stats(Multi_list[idx].net_player_index); - SDL_strlcpy(Debrief_current_callsign, Multi_list[idx].callsign, sizeof(Debrief_current_callsign)); + SDL_strlcpy(Debrief_current_callsign, Multi_list[idx].callsign, SDL_arraysize(Debrief_current_callsign)); Debrief_player = Net_players[Multi_list[idx].net_player_index].player; break; } @@ -1703,9 +1703,9 @@ void debrief_multi_list_draw() } } - SDL_strlcpy(str, Multi_list[z].callsign, sizeof(str)); + SDL_strlcpy(str, Multi_list[z].callsign, SDL_arraysize(str)); if(Net_players[Multi_list[z].net_player_index].flags & NETINFO_FLAG_OBSERVER && !(Net_players[Multi_list[z].net_player_index].flags & NETINFO_FLAG_OBS_PLAYER)){ - SDL_strlcat(str, XSTR( "(O)", 438), sizeof(str)); + SDL_strlcat(str, XSTR( "(O)", 438), SDL_arraysize(str)); } // bli @@ -1930,7 +1930,7 @@ void debrief_render_stagenum() if (Num_stages < 2) return; - SDL_snprintf(buf, sizeof(buf), XSTR( "%d of %d", 445), Current_stage + 1, Num_stages); + SDL_snprintf(buf, SDL_arraysize(buf), XSTR( "%d of %d", 445), Current_stage + 1, Num_stages); gr_get_string_size(&w, NULL, buf); gr_set_color_fast(&Color_bright_blue); gr_string(Debrief_stage_info_coords[gr_screen.res][0] - w, Debrief_stage_info_coords[gr_screen.res][1], buf); @@ -1942,7 +1942,7 @@ void debrief_render_mission_time(int y_loc) { char time_str[30]; - game_format_time(Missiontime, time_str, sizeof(time_str)); + game_format_time(Missiontime, time_str, SDL_arraysize(time_str)); gr_string(0, y_loc, XSTR( "Mission Time", 446)); gr_string(Debrief_text_x2[gr_screen.res], y_loc, time_str); } @@ -2233,8 +2233,8 @@ void debrief_setup_ship_kill_stats(int stage_num) kill_info->num = kill_arr[i]; - SDL_strlcpy(kill_info->text, Ship_info[i].name, sizeof(kill_info->text)); - SDL_strlcat(kill_info->text, NOX(":"), sizeof(kill_info->text)); + SDL_strlcpy(kill_info->text, Ship_info[i].name, SDL_arraysize(kill_info->text)); + SDL_strlcat(kill_info->text, NOX(":"), SDL_arraysize(kill_info->text)); } Num_text_lines += 2; @@ -2260,7 +2260,7 @@ void debrief_check_buttons() if ((z >= 0) && (z < Multi_list_size)) { // switch stats display to this newly selected player set_player_stats(Multi_list[z].net_player_index); - SDL_strlcpy(Debrief_current_callsign, Multi_list[z].callsign, sizeof(Debrief_current_callsign)); + SDL_strlcpy(Debrief_current_callsign, Multi_list[z].callsign, SDL_arraysize(Debrief_current_callsign)); Debrief_player = Net_players[Multi_list[z].net_player_index].player; Multi_list_select = z; debrief_setup_ship_kill_stats(Current_stage); @@ -2423,7 +2423,7 @@ void debrief_init() // rank_bitmaps_clear(); // rank_bitmaps_load(); - SDL_strlcpy(Debrief_current_callsign, Player->callsign, sizeof(Debrief_current_callsign)); + SDL_strlcpy(Debrief_current_callsign, Player->callsign, SDL_arraysize(Debrief_current_callsign)); Debrief_player = Player; // Debrief_current_net_player_index = debrief_multi_list[0].net_player_index; @@ -2941,7 +2941,7 @@ void debrief_do_frame(float frametime) // draw the title of the mission gr_set_color_fast(&Color_bright_white); - SDL_strlcpy(buf, The_mission.name, sizeof(buf)); + SDL_strlcpy(buf, The_mission.name, SDL_arraysize(buf)); gr_force_fit_string(buf, 255, Debrief_title_coords[gr_screen.res][2]); gr_string(Debrief_title_coords[gr_screen.res][0], Debrief_title_coords[gr_screen.res][1], buf); @@ -3062,7 +3062,7 @@ void debrief_rebuild_player_list() if ( MULTI_CONNECTED((*np)) && !MULTI_STANDALONE((*np))){ list = &Multi_list[Multi_list_size++]; list->net_player_index = i; - SDL_strlcpy(list->callsign, np->player->callsign, sizeof(list->callsign)); + SDL_strlcpy(list->callsign, np->player->callsign, SDL_arraysize(list->callsign)); // make sure to leave some room to blit the team indicator gr_force_fit_string(list->callsign, CALLSIGN_LEN - 1, Debrief_list_coords[gr_screen.res][2] - MULTI_LIST_TEAM_OFFSET); diff --git a/src/missionui/missionscreencommon.cpp b/src/missionui/missionscreencommon.cpp index f182a44..1f5ac62 100644 --- a/src/missionui/missionscreencommon.cpp +++ b/src/missionui/missionscreencommon.cpp @@ -645,7 +645,7 @@ void common_set_interface_palette(const char *filename) if ( (InterfacePaletteBitmap != -1) && !SDL_strcasecmp(filename, buf) ) return; // already set to this palette - SDL_strlcpy(buf, filename, sizeof(buf)); + SDL_strlcpy(buf, filename, SDL_arraysize(buf)); // unload the interface bitmap from memory if (InterfacePaletteBitmap != -1) { diff --git a/src/missionui/missionshipchoice.cpp b/src/missionui/missionshipchoice.cpp index 108a647..8d73703 100644 --- a/src/missionui/missionshipchoice.cpp +++ b/src/missionui/missionshipchoice.cpp @@ -1400,7 +1400,7 @@ void ship_select_blit_ship_info() gr_set_color_fast(header); gr_string(Ship_info_coords[gr_screen.res][SHIP_SELECT_X_COORD], y_start,XSTR("Max Velocity",742)); y_start += 10; - SDL_snprintf(str,sizeof(str),XSTR("%d m/s",743),(int)sip->max_vel.xyz.z); + SDL_snprintf(str,SDL_arraysize(str),XSTR("%d m/s",743),(int)sip->max_vel.xyz.z); gr_set_color_fast(text); gr_string(Ship_info_coords[gr_screen.res][SHIP_SELECT_X_COORD]+4, y_start,str); y_start += 10; @@ -1855,7 +1855,7 @@ void draw_ship_icon_with_number(int screen_offset, int ship_class) gr_bitmap(Ship_list_coords[gr_screen.res][screen_offset][0], Ship_list_coords[gr_screen.res][screen_offset][1]); // blit the number - SDL_snprintf(buf, sizeof(buf), "%d", Ss_pool[ship_class] ); + SDL_snprintf(buf, SDL_arraysize(buf), "%d", Ss_pool[ship_class] ); gr_set_color_fast(&Color_white); gr_string(num_x, num_y, buf); } @@ -1895,16 +1895,16 @@ anim* ss_load_individual_animation(int ship_class) // If we are in 1024x768, we first want to append "2_" in front of the filename if (gr_screen.res == GR_1024) { SDL_assert(strlen(Ship_info[ship_class].anim_filename) <= 30); - SDL_strlcpy(animation_filename, "2_", sizeof(animation_filename)); - SDL_strlcat(animation_filename, Ship_info[ship_class].anim_filename, sizeof(animation_filename)); + SDL_strlcpy(animation_filename, "2_", SDL_arraysize(animation_filename)); + SDL_strlcat(animation_filename, Ship_info[ship_class].anim_filename, SDL_arraysize(animation_filename)); // now check if file exists // GRR must add a .ANI at the end for detection - SDL_strlcat(animation_filename, ".ani", sizeof(animation_filename)); + SDL_strlcat(animation_filename, ".ani", SDL_arraysize(animation_filename)); p_anim = anim_load(animation_filename); if (p_anim == NULL) { // failed loading hi-res, revert to low res - SDL_strlcpy(animation_filename, Ship_info[ship_class].anim_filename, sizeof(animation_filename)); + SDL_strlcpy(animation_filename, Ship_info[ship_class].anim_filename, SDL_arraysize(animation_filename)); p_anim = anim_load(animation_filename); mprintf(("Ship ANI: Can not find %s, using lowres version instead.\n", animation_filename)); } else { @@ -1922,7 +1922,7 @@ anim* ss_load_individual_animation(int ship_class) } */ } else { - SDL_strlcpy(animation_filename, Ship_info[ship_class].anim_filename, sizeof(animation_filename)); + SDL_strlcpy(animation_filename, Ship_info[ship_class].anim_filename, SDL_arraysize(animation_filename)); p_anim = anim_load(animation_filename); } @@ -2042,8 +2042,8 @@ void commit_pressed() // save the player loadout if ( !(Game_mode & GM_MULTIPLAYER) ) { - SDL_strlcpy(Player_loadout.filename, Game_current_mission_filename, sizeof(Player_loadout.filename)); - SDL_strlcpy(Player_loadout.last_modified, The_mission.modified, sizeof(Player_loadout.last_modified)); + SDL_strlcpy(Player_loadout.filename, Game_current_mission_filename, SDL_arraysize(Player_loadout.filename)); + SDL_strlcpy(Player_loadout.last_modified, The_mission.modified, SDL_arraysize(Player_loadout.last_modified)); wss_save_loadout(); } diff --git a/src/missionui/missionweaponchoice.cpp b/src/missionui/missionweaponchoice.cpp index 6e8bfb5..ff78215 100644 --- a/src/missionui/missionweaponchoice.cpp +++ b/src/missionui/missionweaponchoice.cpp @@ -1245,7 +1245,7 @@ void wl_render_overhead_view(float frametime) } else { // high-res char filename[NAME_LENGTH+2] = "2_"; - SDL_strlcat(filename, Ship_info[ship_class].overhead_filename, sizeof(filename)); + SDL_strlcat(filename, Ship_info[ship_class].overhead_filename, SDL_arraysize(filename)); wl_ship->overhead_bitmap = bm_load(filename); } if ( wl_ship->overhead_bitmap < 0 ) { @@ -1257,7 +1257,7 @@ void wl_render_overhead_view(float frametime) gr_bitmap(Wl_overhead_coords[gr_screen.res][0], Wl_overhead_coords[gr_screen.res][1]); } - ss_return_name(Selected_wl_slot/4, Selected_wl_slot%4, name, sizeof(name)); + ss_return_name(Selected_wl_slot/4, Selected_wl_slot%4, name, SDL_arraysize(name)); gr_set_color_fast(&Color_normal); gr_string(Wl_ship_name_coords[gr_screen.res][0], Wl_ship_name_coords[gr_screen.res][1], name); } @@ -1447,17 +1447,17 @@ void wl_load_anim(int weapon_class) // If we are in 1024x768, we first want to append "2_" in front of the filename if (gr_screen.res == GR_1024) { SDL_assert(strlen(Weapon_info[weapon_class].anim_filename) <= 30); - SDL_strlcpy(animation_filename, "2_", sizeof(animation_filename)); - SDL_strlcat(animation_filename, Weapon_info[weapon_class].anim_filename, sizeof(animation_filename)); + SDL_strlcpy(animation_filename, "2_", SDL_arraysize(animation_filename)); + SDL_strlcat(animation_filename, Weapon_info[weapon_class].anim_filename, SDL_arraysize(animation_filename)); // now check if file exists // GRR must add a .ANI at the end for detection - SDL_strlcat(animation_filename,".ani", sizeof(animation_filename)); + SDL_strlcat(animation_filename,".ani", SDL_arraysize(animation_filename)); icon->anim = anim_load(animation_filename); if (icon->anim == NULL) { mprintf(("Weapon ANI: Can not find %s, using lowres version instead.\n",animation_filename)); - SDL_strlcpy(animation_filename, Weapon_info[weapon_class].anim_filename, sizeof(animation_filename)); + SDL_strlcpy(animation_filename, Weapon_info[weapon_class].anim_filename, SDL_arraysize(animation_filename)); icon->anim = anim_load(animation_filename); } @@ -1472,7 +1472,7 @@ void wl_load_anim(int weapon_class) } */ } else { - SDL_strlcpy(animation_filename, Weapon_info[weapon_class].anim_filename, sizeof(animation_filename)); + SDL_strlcpy(animation_filename, Weapon_info[weapon_class].anim_filename, SDL_arraysize(animation_filename)); // load the compressed ship animation into memory icon->anim = anim_load(animation_filename); } @@ -2990,8 +2990,8 @@ void weapon_select_do(float frametime) if (Lcl_gr) { // might have to get weapon name translation char display_name[128]; - SDL_strlcpy(display_name, Weapon_info[Carried_wl_icon.weapon_class].name, sizeof(display_name)); - lcl_translate_wep_name(display_name, sizeof(display_name)); + SDL_strlcpy(display_name, Weapon_info[Carried_wl_icon.weapon_class].name, SDL_arraysize(display_name)); + lcl_translate_wep_name(display_name, SDL_arraysize(display_name)); popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, XSTR( "A %s is unable to carry %s weaponry", 633), Ship_info[ship_class].name, display_name); } else { popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, XSTR( "A %s is unable to carry %s weaponry", 633), Ship_info[ship_class].name, Weapon_info[Carried_wl_icon.weapon_class].name); @@ -3102,7 +3102,7 @@ void wl_render_icon_count(int num, int x, int y) int number_to_draw = (num > 1000) ? 999 : num; // cap count @ 999 SDL_assert(number_to_draw >= 0); - SDL_snprintf(buf, sizeof(buf), "%d", number_to_draw); + SDL_snprintf(buf, SDL_arraysize(buf), "%d", number_to_draw); gr_get_string_size(&num_w, &num_h, buf, strlen(buf)); // render diff --git a/src/missionui/redalert.cpp b/src/missionui/redalert.cpp index d52f2da..7973f35 100644 --- a/src/missionui/redalert.cpp +++ b/src/missionui/redalert.cpp @@ -713,7 +713,7 @@ void red_alert_store_wingman_status() Red_alert_num_slots_used = 0; // store the mission filename for the red alert precursor mission - SDL_strlcpy(Red_alert_precursor_mission, Game_current_mission_filename, sizeof(Red_alert_precursor_mission)); + SDL_strlcpy(Red_alert_precursor_mission, Game_current_mission_filename, SDL_arraysize(Red_alert_precursor_mission)); // store status for all existing ships for ( so = GET_FIRST(&Ship_obj_list); so != END_OF_LIST(&Ship_obj_list); so = GET_NEXT(so) ) { @@ -737,7 +737,7 @@ void red_alert_store_wingman_status() ras = &Red_alert_wingman_status[Red_alert_num_slots_used]; Red_alert_num_slots_used++; - SDL_strlcpy(ras->name, shipp->ship_name, sizeof(ras->name)); + SDL_strlcpy(ras->name, shipp->ship_name, SDL_arraysize(ras->name)); ras->hull = Objects[shipp->objnum].hull_strength; ras->ship_class = shipp->ship_info_index; red_alert_store_weapons(ras, &shipp->weapons); @@ -756,7 +756,7 @@ void red_alert_store_wingman_status() ras = &Red_alert_wingman_status[Red_alert_num_slots_used]; Red_alert_num_slots_used++; - SDL_strlcpy(ras->name, Ships_exited[idx].ship_name, sizeof(ras->name)); + SDL_strlcpy(ras->name, Ships_exited[idx].ship_name, SDL_arraysize(ras->name)); ras->hull = float(Ships_exited[idx].hull_strength); ras->ship_class = RED_ALERT_EXITED_SHIP_CLASS; //shipp->ship_info_index; red_alert_store_weapons(ras, NULL); diff --git a/src/model/modelread.cpp b/src/model/modelread.cpp index 0ddbbbb..fafac0b 100644 --- a/src/model/modelread.cpp +++ b/src/model/modelread.cpp @@ -936,7 +936,7 @@ void model_copy_subsystems( int n_subsystems, model_subsystem *d_sp, model_subsy dest->turn_rate = source->turn_rate; dest->turret_gun_sobj = source->turret_gun_sobj; - SDL_strlcpy( dest->name, source->name, sizeof(dest->name) ); + SDL_strlcpy( dest->name, source->name, SDL_arraysize(dest->name) ); if ( dest->type == SUBSYSTEM_TURRET ) { int nfp; @@ -950,7 +950,7 @@ void model_copy_subsystems( int n_subsystems, model_subsystem *d_sp, model_subsy dest->turret_firing_point[nfp] = source->turret_firing_point[nfp]; if ( dest->flags & MSS_FLAG_CREWPOINT ) - SDL_strlcpy(dest->crewspot, source->crewspot, sizeof(dest->crewspot)); + SDL_strlcpy(dest->crewspot, source->crewspot, SDL_arraysize(dest->crewspot)); } break; } @@ -969,11 +969,11 @@ static void set_subsystem_info( model_subsystem *subsystemp, char *props, char * char lcdname[256]; if ( (p = strstr(props, "$name")) != NULL) - get_user_prop_value(p+5, subsystemp->name, sizeof(subsystemp->name)); + get_user_prop_value(p+5, subsystemp->name, SDL_arraysize(subsystemp->name)); else - SDL_strlcpy( subsystemp->name, dname, sizeof(subsystemp->name) ); + SDL_strlcpy( subsystemp->name, dname, SDL_arraysize(subsystemp->name) ); - SDL_strlcpy(lcdname, dname, sizeof(lcdname)); + SDL_strlcpy(lcdname, dname, SDL_arraysize(lcdname)); SDL_strlwr(lcdname); // check the name for it's specific type @@ -986,16 +986,16 @@ static void set_subsystem_info( model_subsystem *subsystemp, char *props, char * subsystemp->type = SUBSYSTEM_TURRET; if ( (p = strstr(props, "$fov")) != NULL ) - get_user_prop_value(p+4, buf, sizeof(buf)); // get the value of the fov + get_user_prop_value(p+4, buf, SDL_arraysize(buf)); // get the value of the fov else - SDL_strlcpy(buf,"180", sizeof(buf)); + SDL_strlcpy(buf,"180", SDL_arraysize(buf)); angle = ANG_TO_RAD(atoi(buf))/2.0f; subsystemp->turret_fov = (float)cos(angle); subsystemp->turret_num_firing_points = 0; if ( (p = strstr(props, "$crewspot")) != NULL) { subsystemp->flags |= MSS_FLAG_CREWPOINT; - get_user_prop_value(p+9, subsystemp->crewspot, sizeof(subsystemp->crewspot)); + get_user_prop_value(p+9, subsystemp->crewspot, SDL_arraysize(subsystemp->crewspot)); } } else if ( strstr(lcdname, "navigation") ) { @@ -1023,7 +1023,7 @@ static void set_subsystem_info( model_subsystem *subsystemp, char *props, char * // get time for (a) complete rotation (b) step (c) activation float turn_time; - get_user_prop_value(p+7, buf, sizeof(buf)); + get_user_prop_value(p+7, buf, SDL_arraysize(buf)); turn_time = (float)atof(buf); // CASE OF STEPPED ROTATION @@ -1034,7 +1034,7 @@ static void set_subsystem_info( model_subsystem *subsystemp, char *props, char * // get number of steps if ( (p = strstr(props, "$steps")) != NULL) { - get_user_prop_value(p+6, buf, sizeof(buf)); + get_user_prop_value(p+6, buf, SDL_arraysize(buf)); subsystemp->stepped_rotation->num_steps = atoi(buf); } else { subsystemp->stepped_rotation->num_steps = 8; @@ -1042,7 +1042,7 @@ static void set_subsystem_info( model_subsystem *subsystemp, char *props, char * // get pause time if ( (p = strstr(props, "$t_paused")) != NULL) { - get_user_prop_value(p+9, buf, sizeof(buf)); + get_user_prop_value(p+9, buf, SDL_arraysize(buf)); subsystemp->stepped_rotation->t_pause = (float)atof(buf); } else { subsystemp->stepped_rotation->t_pause = 2.0f; @@ -1050,7 +1050,7 @@ static void set_subsystem_info( model_subsystem *subsystemp, char *props, char * // get transition time - time to go between steps if ( (p = strstr(props, "$t_transit")) != NULL) { - get_user_prop_value(p+10, buf, sizeof(buf)); + get_user_prop_value(p+10, buf, SDL_arraysize(buf)); subsystemp->stepped_rotation->t_transit = (float)atof(buf); } else { subsystemp->stepped_rotation->t_transit = 2.0f; @@ -1058,7 +1058,7 @@ static void set_subsystem_info( model_subsystem *subsystemp, char *props, char * // get fraction of time spent in accel if ( (p = strstr(props, "$fraction_accel")) != NULL) { - get_user_prop_value(p+15, buf, sizeof(buf)); + get_user_prop_value(p+15, buf, SDL_arraysize(buf)); subsystemp->stepped_rotation->fraction = (float)atof(buf); SDL_assert(subsystemp->stepped_rotation->fraction > 0 && subsystemp->stepped_rotation->fraction < 0.5); } else { @@ -1076,7 +1076,7 @@ static void set_subsystem_info( model_subsystem *subsystemp, char *props, char * // CASE OF AI ROTATION else if ( (p = strstr(props, "$ai")) != NULL) { - get_user_prop_value(p+8, buf, sizeof(buf)); + get_user_prop_value(p+8, buf, SDL_arraysize(buf)); subsystemp->flags |= MSS_FLAG_AI_ROTATE; // get parameters - ie, speed / dist / other ?? @@ -1136,7 +1136,7 @@ void do_new_subsystem( int n_subsystems, model_subsystem *slist, int subobj_num, subsystemp->pnt = *pnt; // use the offset to get the center point of the subsystem subsystemp->radius = rad; set_subsystem_info( subsystemp, props, subobj_name); - SDL_strlcpy(subsystemp->subobj_name, subobj_name, sizeof(subsystemp->subobj_name)); // copy the object name + SDL_strlcpy(subsystemp->subobj_name, subobj_name, SDL_arraysize(subsystemp->subobj_name)); // copy the object name return; } } @@ -1144,7 +1144,7 @@ void do_new_subsystem( int n_subsystems, model_subsystem *slist, int subobj_num, if ( !ss_warning_shown) { char bname[MAX_FILENAME_LEN]; - base_filename(model_filename, bname, sizeof(bname)); + base_filename(model_filename, bname, SDL_arraysize(bname)); Warning(LOCATION, "A subsystem was found in model %s that does not have a record in ships.tbl.\nA list of subsystems for this ship will be dumped to:\n\ndata\\tables\\%s.subsystems for inclusion\n into ships.tbl.", model_filename, bname); ss_warning_shown = 1; @@ -1154,7 +1154,7 @@ void do_new_subsystem( int n_subsystems, model_subsystem *slist, int subobj_num, #ifndef NDEBUG if ( ss_fp ) { char tmp_buffer[128]; - SDL_snprintf(tmp_buffer, sizeof(tmp_buffer), "$Subsystem:\t\t\t%s,1,0.0\n", subobj_name); + SDL_snprintf(tmp_buffer, SDL_arraysize(tmp_buffer), "$Subsystem:\t\t\t%s,1,0.0\n", subobj_name); cfputs(tmp_buffer, ss_fp); } #endif @@ -1170,13 +1170,13 @@ void print_family_tree( polymodel *obj, int modelnum, const char * ident, int is if (strlen(ident)==0 ) { mprintf(( " %s", obj->submodel[modelnum].name )); - SDL_snprintf( temp, sizeof(temp), " " ); + SDL_snprintf( temp, SDL_arraysize(temp), " " ); } else if ( islast ) { mprintf(( "%s��%s", ident, obj->submodel[modelnum].name )); - SDL_snprintf( temp, sizeof(temp), "%s ", ident ); + SDL_snprintf( temp, SDL_arraysize(temp), "%s ", ident ); } else { mprintf(( "%s��%s", ident, obj->submodel[modelnum].name )); - SDL_snprintf( temp, sizeof(temp), "%s� ", ident ); + SDL_snprintf( temp, SDL_arraysize(temp), "%s� ", ident ); } mprintf(( "\n" )); @@ -1247,7 +1247,7 @@ int read_model_file(polymodel * pm, const char *filename, int n_subsystems, mode int i,j; #ifndef NDEBUG - SDL_strlcpy(Global_filename, filename, sizeof(Global_filename)); + SDL_strlcpy(Global_filename, filename, SDL_arraysize(Global_filename)); #endif fp = cfopen(filename,"rb"); @@ -1263,13 +1263,13 @@ int read_model_file(polymodel * pm, const char *filename, int n_subsystems, mode { char bname[MAX_PATH_LEN]; - base_filename(filename, bname, sizeof(bname)); - SDL_snprintf(debug_name, sizeof(debug_name), "%s.subsystems", bname); + base_filename(filename, bname, SDL_arraysize(bname)); + SDL_snprintf(debug_name, SDL_arraysize(debug_name), "%s.subsystems", bname); ss_fp = cfopen(debug_name, "wb", CFILE_NORMAL, CF_TYPE_TABLES ); if ( !ss_fp ) { mprintf(( "Can't open debug file for writing subsystems for %s\n", filename)); } else { - SDL_strlcpy(model_filename, filename, sizeof(model_filename)); + SDL_strlcpy(model_filename, filename, SDL_arraysize(model_filename)); ss_warning_shown = 0; } } @@ -1500,7 +1500,7 @@ int read_model_file(polymodel * pm, const char *filename, int n_subsystems, mode if ( ( p = strstr(props, "$special"))!= NULL ) { char type[32]; - get_user_prop_value(p+9, type, sizeof(type)); + get_user_prop_value(p+9, type, SDL_arraysize(type)); if ( !SDL_strcasecmp(type, "subsystem") ) { // if we have a subsystem, put it into the list! do_new_subsystem( n_subsystems, subsystems, n, pm->submodel[n].rad, &pm->submodel[n].offset, props, pm->submodel[n].name, pm->id ); rotating_submodel_has_subsystem = true; @@ -1652,9 +1652,9 @@ int read_model_file(polymodel * pm, const char *filename, int n_subsystems, mode cfread_string_len( props, MAX_PROP_LEN, fp ); if ( (p = strstr(props, "$name"))!= NULL ) - get_user_prop_value(p+5, bay->name, sizeof(bay->name)); + get_user_prop_value(p+5, bay->name, SDL_arraysize(bay->name)); else - SDL_snprintf(bay->name, sizeof(bay->name), "", 'A' + i); + SDL_snprintf(bay->name, SDL_arraysize(bay->name), "", 'A' + i); bay->num_spline_paths = cfread_int( fp ); if ( bay->num_spline_paths > 0 ) { bay->splines = (int *)malloc(sizeof(int) * bay->num_spline_paths); @@ -1829,7 +1829,7 @@ int read_model_file(polymodel * pm, const char *filename, int n_subsystems, mode } else if ( ( p = strstr(props, "$special"))!= NULL ) { char type[32]; - get_user_prop_value(p+9, type, sizeof(type)); + get_user_prop_value(p+9, type, SDL_arraysize(type)); if ( !SDL_strcasecmp(type, "subsystem") ) // if we have a subsystem, put it into the list! do_new_subsystem( n_subsystems, subsystems, -1, radius, &pnt, props, &name[1], pm->id ); // skip the first '$' character of the name } else if ( strstr(name, "$enginelarge") || strstr(name, "$enginehuge") ){ @@ -1911,7 +1911,7 @@ int read_model_file(polymodel * pm, const char *filename, int n_subsystems, mode // get rid of leading '$' char in name if ( pm->paths[i].parent_name[0] == '$' ) { char tmpbuf[MAX_NAME_LEN]; - SDL_strlcpy(tmpbuf, pm->paths[i].parent_name+1, sizeof(tmpbuf)); + SDL_strlcpy(tmpbuf, pm->paths[i].parent_name+1, SDL_arraysize(tmpbuf)); SDL_strlcpy(pm->paths[i].parent_name, tmpbuf, MAX_NAME_LEN); } // store the sub_model index (ie index into pm->submodel) of the parent @@ -2127,8 +2127,8 @@ int model_load(const char *filename, int n_subsystems, model_subsystem *subsyste int j; char destroyed_name[128]; - SDL_strlcpy( destroyed_name, pm->submodel[i].name, sizeof(destroyed_name) ); - SDL_strlcat( destroyed_name, "-destroyed", sizeof(destroyed_name) ); + SDL_strlcpy( destroyed_name, pm->submodel[i].name, SDL_arraysize(destroyed_name) ); + SDL_strlcat( destroyed_name, "-destroyed", SDL_arraysize(destroyed_name) ); for (j=0; jn_models; j++ ) { if ( !SDL_strcasecmp( pm->submodel[j].name, destroyed_name )) { // mprintf(( "Found destroyed model for '%s'\n", pm->submodel[i].name )); @@ -2141,8 +2141,8 @@ int model_load(const char *filename, int n_subsystems, model_subsystem *subsyste // This debris comes from a destroyed subsystem when ship is still alive char live_debris_name[128]; - SDL_strlcpy( live_debris_name, "debris-", sizeof(live_debris_name) ); - SDL_strlcat( live_debris_name, pm->submodel[i].name, sizeof(live_debris_name) ); + SDL_strlcpy( live_debris_name, "debris-", SDL_arraysize(live_debris_name) ); + SDL_strlcat( live_debris_name, pm->submodel[i].name, SDL_arraysize(live_debris_name) ); pm->submodel[i].num_live_debris = 0; diff --git a/src/movie/mvelib.cpp b/src/movie/mvelib.cpp index 656b1fd..30cd6ef 100644 --- a/src/movie/mvelib.cpp +++ b/src/movie/mvelib.cpp @@ -82,7 +82,7 @@ MVEFILE *mvefile_open(const char *filename) char upper_name[MAX_FILENAME_LEN]; // upper case filename for checking - SDL_strlcpy(upper_name, filename, sizeof(upper_name)); + SDL_strlcpy(upper_name, filename, SDL_arraysize(upper_name)); SDL_strupr(upper_name); file->stream = cfopen(upper_name, "rb", CFILE_NORMAL, CF_TYPE_ANY); diff --git a/src/nebula/neb.cpp b/src/nebula/neb.cpp index 226c582..4a3c4d0 100644 --- a/src/nebula/neb.cpp +++ b/src/nebula/neb.cpp @@ -326,7 +326,7 @@ void neb2_init() stuff_string(name, F_NAME, NULL); if(Neb2_bitmap_count < MAX_NEB2_BITMAPS){ - SDL_strlcpy(Neb2_bitmap_filenames[Neb2_bitmap_count++], name, sizeof(Neb2_bitmap_filenames[0])); + SDL_strlcpy(Neb2_bitmap_filenames[Neb2_bitmap_count++], name, SDL_arraysize(Neb2_bitmap_filenames[0])); } } @@ -338,7 +338,7 @@ void neb2_init() stuff_string(name, F_NAME, NULL); if(Neb2_poof_count < MAX_NEB2_POOFS){ - SDL_strlcpy(Neb2_poof_filenames[Neb2_poof_count++], name, sizeof(Neb2_poof_filenames[0])); + SDL_strlcpy(Neb2_poof_filenames[Neb2_poof_count++], name, SDL_arraysize(Neb2_poof_filenames[0])); } } } catch (parse_error_t rval) { diff --git a/src/network/multi.cpp b/src/network/multi.cpp index 55d84f6..04d3471 100644 --- a/src/network/multi.cpp +++ b/src/network/multi.cpp @@ -1702,7 +1702,7 @@ void standalone_main_init() Net_player->flags |= (NETINFO_FLAG_AM_MASTER | NETINFO_FLAG_CONNECTED | NETINFO_FLAG_DO_NETWORKING | NETINFO_FLAG_MISSION_OK); Net_player->state = NETPLAYER_STATE_WAITING; Net_player->player = Player; - SDL_strlcpy(Player->callsign, "server", sizeof(Player->callsign)); + SDL_strlcpy(Player->callsign, "server", SDL_arraysize(Player->callsign)); Net_player->p_info.addr = Psnet_my_addr; Net_player->s_info.xfer_handle = -1; Net_player->player_id = multi_get_new_id(); diff --git a/src/network/multi_campaign.cpp b/src/network/multi_campaign.cpp index edfb27e..f6d28ff 100644 --- a/src/network/multi_campaign.cpp +++ b/src/network/multi_campaign.cpp @@ -224,7 +224,7 @@ void multi_campaign_start(char *filename) Netgame.campaign_mode = MP_CAMPAIGN; // set the campaign filename - SDL_strlcpy(Netgame.campaign_name, filename, sizeof(Netgame.campaign_name)); + SDL_strlcpy(Netgame.campaign_name, filename, SDL_arraysize(Netgame.campaign_name)); // add the campaign mode flag Game_mode |= GM_CAMPAIGN_MODE; @@ -237,14 +237,14 @@ void multi_campaign_start(char *filename) mission_campaign_next_mission(); // setup various filenames and mission names - SDL_strlcpy(Netgame.mission_name ,Campaign.missions[Campaign.current_mission].name, sizeof(Netgame.mission_name)); - SDL_strlcpy(Netgame.campaign_name, filename, sizeof(Netgame.campaign_name)); - SDL_strlcpy(Game_current_mission_filename, Netgame.mission_name, sizeof(Game_current_mission_filename)); + SDL_strlcpy(Netgame.mission_name ,Campaign.missions[Campaign.current_mission].name, SDL_arraysize(Netgame.mission_name)); + SDL_strlcpy(Netgame.campaign_name, filename, SDL_arraysize(Netgame.campaign_name)); + SDL_strlcpy(Game_current_mission_filename, Netgame.mission_name, SDL_arraysize(Game_current_mission_filename)); // if we're the standalone server, set the mission and campaign names if(Game_mode & GM_STANDALONE_SERVER){ memset(str,0,255); - SDL_snprintf(str, sizeof(str), "%s (%s)", Netgame.mission_name,Netgame.campaign_name ); + SDL_snprintf(str, SDL_arraysize(str), "%s (%s)", Netgame.mission_name,Netgame.campaign_name ); // set the control on the stand_gui std_multi_set_standalone_mission_name(str); @@ -283,13 +283,13 @@ void multi_campaign_next_mission() // now we should be sequencing through the next stage (mission load, etc) // this will eventually be replaced with the real filename of the next mission if(Campaign.current_mission != -1){ - SDL_strlcpy(Game_current_mission_filename, Campaign.missions[Campaign.current_mission].name, sizeof(Game_current_mission_filename)); - SDL_strlcpy(Netgame.mission_name, Game_current_mission_filename, sizeof(Netgame.mission_name)); + SDL_strlcpy(Game_current_mission_filename, Campaign.missions[Campaign.current_mission].name, SDL_arraysize(Game_current_mission_filename)); + SDL_strlcpy(Netgame.mission_name, Game_current_mission_filename, SDL_arraysize(Netgame.mission_name)); // if we're the standalone server, set the mission and campaign names if(Game_mode & GM_STANDALONE_SERVER){ memset(str,0,255); - SDL_snprintf(str, sizeof(str), "%s (%s)", Netgame.mission_name, Netgame.campaign_name); + SDL_snprintf(str, SDL_arraysize(str), "%s (%s)", Netgame.mission_name, Netgame.campaign_name); // set the control on the stand_gui std_multi_set_standalone_mission_name(str); diff --git a/src/network/multi_dogfight.cpp b/src/network/multi_dogfight.cpp index 8ce8df9..8c2a021 100644 --- a/src/network/multi_dogfight.cpp +++ b/src/network/multi_dogfight.cpp @@ -328,7 +328,7 @@ void multi_df_debrief_do() chatbox_render(); // draw the mission title - SDL_strlcpy(buf, The_mission.name, sizeof(buf)); + SDL_strlcpy(buf, The_mission.name, SDL_arraysize(buf)); gr_force_fit_string(buf, 255, Kill_matrix_title_coords[gr_screen.res][2]); gr_set_color_fast(&Color_bright_white); gr_string(Kill_matrix_title_coords[gr_screen.res][0], Kill_matrix_title_coords[gr_screen.res][1], buf); @@ -413,7 +413,7 @@ void multi_df_setup_kill_matrix() } s->stats = Net_players[idx].player->stats; - SDL_strlcpy(s->callsign, Net_players[idx].player->callsign, sizeof(s->callsign)); + SDL_strlcpy(s->callsign, Net_players[idx].player->callsign, SDL_arraysize(s->callsign)); s->np_index = idx; } } @@ -443,7 +443,7 @@ void multi_df_blit_kill_matrix() cy = top_y_start; for(idx=0; idx= 0); @@ -487,10 +487,10 @@ void multi_df_blit_kill_matrix() for(s_idx=0; s_idx= 0); if(Multi_df_score[idx].np_index >= 0){ gr_set_color_fast(Color_netplayer[Multi_df_score[idx].np_index]); @@ -508,7 +508,7 @@ void multi_df_blit_kill_matrix() // draw the row total gr_set_color_fast(Color_netplayer[Multi_df_score[idx].np_index]); - SDL_snprintf(squashed_string, sizeof(squashed_string), "(%d)", row_total); + SDL_snprintf(squashed_string, SDL_arraysize(squashed_string), "(%d)", row_total); gr_get_string_size(&str_len, NULL, squashed_string); gr_string(Multi_df_display_coords[gr_screen.res][0] + Multi_df_display_coords[gr_screen.res][2] - (MULTI_DF_TOTAL_ADJUST + str_len), cy, squashed_string); @@ -546,6 +546,6 @@ int multi_df_stuff_kills(char *kills, const int max_klen, int player_x, int play multi_df_score *s = &Multi_df_score[player_x]; SDL_strlcpy(kills, "", max_klen); - SDL_snprintf(kills, sizeof(max_klen), "%d", s->stats.m_dogfight_kills[Multi_df_score[player_y].np_index]); + SDL_snprintf(kills, max_klen, "%d", s->stats.m_dogfight_kills[Multi_df_score[player_y].np_index]); return s->stats.m_dogfight_kills[Multi_df_score[player_y].np_index]; } diff --git a/src/network/multi_endgame.cpp b/src/network/multi_endgame.cpp index b64d04a..1271937 100644 --- a/src/network/multi_endgame.cpp +++ b/src/network/multi_endgame.cpp @@ -606,40 +606,40 @@ void multi_endgame_popup(int notify_code,int error_code,int wsa_error) } else { // if there is a winsock error code, stick it on the end of the text if(wsa_error != -1){ - SDL_snprintf(err_msg, sizeof(err_msg), NOX("WSAERROR : %d\n\n"), wsa_error); + SDL_snprintf(err_msg, SDL_arraysize(err_msg), NOX("WSAERROR : %d\n\n"), wsa_error); flags |= PF_TITLE_RED; } else { - SDL_strlcpy(err_msg, "", sizeof(err_msg)); + SDL_strlcpy(err_msg, "", SDL_arraysize(err_msg)); } // setup the error message string if(notify_code != MULTI_END_NOTIFY_NONE){ switch(notify_code){ case MULTI_END_NOTIFY_KICKED : - SDL_strlcat(err_msg,XSTR("You have been kicked",651),sizeof(err_msg)); + SDL_strlcat(err_msg,XSTR("You have been kicked",651),SDL_arraysize(err_msg)); break; case MULTI_END_NOTIFY_SERVER_LEFT: - SDL_strlcat(err_msg,XSTR("The server has left the game",652),sizeof(err_msg)); + SDL_strlcat(err_msg,XSTR("The server has left the game",652),SDL_arraysize(err_msg)); break; case MULTI_END_NOTIFY_FILE_REJECTED: - SDL_strlcat(err_msg,XSTR("Your mission file has been rejected by the server",653),sizeof(err_msg)); + SDL_strlcat(err_msg,XSTR("Your mission file has been rejected by the server",653),SDL_arraysize(err_msg)); break; case MULTI_END_NOTIFY_EARLY_END: - SDL_strlcat(err_msg,XSTR("The game has ended while you were ingame joining",654),sizeof(err_msg)); + SDL_strlcat(err_msg,XSTR("The game has ended while you were ingame joining",654),SDL_arraysize(err_msg)); break; case MULTI_END_NOTIFY_INGAME_TIMEOUT: - SDL_strlcat(err_msg,XSTR("You have waited too long to select a ship",655),sizeof(err_msg)); + SDL_strlcat(err_msg,XSTR("You have waited too long to select a ship",655),SDL_arraysize(err_msg)); break; case MULTI_END_NOTIFY_KICKED_BAD_XFER: - SDL_strlcat(err_msg,XSTR("You were kicked because mission file xfer failed",998),sizeof(err_msg)); + SDL_strlcat(err_msg,XSTR("You were kicked because mission file xfer failed",998),SDL_arraysize(err_msg)); break; case MULTI_END_NOTIFY_KICKED_CANT_XFER: - SDL_strlcat(err_msg,XSTR("You were kicked because you do not have the builtin mission",999),sizeof(err_msg)); - SDL_strlcat(err_msg, NOX(" "), sizeof(err_msg)); - SDL_strlcat(err_msg, Game_current_mission_filename, sizeof(err_msg)); + SDL_strlcat(err_msg,XSTR("You were kicked because you do not have the builtin mission",999),SDL_arraysize(err_msg)); + SDL_strlcat(err_msg, NOX(" "), SDL_arraysize(err_msg)); + SDL_strlcat(err_msg, Game_current_mission_filename, SDL_arraysize(err_msg)); break; case MULTI_END_NOTIFY_KICKED_INGAME_ENDED: - SDL_strlcat(err_msg,XSTR("You were kicked because you were ingame joining a game that has ended",1000),sizeof(err_msg)); + SDL_strlcat(err_msg,XSTR("You were kicked because you were ingame joining a game that has ended",1000),SDL_arraysize(err_msg)); break; default : Int3(); @@ -647,43 +647,43 @@ void multi_endgame_popup(int notify_code,int error_code,int wsa_error) } else { switch(error_code){ case MULTI_END_ERROR_CONTACT_LOST : - SDL_strlcat(err_msg,XSTR("Contact with server has been lost",656),sizeof(err_msg)); + SDL_strlcat(err_msg,XSTR("Contact with server has been lost",656),SDL_arraysize(err_msg)); break; case MULTI_END_ERROR_CONNECT_FAIL : - SDL_strlcat(err_msg,XSTR("Failed to connect to server on reliable socket",657),sizeof(err_msg)); + SDL_strlcat(err_msg,XSTR("Failed to connect to server on reliable socket",657),SDL_arraysize(err_msg)); break; case MULTI_END_ERROR_LOAD_FAIL : - SDL_strlcat(err_msg,XSTR("Failed to load mission file properly",658),sizeof(err_msg)); + SDL_strlcat(err_msg,XSTR("Failed to load mission file properly",658),SDL_arraysize(err_msg)); break; case MULTI_END_ERROR_INGAME_SHIP : - SDL_strlcat(err_msg,XSTR("Unable to create ingame join player ship",659),sizeof(err_msg)); + SDL_strlcat(err_msg,XSTR("Unable to create ingame join player ship",659),SDL_arraysize(err_msg)); break; case MULTI_END_ERROR_INGAME_BOGUS : - SDL_strlcat(err_msg,XSTR("Recevied bogus packet data while ingame joining",660),sizeof(err_msg)); + SDL_strlcat(err_msg,XSTR("Recevied bogus packet data while ingame joining",660),SDL_arraysize(err_msg)); break; case MULTI_END_ERROR_STRANS_FAIL : - SDL_strlcat(err_msg,XSTR("Server transfer failed (obsolete)",661),sizeof(err_msg)); + SDL_strlcat(err_msg,XSTR("Server transfer failed (obsolete)",661),SDL_arraysize(err_msg)); break; case MULTI_END_ERROR_SHIP_ASSIGN: - SDL_strlcat(err_msg,XSTR("Server encountered errors trying to assign players to ships",662),sizeof(err_msg)); + SDL_strlcat(err_msg,XSTR("Server encountered errors trying to assign players to ships",662),SDL_arraysize(err_msg)); break; case MULTI_END_ERROR_HOST_LEFT: - SDL_strlcat(err_msg,XSTR("Host has left the game, aborting...",663),sizeof(err_msg)); + SDL_strlcat(err_msg,XSTR("Host has left the game, aborting...",663),SDL_arraysize(err_msg)); break; case MULTI_END_ERROR_XFER_FAIL: - SDL_strlcat(err_msg,XSTR("There was an error receiving the mission file!",665),sizeof(err_msg)); + SDL_strlcat(err_msg,XSTR("There was an error receiving the mission file!",665),SDL_arraysize(err_msg)); break; case MULTI_END_ERROR_WAVE_COUNT: - SDL_strlcat(err_msg,XSTR("The player wings Alpha, Beta, Gamma, and Zeta must have only 1 wave. One of these wings currently has more than 1 wave.", 987),sizeof(err_msg)); + SDL_strlcat(err_msg,XSTR("The player wings Alpha, Beta, Gamma, and Zeta must have only 1 wave. One of these wings currently has more than 1 wave.", 987),SDL_arraysize(err_msg)); break; case MULTI_END_ERROR_TEAM0_EMPTY: - SDL_strlcat(err_msg,XSTR("All players from team 1 have left the game", 1466),sizeof(err_msg)); + SDL_strlcat(err_msg,XSTR("All players from team 1 have left the game", 1466),SDL_arraysize(err_msg)); break; case MULTI_END_ERROR_TEAM1_EMPTY: - SDL_strlcat(err_msg,XSTR("All players from team 2 have left the game", 1467),sizeof(err_msg)); + SDL_strlcat(err_msg,XSTR("All players from team 2 have left the game", 1467),SDL_arraysize(err_msg)); break; case MULTI_END_ERROR_CAPTAIN_LEFT: - SDL_strlcat(err_msg,XSTR("Team captain(s) have left the game, aborting...",664),sizeof(err_msg)); + SDL_strlcat(err_msg,XSTR("Team captain(s) have left the game, aborting...",664),SDL_arraysize(err_msg)); break; default : Int3(); diff --git a/src/network/multi_ingame.cpp b/src/network/multi_ingame.cpp index 06b6323..07e17c2 100644 --- a/src/network/multi_ingame.cpp +++ b/src/network/multi_ingame.cpp @@ -593,7 +593,7 @@ void multi_ingame_sync_init() multi_oo_reset_sequencing(); // send the file signature to the host for possible mission file transfer - SDL_strlcpy(Netgame.mission_name, Game_current_mission_filename, sizeof(Netgame.mission_name)); + SDL_strlcpy(Netgame.mission_name, Game_current_mission_filename, SDL_arraysize(Netgame.mission_name)); send_file_sig_packet(Multi_current_file_checksum,Multi_current_file_length); Ingame_ships_deleted = 0; @@ -1261,7 +1261,7 @@ void multi_ingame_handle_timeout() int time_left = timestamp_until(Ingame_time_left) / 1000; char tl_string[100]; gr_set_color_fast(&Color_bright); - SDL_snprintf(tl_string,sizeof(tl_string),XSTR("Time remaining : %d s\n",682),time_left); + SDL_snprintf(tl_string,SDL_arraysize(tl_string),XSTR("Time remaining : %d s\n",682),time_left); gr_string(Multi_ingame_timer_coords[gr_screen.res][0], Multi_ingame_timer_coords[gr_screen.res][1], tl_string); } diff --git a/src/network/multi_kick.cpp b/src/network/multi_kick.cpp index c900af6..de78f51 100644 --- a/src/network/multi_kick.cpp +++ b/src/network/multi_kick.cpp @@ -214,7 +214,7 @@ void multi_kick_player(int player_index, int ban, int reason) // wait until he either shuts his connection down or he times out) // add the string to the chatbox and the hud (always safe - if it is not inited, nothing bad will happen) char str[512]; - SDL_snprintf(str, sizeof(str), XSTR("", 1501), Net_players[player_index].player->callsign); + SDL_snprintf(str, SDL_arraysize(str), XSTR("", 1501), Net_players[player_index].player->callsign); multi_display_chat_msg(str, player_index, 0); } // otherwise, we should send the packet indicating that this guy should be kicked diff --git a/src/network/multi_log.cpp b/src/network/multi_log.cpp index 5a35337..ed36d38 100644 --- a/src/network/multi_log.cpp +++ b/src/network/multi_log.cpp @@ -198,7 +198,7 @@ void ml_printf(const char *format, ...) // format the text va_start(args, format); - SDL_vsnprintf(tmp, sizeof(tmp), format, args); + SDL_vsnprintf(tmp, SDL_arraysize(tmp), format, args); va_end(args); // log the string @@ -227,12 +227,12 @@ void ml_string(const char *string, int add_time) timer = time(NULL); strftime(time_str, 128, "%m/%d %H:%M:%S~ ", localtime(&timer)); - SDL_strlcpy(tmp, time_str, sizeof(tmp)); - SDL_strlcat(tmp, string, sizeof(tmp)); + SDL_strlcpy(tmp, time_str, SDL_arraysize(tmp)); + SDL_strlcat(tmp, string, SDL_arraysize(tmp)); } else{ - SDL_strlcpy(tmp, string, sizeof(tmp)); + SDL_strlcpy(tmp, string, SDL_arraysize(tmp)); } - SDL_strlcat(tmp, "\n", sizeof(tmp)); + SDL_strlcat(tmp, "\n", SDL_arraysize(tmp)); // now print it to the logfile if necessary cfputs(tmp, Multi_log_out); diff --git a/src/network/multi_observer.cpp b/src/network/multi_observer.cpp index 8985a62..3f2db89 100644 --- a/src/network/multi_observer.cpp +++ b/src/network/multi_observer.cpp @@ -172,7 +172,7 @@ int multi_obs_create_player(int player_num,char *name,net_addr_t *addr,player *p Net_players[player_num].s_info.reliable_buffer_size = 0; // callsign and short callsign - SDL_strlcpy(pl->callsign, name, sizeof(pl->callsign)); + SDL_strlcpy(pl->callsign, name, SDL_arraysize(pl->callsign)); pilot_set_short_callsign(pl,SHORT_CALLSIGN_PIXEL_W); pl->flags |= PLAYER_FLAGS_STRUCTURE_IN_USE; @@ -227,7 +227,7 @@ void multi_obs_create_observer_client() // make ship hidden from sensors so that this observer cannot target it. Observers really have two ships // one observer, and one "Player_ship". Observer needs to ignore the Player_ship. Player_ship->flags |= SF_HIDDEN_FROM_SENSORS; - SDL_strlcpy(Player_ship->ship_name, XSTR("Observer Ship",688), sizeof(Player_ship->ship_name)); + SDL_strlcpy(Player_ship->ship_name, XSTR("Observer Ship",688), SDL_arraysize(Player_ship->ship_name)); Player_ai = &Ai_info[Ships[Objects[pobj_num].instance].ai_index]; // configure the hud to be in "observer" mode diff --git a/src/network/multi_options.cpp b/src/network/multi_options.cpp index 66d3013..6739ab8 100644 --- a/src/network/multi_options.cpp +++ b/src/network/multi_options.cpp @@ -252,13 +252,13 @@ void multi_options_read_config() Multi_options_g.log = (Cmdline_multi_log) ? 1 : 0; Multi_options_g.datarate_cap = OO_HIGH_RATE_DEFAULT; - SDL_strlcpy(Multi_options_g.user_tracker_ip, "", sizeof(Multi_options_g.user_tracker_ip)); - SDL_strlcpy(Multi_options_g.game_tracker_ip, "", sizeof(Multi_options_g.game_tracker_ip)); - SDL_strlcpy(Multi_options_g.pxo_ip, "", sizeof(Multi_options_g.pxo_ip)); - SDL_strlcpy(Multi_options_g.pxo_rank_url, "", sizeof(Multi_options_g.pxo_rank_url)); - SDL_strlcpy(Multi_options_g.pxo_create_url, "", sizeof(Multi_options_g.pxo_create_url)); - SDL_strlcpy(Multi_options_g.pxo_verify_url, "", sizeof(Multi_options_g.pxo_verify_url)); - SDL_strlcpy(Multi_options_g.pxo_banner_url, "", sizeof(Multi_options_g.pxo_banner_url)); + SDL_strlcpy(Multi_options_g.user_tracker_ip, "", SDL_arraysize(Multi_options_g.user_tracker_ip)); + SDL_strlcpy(Multi_options_g.game_tracker_ip, "", SDL_arraysize(Multi_options_g.game_tracker_ip)); + SDL_strlcpy(Multi_options_g.pxo_ip, "", SDL_arraysize(Multi_options_g.pxo_ip)); + SDL_strlcpy(Multi_options_g.pxo_rank_url, "", SDL_arraysize(Multi_options_g.pxo_rank_url)); + SDL_strlcpy(Multi_options_g.pxo_create_url, "", SDL_arraysize(Multi_options_g.pxo_create_url)); + SDL_strlcpy(Multi_options_g.pxo_verify_url, "", SDL_arraysize(Multi_options_g.pxo_verify_url)); + SDL_strlcpy(Multi_options_g.pxo_banner_url, "", SDL_arraysize(Multi_options_g.pxo_banner_url)); // standalone values Multi_options_g.std_max_players = -1; @@ -362,49 +362,49 @@ void multi_options_read_config() // ip addr of user tracker NEXT_TOKEN(); if(tok != NULL){ - SDL_strlcpy(Multi_options_g.user_tracker_ip, tok, sizeof(Multi_options_g.user_tracker_ip)); + SDL_strlcpy(Multi_options_g.user_tracker_ip, tok, SDL_arraysize(Multi_options_g.user_tracker_ip)); } } else if(SETTING("+game_server")){ // ip addr of game tracker NEXT_TOKEN(); if(tok != NULL){ - SDL_strlcpy(Multi_options_g.game_tracker_ip, tok, sizeof(Multi_options_g.game_tracker_ip)); + SDL_strlcpy(Multi_options_g.game_tracker_ip, tok, SDL_arraysize(Multi_options_g.game_tracker_ip)); } } else if(SETTING("+chat_server")){ // ip addr of pxo chat server NEXT_TOKEN(); if(tok != NULL){ - SDL_strlcpy(Multi_options_g.pxo_ip, tok, sizeof(Multi_options_g.pxo_ip)); + SDL_strlcpy(Multi_options_g.pxo_ip, tok, SDL_arraysize(Multi_options_g.pxo_ip)); } } else if(SETTING("+rank_url")){ // url of pilot rankings page NEXT_TOKEN(); if(tok != NULL){ - SDL_strlcpy(Multi_options_g.pxo_rank_url, tok, sizeof(Multi_options_g.pxo_rank_url)); + SDL_strlcpy(Multi_options_g.pxo_rank_url, tok, SDL_arraysize(Multi_options_g.pxo_rank_url)); } } else if(SETTING("+create_url")){ // url of pxo account create page NEXT_TOKEN(); if(tok != NULL){ - SDL_strlcpy(Multi_options_g.pxo_create_url, tok, sizeof(Multi_options_g.pxo_create_url)); + SDL_strlcpy(Multi_options_g.pxo_create_url, tok, SDL_arraysize(Multi_options_g.pxo_create_url)); } } else if(SETTING("+verify_url")){ // url of pxo account verify page NEXT_TOKEN(); if(tok != NULL){ - SDL_strlcpy(Multi_options_g.pxo_verify_url, tok, sizeof(Multi_options_g.pxo_verify_url)); + SDL_strlcpy(Multi_options_g.pxo_verify_url, tok, SDL_arraysize(Multi_options_g.pxo_verify_url)); } } else if(SETTING("+banner_url")){ // url of pxo account verify page NEXT_TOKEN(); if(tok != NULL){ - SDL_strlcpy(Multi_options_g.pxo_banner_url, tok, sizeof(Multi_options_g.pxo_banner_url)); + SDL_strlcpy(Multi_options_g.pxo_banner_url, tok, SDL_arraysize(Multi_options_g.pxo_banner_url)); } } else if(SETTING("+datarate")){ @@ -422,13 +422,13 @@ void multi_options_read_config() if(tok != NULL){ char *ip = strtok(tok, ":"); if(ip != NULL){ - SDL_strlcpy(Multi_options_proxy, ip, sizeof(Multi_options_proxy)); + SDL_strlcpy(Multi_options_proxy, ip, SDL_arraysize(Multi_options_proxy)); } ip = strtok(NULL, ""); if(ip != NULL){ Multi_options_proxy_port = (ushort)atoi(ip); } else { - SDL_strlcpy(Multi_options_proxy, "", sizeof(Multi_options_proxy)); + SDL_strlcpy(Multi_options_proxy, "", SDL_arraysize(Multi_options_proxy)); } } } @@ -725,14 +725,14 @@ void multi_options_process_packet(unsigned char *data, header *hinfo) Netgame.max_players = max_players; } - SDL_strlcpy(Netgame.campaign_name, ng.campaign_name, sizeof(Netgame.campaign_name)); + SDL_strlcpy(Netgame.campaign_name, ng.campaign_name, SDL_arraysize(Netgame.campaign_name)); } Netgame.campaign_mode = 1; // put brackets around the campaign name if(Game_mode & GM_STANDALONE_SERVER){ - SDL_snprintf(str, sizeof(str), "(%s)", Netgame.campaign_name); + SDL_snprintf(str, SDL_arraysize(str), "(%s)", Netgame.campaign_name); std_multi_set_standalone_mission_name(str); } } @@ -747,8 +747,8 @@ void multi_options_process_packet(unsigned char *data, header *hinfo) // setting this to -1 will prevent us from being seen on the network Netgame.max_players = -1; } - SDL_strlcpy(Netgame.mission_name, ng.mission_name, sizeof(Netgame.mission_name)); - SDL_strlcpy(Game_current_mission_filename, Netgame.mission_name, sizeof(Game_current_mission_filename)); + SDL_strlcpy(Netgame.mission_name, ng.mission_name, SDL_arraysize(Netgame.mission_name)); + SDL_strlcpy(Game_current_mission_filename, Netgame.mission_name, SDL_arraysize(Game_current_mission_filename)); } Netgame.campaign_mode = 0; diff --git a/src/network/multi_pause.cpp b/src/network/multi_pause.cpp index 33d06a0..deabf27 100644 --- a/src/network/multi_pause.cpp +++ b/src/network/multi_pause.cpp @@ -551,7 +551,7 @@ void multi_pause_render_callsign() // write out the callsign of the player who paused the game if((Multi_pause_pauser != NULL) && (Multi_pause_pauser->player != NULL)){ memset(pause_str,0,100); - SDL_strlcpy(pause_str, Multi_pause_pauser->player->callsign, sizeof(pause_str)); + SDL_strlcpy(pause_str, Multi_pause_pauser->player->callsign, SDL_arraysize(pause_str)); // blit it gr_set_color_fast(&Color_bright); diff --git a/src/network/multi_pinfo.cpp b/src/network/multi_pinfo.cpp index b8b4b4b..58517a5 100644 --- a/src/network/multi_pinfo.cpp +++ b/src/network/multi_pinfo.cpp @@ -422,9 +422,9 @@ void multi_pinfo_popup_init(net_player *np) // zero bitmap info Mp_pilot.bitmap = -1; - SDL_strlcpy(Mp_pilot.filename, "", sizeof(Mp_pilot.filename)); + SDL_strlcpy(Mp_pilot.filename, "", SDL_arraysize(Mp_pilot.filename)); Mp_squad.bitmap = -1; - SDL_strlcpy(Mp_squad.filename, "", sizeof(Mp_squad.filename)); + SDL_strlcpy(Mp_squad.filename, "", SDL_arraysize(Mp_squad.filename)); // set the player status multi_pinfo_reset_player(np); @@ -583,19 +583,19 @@ void multi_pinfo_blit_pilot_image() // if there is no image if(strlen(Mp_pilot.filename) <= 0){ - SDL_strlcpy(place_text, XSTR("No/Invalid Image", 1053), sizeof(place_text)); + SDL_strlcpy(place_text, XSTR("No/Invalid Image", 1053), SDL_arraysize(place_text)); } // if the image is xferring else if(multi_xfer_lookup(Mp_pilot.filename)){ - SDL_strlcpy(place_text, XSTR("Image Transferring", 691), sizeof(place_text)); + SDL_strlcpy(place_text, XSTR("Image Transferring", 691), SDL_arraysize(place_text)); } // if we're not accepting images else if(!(Net_player->p_info.options.flags & MLO_FLAG_ACCEPT_PIX) || !(Netgame.options.flags & MSO_FLAG_ACCEPT_PIX)){ - SDL_strlcpy(place_text, XSTR("No Image", 692), sizeof(place_text)); + SDL_strlcpy(place_text, XSTR("No Image", 692), SDL_arraysize(place_text)); } // otherwise we wait else { - SDL_strlcpy(place_text, XSTR("Waiting", 690), sizeof(place_text)); + SDL_strlcpy(place_text, XSTR("Waiting", 690), SDL_arraysize(place_text)); } // center the text @@ -630,19 +630,19 @@ void multi_pinfo_blit_squadron_logo() // if there is no image if(strlen(p->squad_filename) <= 0){ - SDL_strlcpy(place_text, XSTR("No/Invalid Image", 1053), sizeof(place_text)); + SDL_strlcpy(place_text, XSTR("No/Invalid Image", 1053), SDL_arraysize(place_text)); } // if the image is xferring else if(multi_xfer_lookup(p->squad_filename)){ - SDL_strlcpy(place_text, XSTR("Image Transferring", 691), sizeof(place_text)); + SDL_strlcpy(place_text, XSTR("Image Transferring", 691), SDL_arraysize(place_text)); } // if we're not accepting images else if(!(Net_player->p_info.options.flags & MLO_FLAG_ACCEPT_PIX) || !(Netgame.options.flags & MSO_FLAG_ACCEPT_PIX)){ - SDL_strlcpy(place_text, XSTR("No Image", 692), sizeof(place_text)); + SDL_strlcpy(place_text, XSTR("No Image", 692), SDL_arraysize(place_text)); } // otherwise we wait else { - SDL_strlcpy(place_text, XSTR("Waiting", 690), sizeof(place_text)); + SDL_strlcpy(place_text, XSTR("Waiting", 690), SDL_arraysize(place_text)); } // center the text @@ -915,12 +915,12 @@ void multi_pinfo_reset_player(net_player *np) Multi_pinfo_popup_player = np; // unload any old image data if necessary - SDL_strlcpy(Mp_pilot.filename, "", sizeof(Mp_pilot.filename)); + SDL_strlcpy(Mp_pilot.filename, "", SDL_arraysize(Mp_pilot.filename)); if(Mp_pilot.bitmap != -1){ bm_release(Mp_pilot.bitmap); Mp_pilot.bitmap = -1; } - SDL_strlcpy(Mp_squad.filename, "", sizeof(Mp_squad.filename)); + SDL_strlcpy(Mp_squad.filename, "", SDL_arraysize(Mp_squad.filename)); if(Mp_squad.bitmap != -1){ bm_release(Mp_squad.bitmap); Mp_squad.bitmap = -1; @@ -928,11 +928,11 @@ void multi_pinfo_reset_player(net_player *np) // try and load pilot pic/squad logo if(strlen(np->player->image_filename) > 0){ - SDL_strlcpy(Mp_pilot.filename, np->player->image_filename, sizeof(Mp_pilot.filename)); + SDL_strlcpy(Mp_pilot.filename, np->player->image_filename, SDL_arraysize(Mp_pilot.filename)); Mp_pilot.bitmap = bm_load_duplicate(Mp_pilot.filename); } if(strlen(np->player->squad_filename) > 0){ - SDL_strlcpy(Mp_squad.filename, np->player->squad_filename, sizeof(Mp_squad.filename)); + SDL_strlcpy(Mp_squad.filename, np->player->squad_filename, SDL_arraysize(Mp_squad.filename)); Mp_squad.bitmap = bm_load_duplicate(Mp_squad.filename); } diff --git a/src/network/multi_pmsg.cpp b/src/network/multi_pmsg.cpp index a84287c..dee1b6f 100644 --- a/src/network/multi_pmsg.cpp +++ b/src/network/multi_pmsg.cpp @@ -376,7 +376,7 @@ int multi_msg_text_process(int k) str[0] = (char)key_text; str[1] = '\0'; - SDL_strlcat(Multi_msg_text, str, sizeof(Multi_msg_text)); + SDL_strlcat(Multi_msg_text, str, SDL_arraysize(Multi_msg_text)); } break; } @@ -510,7 +510,7 @@ int multi_msg_check_command(char *str) } // store the text as the actual parameter - SDL_strlcpy(param, predicate, sizeof(param)); + SDL_strlcpy(param, predicate, SDL_arraysize(param)); drop_leading_white_space(param); // go through all existing commands and see what we can do @@ -526,7 +526,7 @@ int multi_msg_check_command(char *str) // apply the results as a general expression, if we're in message all mode if(Multi_msg_mode == MULTI_MSG_ALL){ - SDL_strlcpy(Multi_msg_text, param, sizeof(Multi_msg_text)); + SDL_strlcpy(Multi_msg_text, param, SDL_arraysize(Multi_msg_text)); // send the chat packet send_game_chat_packet(Net_player, Multi_msg_text, MULTI_MSG_EXPR,NULL, prefix); @@ -593,7 +593,7 @@ void multi_msg_show_squadmsg(net_player *source,int command,ushort target_sig,in memset(temp_string,0,100); // add the message header - SDL_snprintf(hud_string,sizeof(hud_string),XSTR("ORDER FROM <%s> : ",699),source->player->callsign); + SDL_snprintf(hud_string,SDL_arraysize(hud_string),XSTR("ORDER FROM <%s> : ",699),source->player->callsign); // get the target obj if possible target_obj = NULL; @@ -606,8 +606,8 @@ void multi_msg_show_squadmsg(net_player *source,int command,ushort target_sig,in // attack my target case ATTACK_TARGET_ITEM : if((target_obj != NULL) && (target_obj->type == OBJ_SHIP)){ - SDL_snprintf(temp_string,sizeof(temp_string),XSTR("Attack %s",700),Ships[target_obj->instance].ship_name); - SDL_strlcat(hud_string, temp_string, sizeof(hud_string)); + SDL_snprintf(temp_string,SDL_arraysize(temp_string),XSTR("Attack %s",700),Ships[target_obj->instance].ship_name); + SDL_strlcat(hud_string, temp_string, SDL_arraysize(hud_string)); } else { should_display = 0; } @@ -616,8 +616,8 @@ void multi_msg_show_squadmsg(net_player *source,int command,ushort target_sig,in // disable my target case DISABLE_TARGET_ITEM: if((target_obj != NULL) && (target_obj->type == OBJ_SHIP)){ - SDL_snprintf(temp_string,sizeof(temp_string),XSTR("Disable %s",701),Ships[target_obj->instance].ship_name); - SDL_strlcat(hud_string, temp_string, sizeof(hud_string)); + SDL_snprintf(temp_string,SDL_arraysize(temp_string),XSTR("Disable %s",701),Ships[target_obj->instance].ship_name); + SDL_strlcat(hud_string, temp_string, SDL_arraysize(hud_string)); } else { should_display = 0; } @@ -626,8 +626,8 @@ void multi_msg_show_squadmsg(net_player *source,int command,ushort target_sig,in // protect my target case PROTECT_TARGET_ITEM: if((target_obj != NULL) && (target_obj->type == OBJ_SHIP)){ - SDL_snprintf(temp_string,sizeof(temp_string),XSTR("Protect %s",702),Ships[target_obj->instance].ship_name); - SDL_strlcat(hud_string, temp_string, sizeof(hud_string)); + SDL_snprintf(temp_string,SDL_arraysize(temp_string),XSTR("Protect %s",702),Ships[target_obj->instance].ship_name); + SDL_strlcat(hud_string, temp_string, SDL_arraysize(hud_string)); } else { should_display = 0; } @@ -636,8 +636,8 @@ void multi_msg_show_squadmsg(net_player *source,int command,ushort target_sig,in // ignore my target case IGNORE_TARGET_ITEM: if((target_obj != NULL) && (target_obj->type == OBJ_SHIP)){ - SDL_snprintf(temp_string,sizeof(temp_string),XSTR("Ignore %s",703),Ships[target_obj->instance].ship_name); - SDL_strlcat(hud_string, temp_string, sizeof(hud_string)); + SDL_snprintf(temp_string,SDL_arraysize(temp_string),XSTR("Ignore %s",703),Ships[target_obj->instance].ship_name); + SDL_strlcat(hud_string, temp_string, SDL_arraysize(hud_string)); } else { should_display = 0; } @@ -646,8 +646,8 @@ void multi_msg_show_squadmsg(net_player *source,int command,ushort target_sig,in // disarm my target case DISARM_TARGET_ITEM: if((target_obj != NULL) && (target_obj->type == OBJ_SHIP)){ - SDL_snprintf(temp_string,sizeof(temp_string),XSTR("Disarm %s",704),Ships[target_obj->instance].ship_name); - SDL_strlcat(hud_string, temp_string, sizeof(hud_string)); + SDL_snprintf(temp_string,SDL_arraysize(temp_string),XSTR("Disarm %s",704),Ships[target_obj->instance].ship_name); + SDL_strlcat(hud_string, temp_string, SDL_arraysize(hud_string)); } else { should_display = 0; } @@ -656,8 +656,8 @@ void multi_msg_show_squadmsg(net_player *source,int command,ushort target_sig,in // disable subsystem on my target case DISABLE_SUBSYSTEM_ITEM: if((target_obj != NULL) && (target_obj->type == OBJ_SHIP) && (subsys_type != -1) && (subsys_type != 0)){ - SDL_snprintf(temp_string,sizeof(temp_string),XSTR("Disable subsystem %s on %s",705),Multi_msg_subsys_name[subsys_type],Ships[target_obj->instance].ship_name); - SDL_strlcat(hud_string, temp_string, sizeof(hud_string)); + SDL_snprintf(temp_string,SDL_arraysize(temp_string),XSTR("Disable subsystem %s on %s",705),Multi_msg_subsys_name[subsys_type],Ships[target_obj->instance].ship_name); + SDL_strlcat(hud_string, temp_string, SDL_arraysize(hud_string)); } else { should_display = 0; } @@ -665,17 +665,17 @@ void multi_msg_show_squadmsg(net_player *source,int command,ushort target_sig,in // form on my wing case FORMATION_ITEM: - SDL_strlcat(hud_string, XSTR("Form on my wing",706), sizeof(hud_string)); + SDL_strlcat(hud_string, XSTR("Form on my wing",706), SDL_arraysize(hud_string)); break; // cover me case COVER_ME_ITEM: - SDL_strlcat(hud_string, XSTR("Cover me",707), sizeof(hud_string)); + SDL_strlcat(hud_string, XSTR("Cover me",707), SDL_arraysize(hud_string)); break; // engage enemy case ENGAGE_ENEMY_ITEM: - SDL_strlcat(hud_string, XSTR("Engage enemy!",708), sizeof(hud_string)); + SDL_strlcat(hud_string, XSTR("Engage enemy!",708), SDL_arraysize(hud_string)); break; default : diff --git a/src/network/multi_rate.cpp b/src/network/multi_rate.cpp index 75a0c1b..7aa6420 100644 --- a/src/network/multi_rate.cpp +++ b/src/network/multi_rate.cpp @@ -152,7 +152,7 @@ int multi_rate_add(int np_index, const char *type, int size) m = &Multi_rate[np_index][idx]; // type string - SDL_strlcpy(m->type, type, sizeof(m->type)); + SDL_strlcpy(m->type, type, SDL_arraysize(m->type)); // alltime m->total_bytes += size; diff --git a/src/network/multi_respawn.cpp b/src/network/multi_respawn.cpp index 5c2fe9a..41d064d 100644 --- a/src/network/multi_respawn.cpp +++ b/src/network/multi_respawn.cpp @@ -402,7 +402,7 @@ void multi_respawn_build_points() if((Ships[Objects[moveup->objnum].instance].respawn_priority > 0) && (Multi_respawn_priority_count < MAX_PRIORITY_POINTS)){ r = &Multi_respawn_priority_ships[Multi_respawn_priority_count++]; - SDL_strlcpy(r->ship_name, Ships[Objects[moveup->objnum].instance].ship_name, sizeof(r->ship_name)); + SDL_strlcpy(r->ship_name, Ships[Objects[moveup->objnum].instance].ship_name, SDL_arraysize(r->ship_name)); r->team = Ships[Objects[moveup->objnum].instance].team; } moveup = GET_NEXT(moveup); diff --git a/src/network/multi_team.cpp b/src/network/multi_team.cpp index 92db707..fd96c6a 100644 --- a/src/network/multi_team.cpp +++ b/src/network/multi_team.cpp @@ -741,9 +741,9 @@ void multi_team_report() SEND_AND_DISPLAY("----****"); // display scores - SDL_snprintf(report, sizeof(report), XSTR("", 1275), Multi_team0_score); + SDL_snprintf(report, SDL_arraysize(report), XSTR("", 1275), Multi_team0_score); SEND_AND_DISPLAY(report); - SDL_snprintf(report, sizeof(report), XSTR("", 1276), Multi_team1_score); + SDL_snprintf(report, SDL_arraysize(report), XSTR("", 1276), Multi_team1_score); SEND_AND_DISPLAY(report); // display winner diff --git a/src/network/multi_update.cpp b/src/network/multi_update.cpp index e601878..c9b5707 100644 --- a/src/network/multi_update.cpp +++ b/src/network/multi_update.cpp @@ -151,16 +151,16 @@ int multi_update_http_init() char local_file[512] = ""; // url - SDL_strlcpy(url_file, VERSION_URL, sizeof(url_file)); + SDL_strlcpy(url_file, VERSION_URL, SDL_arraysize(url_file)); // local file - SDL_snprintf(local_file, sizeof(local_file), "%s%s%s", Cfile_root_dir, DIR_SEPARATOR_STR, VERSION_LOC_FNAME); + SDL_snprintf(local_file, SDL_arraysize(local_file), "%s%s%s", Cfile_root_dir, DIR_SEPARATOR_STR, VERSION_LOC_FNAME); // new file Multi_update_get = new InetGetFile(url_file, local_file); if(Multi_update_get == NULL){ // error string - SDL_strlcpy(Multi_update_error_string, XSTR("Could not get data from website", 977), sizeof(Multi_update_error_string)); + SDL_strlcpy(Multi_update_error_string, XSTR("Could not get data from website", 977), SDL_arraysize(Multi_update_error_string)); return 0; } @@ -174,7 +174,7 @@ int multi_update_http_do() // sanity if(Multi_update_get == NULL){ // error string - SDL_strlcpy(Multi_update_error_string, XSTR("Could not get data from website", 977), sizeof(Multi_update_error_string)); + SDL_strlcpy(Multi_update_error_string, XSTR("Could not get data from website", 977), SDL_arraysize(Multi_update_error_string)); return 2; } @@ -185,7 +185,7 @@ int multi_update_http_do() Multi_update_get = NULL; // error string - SDL_strlcpy(Multi_update_error_string, XSTR("Could not get data from website", 977), sizeof(Multi_update_error_string)); + SDL_strlcpy(Multi_update_error_string, XSTR("Could not get data from website", 977), SDL_arraysize(Multi_update_error_string)); return 2; } @@ -216,7 +216,7 @@ int multi_update_error_verifying() char out_str[512]; memset(out_str, 0, 512); - SDL_snprintf(out_str, sizeof(out_str), "(%s)\n\n%s", Multi_update_error_string, + SDL_snprintf(out_str, SDL_arraysize(out_str), "(%s)\n\n%s", Multi_update_error_string, XSTR("There was an error verifying your version of Freespace, if you continue, you will not necessarily be up to date", 978)); switch(popup(PF_USE_AFFIRMATIVE_ICON | PF_USE_NEGATIVE_ICON, 2, XSTR("&Go back", 1524), XSTR("&Continue", 1525), out_str)){ @@ -257,9 +257,9 @@ int multi_update_gobaby() extern char Multi_options_proxy[512]; extern ushort Multi_options_proxy_port; if(strlen(Multi_options_proxy) > 0){ - SDL_snprintf(msg, sizeof(msg), "%s (%s : %d)", XSTR("Verifying Freespace Version",981), Multi_options_proxy, Multi_options_proxy_port); + SDL_snprintf(msg, SDL_arraysize(msg), "%s (%s : %d)", XSTR("Verifying Freespace Version",981), Multi_options_proxy, Multi_options_proxy_port); } else { - SDL_strlcpy(msg, XSTR("Verifying Freespace Version",981), sizeof(msg)); + SDL_strlcpy(msg, XSTR("Verifying Freespace Version",981), SDL_arraysize(msg)); } ret_code = popup_till_condition(multi_update_http_do, XSTR("Cancel",948), msg); diff --git a/src/network/multi_voice.cpp b/src/network/multi_voice.cpp index e03110a..0bd563e 100644 --- a/src/network/multi_voice.cpp +++ b/src/network/multi_voice.cpp @@ -2145,7 +2145,7 @@ void multi_voice_alg_play_window(int stream_index) int player_index = find_player_id(Multi_voice_stream[stream_index].stream_from); if(player_index != -1){ - SDL_snprintf(voice_msg, sizeof(voice_msg), XSTR("<%s is speaking>", 712), Net_players[player_index].player->callsign); + SDL_snprintf(voice_msg, SDL_arraysize(voice_msg), XSTR("<%s is speaking>", 712), Net_players[player_index].player->callsign); // display a chat message (write to the correct spot - hud, standalone gui, chatbox, etc) multi_display_chat_msg(voice_msg,player_index,0); diff --git a/src/network/multi_xfer.cpp b/src/network/multi_xfer.cpp index d3261fa..0b594e4 100644 --- a/src/network/multi_xfer.cpp +++ b/src/network/multi_xfer.cpp @@ -416,7 +416,7 @@ int multi_xfer_send_file(PSNET_SOCKET_RELIABLE who, char *filename, int cfile_fl memset(&temp_entry,0,sizeof(xfer_entry)); // set the filename - SDL_strlcpy(temp_entry.filename, filename, sizeof(temp_entry.filename)); + SDL_strlcpy(temp_entry.filename, filename, SDL_arraysize(temp_entry.filename)); // attempt to open the file temp_entry.file = NULL; @@ -1128,11 +1128,11 @@ void multi_xfer_process_header(ubyte *data, PSNET_SOCKET_RELIABLE who, ushort si xe->sig = sig; // copy the filename and get the prefixed xfer filename - SDL_strlcpy(xe->filename, filename, sizeof(xe->filename)); + SDL_strlcpy(xe->filename, filename, SDL_arraysize(xe->filename)); // lower case all filenames to avoid case issues SDL_strlwr(xe->filename); - multi_xfer_conv_prefix(xe->filename, xe->ex_filename, sizeof(xe->ex_filename)); + multi_xfer_conv_prefix(xe->filename, xe->ex_filename, SDL_arraysize(xe->ex_filename)); #ifdef MULTI_XFER_VERBOSE nprintf(("Network","MULTI XFER : converted filename %s to %s\n",xe->filename, xe->ex_filename)); #endif @@ -1345,10 +1345,10 @@ void multi_xfer_conv_prefix(char *filename, char *ex_filename, const int max_len memset(temp, 0, MAX_FILENAME_LEN+50); // copy in the prefix - SDL_strlcpy(temp, MULTI_XFER_FNAME_PREFIX, sizeof(temp)); + SDL_strlcpy(temp, MULTI_XFER_FNAME_PREFIX, SDL_arraysize(temp)); // stick on the original name - SDL_strlcat(temp, filename, sizeof(temp)); + SDL_strlcat(temp, filename, SDL_arraysize(temp)); // copy the whole thing to the outgoing filename SDL_strlcpy(ex_filename, temp, max_len); diff --git a/src/network/multimsgs.cpp b/src/network/multimsgs.cpp index 440616b..3cae1e4 100644 --- a/src/network/multimsgs.cpp +++ b/src/network/multimsgs.cpp @@ -1250,7 +1250,7 @@ void process_join_packet(ubyte* data, header* hinfo) // } // } else if(Netgame.mode == NG_MODE_RESTRICTED){ host_restr_mode = MULTI_JOIN_RESTR_MODE_1; - SDL_snprintf(join_string,sizeof(join_string),XSTR("Player %s has tried to join, accept y/n ?",715),jr.callsign); + SDL_snprintf(join_string,SDL_arraysize(join_string),XSTR("Player %s has tried to join, accept y/n ?",715),jr.callsign); // } SDL_assert(host_restr_mode != -1); @@ -1395,7 +1395,7 @@ void process_new_player_packet(ubyte* data, header* hinfo) // add a chat message if(Net_players[new_player_num].player->callsign != NULL){ - SDL_snprintf(notify_string,sizeof(notify_string),XSTR("<%s has joined>",717),Net_players[new_player_num].player->callsign); + SDL_snprintf(notify_string,SDL_arraysize(notify_string),XSTR("<%s has joined>",717),Net_players[new_player_num].player->callsign); multi_display_chat_msg(notify_string,0,0); } } @@ -1569,7 +1569,7 @@ void send_accept_packet(int new_player_num, int code, int ingame_join_team) // add a chat message if(Net_players[new_player_num].player->callsign != NULL){ - SDL_snprintf(notify_string,sizeof(notify_string),XSTR("<%s has joined>",717), Net_players[new_player_num].player->callsign); + SDL_snprintf(notify_string,SDL_arraysize(notify_string),XSTR("<%s has joined>",717), Net_players[new_player_num].player->callsign); multi_display_chat_msg(notify_string, 0, 0); } @@ -1958,7 +1958,7 @@ void process_leave_game_packet(ubyte* data, header* hinfo) // display the result memset(str, 0, 512); - multi_kick_get_text(&Net_players[player_num], kicked_reason, str, sizeof(str)); + multi_kick_get_text(&Net_players[player_num], kicked_reason, str, SDL_arraysize(str)); multi_display_chat_msg(str, player_num, 0); } } @@ -1967,7 +1967,7 @@ void process_leave_game_packet(ubyte* data, header* hinfo) if (Net_player->flags & NETINFO_FLAG_AM_MASTER) { char msg[255]; - SDL_snprintf(msg, sizeof(msg), XSTR("%s has left the game",719), Net_players[player_num].player->callsign ); + SDL_snprintf(msg, SDL_arraysize(msg), XSTR("%s has left the game",719), Net_players[player_num].player->callsign ); if (!(Game_mode & GM_STANDALONE_SERVER)){ HUD_sourced_printf(HUD_SOURCE_HIDDEN, msg); @@ -4468,7 +4468,7 @@ void process_file_sig_request(ubyte *data, header *hinfo) PACKET_SET_SIZE(); // set the current mission filename - SDL_strlcpy(Game_current_mission_filename, Netgame.mission_name, sizeof(Game_current_mission_filename)); + SDL_strlcpy(Game_current_mission_filename, Netgame.mission_name, SDL_arraysize(Game_current_mission_filename)); // get the checksum multi_get_mission_checksum(Game_current_mission_filename); @@ -4643,8 +4643,8 @@ void process_netplayer_load_packet(ubyte *data, header *hinfo) GET_STRING(str); PACKET_SET_SIZE(); - SDL_strlcpy(Netgame.mission_name, str, sizeof(Netgame.mission_name)); - SDL_strlcpy(Game_current_mission_filename, str, sizeof(Game_current_mission_filename)); + SDL_strlcpy(Netgame.mission_name, str, SDL_arraysize(Netgame.mission_name)); + SDL_strlcpy(Game_current_mission_filename, str, SDL_arraysize(Game_current_mission_filename)); if(!Multi_mission_loaded){ // MWA 2/3/98 -- ingame join changes!!! @@ -5136,7 +5136,7 @@ void process_mission_sync_packet(ubyte *data, header *hinfo) // get the single mission filename GET_STRING(Game_current_mission_filename); - SDL_strlcpy(Netgame.mission_name, Game_current_mission_filename, sizeof(Netgame.mission_name)); + SDL_strlcpy(Netgame.mission_name, Game_current_mission_filename, SDL_arraysize(Netgame.mission_name)); } } PACKET_SET_SIZE(); diff --git a/src/network/multiteamselect.cpp b/src/network/multiteamselect.cpp index 9d228c0..ca5fc7e 100644 --- a/src/network/multiteamselect.cpp +++ b/src/network/multiteamselect.cpp @@ -1030,14 +1030,14 @@ void multi_ts_assign_players_all() if(Netgame.type_flags & NG_TYPE_TEAM){ switch(Netgame.host->p_info.team){ case 0 : - SDL_strlcpy(name_lookup, NOX("alpha 1"), sizeof(name_lookup)); + SDL_strlcpy(name_lookup, NOX("alpha 1"), SDL_arraysize(name_lookup)); break; case 1 : - SDL_strlcpy(name_lookup, NOX("zeta 1"), sizeof(name_lookup)); + SDL_strlcpy(name_lookup, NOX("zeta 1"), SDL_arraysize(name_lookup)); break; } } else { - SDL_strlcpy(name_lookup, NOX("alpha 1"), sizeof(name_lookup)); + SDL_strlcpy(name_lookup, NOX("alpha 1"), SDL_arraysize(name_lookup)); } shipnum = ship_name_lookup(name_lookup); @@ -1463,16 +1463,16 @@ void multi_ts_blit_wing_callsigns() // if there is a player in the slot if(Multi_ts_team[Net_player->p_info.team].multi_ts_player[idx] != NULL){ // make sure the string fits - SDL_strlcpy(callsign, Multi_ts_team[Net_player->p_info.team].multi_ts_player[idx]->player->callsign, sizeof(callsign)); + SDL_strlcpy(callsign, Multi_ts_team[Net_player->p_info.team].multi_ts_player[idx]->player->callsign, SDL_arraysize(callsign)); } else { // determine if this is a locked AI ship pobj = mission_parse_get_arrival_ship(Ships[Objects[Multi_ts_team[Net_player->p_info.team].multi_ts_objnum[idx]].instance].ship_name); if((pobj == NULL) || !(pobj->flags & OF_PLAYER_SHIP)){ - SDL_strlcpy(callsign, NOX("<"), sizeof(callsign)); - SDL_strlcat(callsign, XSTR("AI", 738), sizeof(callsign)); // [[ Artificial Intellegence ]] - SDL_strlcat(callsign, NOX(">"), sizeof(callsign)); + SDL_strlcpy(callsign, NOX("<"), SDL_arraysize(callsign)); + SDL_strlcat(callsign, XSTR("AI", 738), SDL_arraysize(callsign)); // [[ Artificial Intellegence ]] + SDL_strlcat(callsign, NOX(">"), SDL_arraysize(callsign)); } else { - SDL_strlcpy(callsign, XSTR("AI", 738), sizeof(callsign)); // [[ Artificial Intellegence ]] + SDL_strlcpy(callsign, XSTR("AI", 738), SDL_arraysize(callsign)); // [[ Artificial Intellegence ]] } } @@ -1510,7 +1510,7 @@ void multi_ts_blit_avail_ships() ss_blit_ship_icon(Multi_ts_avail_coords[display_count][gr_screen.res][MULTI_TS_X_COORD],Multi_ts_avail_coords[display_count][gr_screen.res][MULTI_TS_Y_COORD],idx,multi_ts_avail_bmap_num(display_count)); // blit the ship count available - SDL_snprintf(count,sizeof(count),"%d",Ss_pool[idx]); + SDL_snprintf(count,SDL_arraysize(count),"%d",Ss_pool[idx]); gr_set_color_fast(&Color_normal); gr_string(Multi_ts_avail_coords[display_count][gr_screen.res][MULTI_TS_X_COORD] - 20,Multi_ts_avail_coords[display_count][gr_screen.res][MULTI_TS_Y_COORD],count); @@ -1730,7 +1730,7 @@ void multi_ts_blit_ship_info() // blit the max velocity gr_set_color_fast(&Color_normal); gr_string(Multi_ts_ship_info_coords[gr_screen.res][MULTI_TS_X_COORD], y_start,XSTR("Max Velocity",742)); - SDL_snprintf(str,sizeof(str),XSTR("%d m/s",743),(int)sip->max_vel.xyz.z); + SDL_snprintf(str,SDL_arraysize(str),XSTR("%d m/s",743),(int)sip->max_vel.xyz.z); gr_set_color_fast(&Color_bright); gr_string(Multi_ts_ship_info_coords[gr_screen.res][MULTI_TS_X_COORD] + 150, y_start,str); y_start += 10; @@ -1802,11 +1802,11 @@ void multi_ts_blit_status_bar() // mode specific text switch(Multi_ts_status_bar_mode){ case 0 : - SDL_strlcpy(text, XSTR("Ships/Weapons Locked", 749), sizeof(text)); + SDL_strlcpy(text, XSTR("Ships/Weapons Locked", 749), SDL_arraysize(text)); blit = 1; break; case 1 : - SDL_strlcpy(text, XSTR("Ships/Weapons Are Now Free", 750), sizeof(text)); + SDL_strlcpy(text, XSTR("Ships/Weapons Are Now Free", 750), SDL_arraysize(text)); blit = 1; break; } @@ -2630,7 +2630,7 @@ void multi_ts_blit_carried_icon() break; case MULTI_TS_PLAYER_LIST: // get the final length of the string so we can calculate a valid offset - SDL_strlcpy(callsign, Multi_ts_team[Net_player->p_info.team].multi_ts_player[Multi_ts_carried_from_index]->player->callsign, sizeof(callsign)); + SDL_strlcpy(callsign, Multi_ts_team[Net_player->p_info.team].multi_ts_player[Multi_ts_carried_from_index]->player->callsign, SDL_arraysize(callsign)); gr_force_fit_string(callsign,CALLSIGN_LEN,Multi_ts_slot_text_coords[Multi_ts_carried_from_index][gr_screen.res][MULTI_TS_W_COORD]); gr_get_string_size(&callsign_w,NULL,callsign); diff --git a/src/network/multiui.cpp b/src/network/multiui.cpp index e3c1846..626ceaf 100644 --- a/src/network/multiui.cpp +++ b/src/network/multiui.cpp @@ -619,7 +619,7 @@ void multi_common_set_text(const char *str, int auto_scroll) if(strlen(str) > MULTI_COMMON_MAX_TEXT){ return ; } else { - SDL_strlcpy(Multi_common_all_text, str, sizeof(Multi_common_all_text)); + SDL_strlcpy(Multi_common_all_text, str, SDL_arraysize(Multi_common_all_text)); } // split the whole thing up @@ -638,7 +638,7 @@ void multi_common_add_text(const char *str, int auto_scroll) if((strlen(str) + strlen(Multi_common_all_text)) > MULTI_COMMON_MAX_TEXT){ return ; } else { - SDL_strlcat(Multi_common_all_text, str, sizeof(Multi_common_all_text)); + SDL_strlcat(Multi_common_all_text, str, SDL_arraysize(Multi_common_all_text)); } // split the whole thing up @@ -719,7 +719,7 @@ int Multi_common_notify_stamp; void multi_common_notify_init() { - SDL_strlcpy(Multi_common_notify_text, "", sizeof(Multi_common_notify_text)); + SDL_strlcpy(Multi_common_notify_text, "", SDL_arraysize(Multi_common_notify_text)); Multi_common_notify_stamp = -1; } @@ -727,7 +727,7 @@ void multi_common_notify_init() void multi_common_add_notify(const char *str) { if(str){ - SDL_strlcpy(Multi_common_notify_text, str, sizeof(Multi_common_notify_text)); + SDL_strlcpy(Multi_common_notify_text, str, SDL_arraysize(Multi_common_notify_text)); Multi_common_notify_stamp = timestamp(MULTI_COMMON_NOTIFY_TIME); } } @@ -1235,7 +1235,7 @@ DCF(mj_make, "") for(idx=0; idxflags & AG_FLAG_STANDALONE){ - SDL_strlcat(str, MJ_CHAR_STANDALONE, sizeof(str)); + SDL_strlcat(str, MJ_CHAR_STANDALONE, SDL_arraysize(str)); } if(moveup->flags & AG_FLAG_CAMPAIGN){ - SDL_strlcat(str, MJ_CHAR_CAMPAIGN, sizeof(str)); + SDL_strlcat(str, MJ_CHAR_CAMPAIGN, SDL_arraysize(str)); } // tack on the actual server name - SDL_strlcat(str, " ", sizeof(str)); - SDL_strlcat(str, moveup->name, sizeof(str)); + SDL_strlcat(str, " ", SDL_arraysize(str)); + SDL_strlcat(str, moveup->name, SDL_arraysize(str)); if(strlen(moveup->mission_name) > 0){ - SDL_strlcat(str, " / ", sizeof(str)); - SDL_strlcat(str, moveup->mission_name, sizeof(str)); + SDL_strlcat(str, " / ", SDL_arraysize(str)); + SDL_strlcat(str, moveup->mission_name, SDL_arraysize(str)); } // make sure the string fits in the display area and draw it @@ -1824,7 +1824,7 @@ void multi_join_display_games() if(moveup->ping.ping_avg > 0){ if(moveup->ping.ping_avg > 1000){ gr_set_color_fast(&Color_bright_red); - SDL_strlcpy(str, XSTR("> 1 sec",761), sizeof(str)); + SDL_strlcpy(str, XSTR("> 1 sec",761), SDL_arraysize(str)); } else { // set the appropriate ping time color indicator if(moveup->ping.ping_avg > MJ_PING_YELLOW){ @@ -1835,7 +1835,7 @@ void multi_join_display_games() gr_set_color_fast(&Color_bright_green); } - SDL_snprintf(str, sizeof(str), "%d%s", moveup->ping.ping_avg, XSTR(" ms",762)); + SDL_snprintf(str, SDL_arraysize(str), "%d%s", moveup->ping.ping_avg, XSTR(" ms",762)); } gr_string(Mj_ping_coords[gr_screen.res][MJ_X_COORD],y_start,str); @@ -1847,7 +1847,7 @@ void multi_join_display_games() } else { gr_set_color_fast(&Color_text_normal); } - SDL_snprintf(str, sizeof(str), "%d", moveup->num_players); + SDL_snprintf(str, SDL_arraysize(str), "%d", moveup->num_players); gr_get_string_size(&w,&h,str); gr_string(Mj_players_coords[gr_screen.res][MJ_X_COORD] + (Mj_players_coords[gr_screen.res][MJ_W_COORD] - w)/2,y_start,str); @@ -1908,27 +1908,27 @@ void multi_join_blit_game_status(active_game *game, int y) switch( game->flags & AG_FLAG_STATE_MASK ){ case AG_FLAG_FORMING: gr_set_color_fast(&Color_bright_green); - SDL_strlcpy(status_text, XSTR("Forming", 764), sizeof(status_text)); + SDL_strlcpy(status_text, XSTR("Forming", 764), SDL_arraysize(status_text)); break; case AG_FLAG_BRIEFING: gr_set_color_fast(&Color_bright_red); - SDL_strlcpy(status_text, XSTR("Briefing", 765), sizeof(status_text)); + SDL_strlcpy(status_text, XSTR("Briefing", 765), SDL_arraysize(status_text)); break; case AG_FLAG_DEBRIEF: gr_set_color_fast(&Color_bright_red); - SDL_strlcpy(status_text, XSTR("Debrief", 766), sizeof(status_text)); + SDL_strlcpy(status_text, XSTR("Debrief", 766), SDL_arraysize(status_text)); break; case AG_FLAG_PAUSE: gr_set_color_fast(&Color_bright_red); - SDL_strlcpy(status_text, XSTR("Paused", 767), sizeof(status_text)); + SDL_strlcpy(status_text, XSTR("Paused", 767), SDL_arraysize(status_text)); break; case AG_FLAG_IN_MISSION: gr_set_color_fast(&Color_bright_red); - SDL_strlcpy(status_text, XSTR("Playing", 768), sizeof(status_text)); + SDL_strlcpy(status_text, XSTR("Playing", 768), SDL_arraysize(status_text)); break; default: gr_set_color_fast(&Color_bright); - SDL_strlcpy(status_text, XSTR("Unknown", 769), sizeof(status_text)); + SDL_strlcpy(status_text, XSTR("Unknown", 769), SDL_arraysize(status_text)); break; } gr_get_string_size(&str_w,NULL,status_text); @@ -1974,7 +1974,7 @@ void multi_join_load_tcp_addrs() // copy the server ip address memset(&addr,0,sizeof(net_addr)); addr.type = NET_TCP; - psnet_string_to_addr(&addr, line, sizeof(line)); + psnet_string_to_addr(&addr, line, SDL_arraysize(line)); if ( addr.port == 0 ){ addr.port = DEFAULT_GAME_PORT; } @@ -2380,7 +2380,7 @@ void multi_join_send_join_request(int as_observer) // if the netgame is in password mode, put up a request for the password if(Multi_join_selected_item->flags & AG_FLAG_PASSWD){ - if(!multi_passwd_popup(Multi_join_request.passwd, sizeof(Multi_join_request.passwd))){ + if(!multi_passwd_popup(Multi_join_request.passwd, SDL_arraysize(Multi_join_request.passwd))){ return; } @@ -2388,13 +2388,13 @@ void multi_join_send_join_request(int as_observer) } // fill out the join request struct - SDL_strlcpy(Multi_join_request.callsign, Player->callsign, sizeof(Multi_join_request.callsign)); + SDL_strlcpy(Multi_join_request.callsign, Player->callsign, SDL_arraysize(Multi_join_request.callsign)); if(strlen(Player->image_filename) > 0){ - SDL_strlcpy(Multi_join_request.image_filename, Player->image_filename, sizeof(Multi_join_request.image_filename)); + SDL_strlcpy(Multi_join_request.image_filename, Player->image_filename, SDL_arraysize(Multi_join_request.image_filename)); } #ifndef MAKE_FS1 if(strlen(Player->squad_filename) > 0){ - SDL_strlcpy(Multi_join_request.squad_filename, Player->squad_filename, sizeof(Multi_join_request.squad_filename)); + SDL_strlcpy(Multi_join_request.squad_filename, Player->squad_filename, SDL_arraysize(Multi_join_request.squad_filename)); } #endif @@ -2915,7 +2915,7 @@ void multi_start_game_init() // if starting a netgame, set the name of the game and any other options that are appropriate if ( Cmdline_start_netgame ) { if ( Cmdline_game_name != NULL ) { - SDL_strlcpy( Multi_sg_netgame->name, Cmdline_game_name, sizeof(Multi_sg_netgame->name) ); + SDL_strlcpy( Multi_sg_netgame->name, Cmdline_game_name, SDL_arraysize(Multi_sg_netgame->name) ); Multi_sg_game_name.set_text(Multi_sg_netgame->name); } @@ -2927,7 +2927,7 @@ void multi_start_game_init() Multi_sg_netgame->mode = NG_MODE_RESTRICTED; } else if ( Cmdline_game_password != NULL ) { Multi_sg_netgame->mode = NG_MODE_PASSWORD; - SDL_strlcpy(Multi_sg_netgame->passwd, Cmdline_game_password, sizeof(Multi_sg_netgame->passwd)); + SDL_strlcpy(Multi_sg_netgame->passwd, Cmdline_game_password, SDL_arraysize(Multi_sg_netgame->passwd)); Multi_sg_game_passwd.set_text(Multi_sg_netgame->passwd); } @@ -3289,12 +3289,12 @@ void multi_sg_init_gamenet() // setup the default game name, taking care of string length and player callsigns memset(out_name,0,128); memset(buf,0,128); - pilot_format_callsign_personal(Player->callsign, out_name, sizeof(out_name)); - SDL_snprintf(buf, sizeof(buf), XSTR("%s game",782), out_name); // [[ %s will be a pilot's name ]] + pilot_format_callsign_personal(Player->callsign, out_name, SDL_arraysize(out_name)); + SDL_snprintf(buf, SDL_arraysize(buf), XSTR("%s game",782), out_name); // [[ %s will be a pilot's name ]] if ( strlen(buf) > MAX_GAMENAME_LEN ){ - SDL_strlcpy(buf, XSTR("Temporary name",783), sizeof(buf)); + SDL_strlcpy(buf, XSTR("Temporary name",783), SDL_arraysize(buf)); } - SDL_strlcpy(Multi_sg_netgame->name, buf, sizeof(Multi_sg_netgame->name)); + SDL_strlcpy(Multi_sg_netgame->name, buf, SDL_arraysize(Multi_sg_netgame->name)); // set the default qos and duration multi_voice_maybe_update_vars(Netgame.options.voice_qos,Netgame.options.voice_record_time); @@ -3478,7 +3478,7 @@ void multi_sg_rank_process_select() gamesnd_play_iface(SND_GENERAL_FAIL); memset(string,0,255); - SDL_snprintf(string,sizeof(string),XSTR("Illegal value for a host of your rank (%s)\n",784),Ranks[Net_player->player->stats.rank].name); + SDL_snprintf(string,SDL_arraysize(string),XSTR("Illegal value for a host of your rank (%s)\n",784),Ranks[Net_player->player->stats.rank].name); multi_common_add_notify(string); } } @@ -3490,7 +3490,7 @@ void multi_sg_rank_build_name(char *in, char *out, const int max_outlen) char use[100]; char *first; - SDL_strlcpy(use, in, sizeof(use)); + SDL_strlcpy(use, in, SDL_arraysize(use)); first = strtok(use," "); // just copy the string @@ -4772,9 +4772,9 @@ void multi_create_plist_blit_normal() } // make sure the string will fit, then display it - SDL_strlcpy(str, Net_players[idx].player->callsign, sizeof(str)); + SDL_strlcpy(str, Net_players[idx].player->callsign, SDL_arraysize(str)); if(Net_players[idx].flags & NETINFO_FLAG_OBSERVER){ - SDL_strlcat(str, XSTR("(O)",787), sizeof(str)); // [[ Observer ]] + SDL_strlcat(str, XSTR("(O)",787), SDL_arraysize(str)); // [[ Observer ]] } gr_force_fit_string(str,CALLSIGN_LEN,Mc_players_coords[gr_screen.res][MC_W_COORD] - total_offset); gr_string(Mc_players_coords[gr_screen.res][MC_X_COORD] + total_offset,y_start,str); @@ -4845,9 +4845,9 @@ void multi_create_plist_blit_team() } // make sure the string will fit - SDL_strlcpy(str, Net_players[idx].player->callsign, sizeof(str)); + SDL_strlcpy(str, Net_players[idx].player->callsign, SDL_arraysize(str)); if(Net_players[idx].flags & NETINFO_FLAG_OBSERVER){ - SDL_strlcat(str, XSTR("(O)",787), sizeof(str)); + SDL_strlcat(str, XSTR("(O)",787), SDL_arraysize(str)); } gr_force_fit_string(str,CALLSIGN_LEN,Mc_players_coords[gr_screen.res][MC_W_COORD] - total_offset); @@ -4911,9 +4911,9 @@ void multi_create_plist_blit_team() } // make sure the string will fit - SDL_strlcpy(str, Net_players[idx].player->callsign, sizeof(str)); + SDL_strlcpy(str, Net_players[idx].player->callsign, SDL_arraysize(str)); if(Net_players[idx].flags & NETINFO_FLAG_OBSERVER){ - SDL_strlcat(str, XSTR("(O)",787), sizeof(str)); + SDL_strlcat(str, XSTR("(O)",787), SDL_arraysize(str)); } gr_force_fit_string(str,CALLSIGN_LEN,Mc_players_coords[gr_screen.res][MC_W_COORD] - total_offset); @@ -4953,7 +4953,7 @@ void multi_create_list_load_missions() char wild_card[6]; int file_count,idx; - SDL_snprintf(wild_card, sizeof(wild_card), "*%s", FS_MISSION_FILE_EXT); + SDL_snprintf(wild_card, SDL_arraysize(wild_card), "*%s", FS_MISSION_FILE_EXT); file_count = cf_get_file_list_preallocated(MULTI_CREATE_MAX_LIST_ITEMS, Multi_create_files_array, NULL, CF_TYPE_MISSIONS, wild_card); Multi_create_mission_count = 0; @@ -4999,8 +4999,8 @@ void multi_create_list_load_missions() multi_create_info *mcip; mcip = &Multi_create_mission_list[Multi_create_mission_count]; - SDL_strlcpy(mcip->filename, filename, sizeof(mcip->filename)); - SDL_strlcpy(mcip->name, mission_name, sizeof(mcip->name)); + SDL_strlcpy(mcip->filename, filename, SDL_arraysize(mcip->filename)); + SDL_strlcpy(mcip->name, mission_name, SDL_arraysize(mcip->name)); mcip->flags = flags; mcip->respawn = m_respawn; mcip->max_players = (ubyte)max_players; @@ -5040,7 +5040,7 @@ void multi_create_list_load_campaigns() } Multi_create_campaign_count = 0; - SDL_snprintf(wild_card, sizeof(wild_card), "*%s", FS_CAMPAIGN_FILE_EXT); + SDL_snprintf(wild_card, SDL_arraysize(wild_card), "*%s", FS_CAMPAIGN_FILE_EXT); file_count = cf_get_file_list_preallocated(MULTI_CREATE_MAX_LIST_ITEMS, Multi_create_files_array, NULL, CF_TYPE_MISSIONS, wild_card); for(idx = 0; idx < file_count; idx++){ int flags; @@ -5067,14 +5067,14 @@ void multi_create_list_load_campaigns() } // if the campaign is a multiplayer campaign, then add the data to the campaign list items - flags = mission_campaign_parse_is_multi( filename, name, sizeof(name) ); + flags = mission_campaign_parse_is_multi( filename, name, SDL_arraysize(name) ); if( flags != CAMPAIGN_TYPE_SINGLE && mission_campaign_get_info(filename,title,&campaign_type,&max_players)) { if ( Multi_create_campaign_count < MULTI_CREATE_MAX_LIST_ITEMS ) { multi_create_info *mcip; mcip = &Multi_create_campaign_list[Multi_create_campaign_count]; - SDL_strlcpy(mcip->filename, filename, sizeof(mcip->filename)); - SDL_strlcpy(mcip->name, name, sizeof(mcip->name)); + SDL_strlcpy(mcip->filename, filename, SDL_arraysize(mcip->filename)); + SDL_strlcpy(mcip->name, name, SDL_arraysize(mcip->name)); // setup various flags if ( flags == CAMPAIGN_TYPE_MULTI_COOP ){ @@ -5158,7 +5158,7 @@ void multi_create_list_do() } // highlight the selected item - multi_create_select_to_filename(Multi_create_list_select, selected_name, sizeof(selected_name)); + multi_create_select_to_filename(Multi_create_list_select, selected_name, SDL_arraysize(selected_name)); if(!strcmp(selected_name,Multi_create_file_list[idx].filename)){ gr_set_color_fast(&Color_text_selected); } else { @@ -5169,16 +5169,16 @@ void multi_create_list_do() multi_create_list_blit_icons(idx, y_start); // force fit the mission name string - SDL_strlcpy(selected_name, Multi_create_file_list[idx].name, sizeof(selected_name)); + SDL_strlcpy(selected_name, Multi_create_file_list[idx].name, SDL_arraysize(selected_name)); gr_force_fit_string(selected_name,255,Mc_column1_w[gr_screen.res]); gr_string(Mc_mission_name_x[gr_screen.res],y_start,selected_name); // draw the max players if in mission mode - SDL_snprintf(selected_name,sizeof(selected_name),"%d",(int)Multi_create_file_list[idx].max_players); + SDL_snprintf(selected_name,SDL_arraysize(selected_name),"%d",(int)Multi_create_file_list[idx].max_players); gr_string(Mc_mission_count_x[gr_screen.res],y_start,selected_name); // force fit the mission filename string - SDL_strlcpy(selected_name, Multi_create_file_list[idx].filename, sizeof(selected_name)); + SDL_strlcpy(selected_name, Multi_create_file_list[idx].filename, SDL_arraysize(selected_name)); gr_force_fit_string(selected_name,255,Mc_column3_w[gr_screen.res]); gr_string(Mc_mission_fname_x[gr_screen.res],y_start,selected_name); @@ -5218,9 +5218,9 @@ void multi_create_list_select_item(int n) // set the mission name if(Multi_create_list_mode == MULTI_CREATE_SHOW_MISSIONS){ - multi_create_select_to_filename(n, ng->mission_name, sizeof(ng->mission_name)); + multi_create_select_to_filename(n, ng->mission_name, SDL_arraysize(ng->mission_name)); } else { - multi_create_select_to_filename(n, ng->campaign_name, sizeof(ng->campaign_name)); + multi_create_select_to_filename(n, ng->campaign_name, SDL_arraysize(ng->campaign_name)); } // make sure the netgame type is properly set @@ -5259,7 +5259,7 @@ void multi_create_list_select_item(int n) ng->max_players = mission_parse_get_multi_mission_info( ng->mission_name ); SDL_assert(ng->max_players > 0); - SDL_strlcpy(ng->title, The_mission.name, sizeof(ng->title)); + SDL_strlcpy(ng->title, The_mission.name, SDL_arraysize(ng->title)); // set the information area text multi_common_set_text(The_mission.mission_desc); @@ -5291,7 +5291,7 @@ void multi_create_list_select_item(int n) // if we successfully got the # of players else { memset(ng->title,0,NAME_LENGTH+1); - SDL_strlcpy(ng->title, title, sizeof(ng->title)); + SDL_strlcpy(ng->title, title, SDL_arraysize(ng->title)); ng->max_players = max_players; } @@ -5406,7 +5406,7 @@ void multi_create_accept_hit() Netgame.campaign_mode = MP_SINGLE; // setup various filenames and mission names - multi_create_select_to_filename(Multi_create_list_select, selected_name, sizeof(selected_name)); + multi_create_select_to_filename(Multi_create_list_select, selected_name, SDL_arraysize(selected_name)); SDL_strlcpy( Game_current_mission_filename, selected_name, MAX_FILENAME_LEN ); SDL_strlcpy( Netgame.mission_name, selected_name, MAX_FILENAME_LEN ); @@ -5425,7 +5425,7 @@ void multi_create_accept_hit() Netgame.campaign_mode = MP_CAMPAIGN; // start a campaign instead of a single mission - multi_create_select_to_filename(Multi_create_list_select, selected_name, sizeof(selected_name)); + multi_create_select_to_filename(Multi_create_list_select, selected_name, SDL_arraysize(selected_name)); multi_campaign_start(selected_name); start_campaign = 1; @@ -5692,9 +5692,9 @@ int multi_create_ok_to_commit() // message everyone - haha if(Net_players[idx].player != NULL){ - SDL_snprintf(err_string, sizeof(err_string), "%s %s", Net_players[idx].player->callsign, XSTR("has hacked tables/data", 1271)); + SDL_snprintf(err_string, SDL_arraysize(err_string), "%s %s", Net_players[idx].player->callsign, XSTR("has hacked tables/data", 1271)); } else { - SDL_snprintf(err_string, sizeof(err_string), "somebody %s", XSTR("has hacked tables/data", 1271)); + SDL_snprintf(err_string, SDL_arraysize(err_string), "somebody %s", XSTR("has hacked tables/data", 1271)); } send_game_chat_packet(Net_player, err_string, MULTI_MSG_ALL, NULL, NULL, 1); } @@ -5732,7 +5732,7 @@ int multi_create_ok_to_commit() observer_count = multi_num_observers(); if(observer_count > Netgame.options.max_observers){ // print up the error string - SDL_snprintf(err_string,sizeof(err_string),XSTR("There are too many observers in the game\n\nMax : %d\nCurrently %d\n\nPlease dump a few",791),Netgame.options.max_observers,observer_count); + SDL_snprintf(err_string,SDL_arraysize(err_string),XSTR("There are too many observers in the game\n\nMax : %d\nCurrently %d\n\nPlease dump a few",791),Netgame.options.max_observers,observer_count); popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, err_string); return 0; @@ -5742,7 +5742,7 @@ int multi_create_ok_to_commit() player_count = multi_num_players(); if(player_count > Netgame.max_players){ // print up the error string - SDL_snprintf(err_string,sizeof(err_string),XSTR("There are too many players in the game\n\nMax : %d\nCurrently %d\n\nPlease dump a few", 792), Netgame.max_players,player_count); + SDL_snprintf(err_string,SDL_arraysize(err_string),XSTR("There are too many players in the game\n\nMax : %d\nCurrently %d\n\nPlease dump a few", 792), Netgame.max_players,player_count); popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, err_string); return 0; @@ -6822,30 +6822,30 @@ void multi_ho_get_options() // get the # of observers memset(resp_str,0,10); - SDL_snprintf(resp_str,sizeof(resp_str),"%d",Netgame.options.max_observers); + SDL_snprintf(resp_str,SDL_arraysize(resp_str),"%d",Netgame.options.max_observers); Multi_ho_obs.set_text(resp_str); // set the respawn count if(Netgame.campaign_mode == MP_SINGLE){ memset(resp_str,0,10); - SDL_snprintf(resp_str,sizeof(resp_str),"%d",Netgame.respawn); + SDL_snprintf(resp_str,SDL_arraysize(resp_str),"%d",Netgame.respawn); Multi_ho_respawns.set_text(resp_str); } // set the mission time limit memset(resp_str,0,10); float tl = f2fl(Netgame.options.mission_time_limit); - SDL_snprintf(resp_str,sizeof(resp_str),"%d",(int)(tl / 60.0f)); + SDL_snprintf(resp_str,SDL_arraysize(resp_str),"%d",(int)(tl / 60.0f)); Multi_ho_time_limit.set_text(resp_str); // set the furball kill limit memset(resp_str,0,10); - SDL_snprintf(resp_str,sizeof(resp_str),"%d",Netgame.options.kill_limit); + SDL_snprintf(resp_str,SDL_arraysize(resp_str),"%d",Netgame.options.kill_limit); Multi_ho_kill_limit.set_text(resp_str); // set the token wait time memset(resp_str,0,10); - SDL_snprintf(resp_str,sizeof(resp_str),"%d",Netgame.options.voice_token_wait / 1000); + SDL_snprintf(resp_str,SDL_arraysize(resp_str),"%d",Netgame.options.voice_token_wait / 1000); Multi_ho_voice_wait.set_text(resp_str); // get whether we're in host/captains only modify mode @@ -6881,7 +6881,7 @@ void multi_ho_display_record_time() half_seconds = ((((Multi_ho_sliders[gr_screen.res][MULTI_HO_SLIDER_VOICE_DUR].slider.pos + 1) * 500) % 1000) / 500) * 5; // format the string - SDL_snprintf(time_str,sizeof(time_str),"%d.%d",full_seconds,half_seconds); + SDL_snprintf(time_str,SDL_arraysize(time_str),"%d.%d",full_seconds,half_seconds); gr_set_color_fast(&Color_bright); gr_string(Ho_vd_coords[gr_screen.res][MULTI_HO_X_COORD],Ho_vd_coords[gr_screen.res][MULTI_HO_Y_COORD],time_str); } @@ -6898,7 +6898,7 @@ int multi_ho_check_values() // if the value is invalid, let the user know if(atoi(val_txt) > Multi_ho_mission_respawn){ memset(val_txt,0,255); - SDL_snprintf(val_txt,sizeof(val_txt),XSTR("Warning\nRespawn count in greater than mission specified max (%d)",796),Multi_ho_mission_respawn); + SDL_snprintf(val_txt,SDL_arraysize(val_txt),XSTR("Warning\nRespawn count in greater than mission specified max (%d)",796),Multi_ho_mission_respawn); popup(PF_USE_AFFIRMATIVE_ICON | PF_TITLE_RED | PF_TITLE_BIG,1,POPUP_OK,val_txt); return 0; } @@ -6909,7 +6909,7 @@ int multi_ho_check_values() // if the value is invalid, force it to be valid if(atoi(val_txt) > MULTI_HO_MAX_TIME_LIMIT){ memset(val_txt,0,255); - SDL_snprintf(val_txt,sizeof(val_txt),XSTR("Warning\nMission time limit is greater than max allowed (%d)",797),MULTI_HO_MAX_TIME_LIMIT); + SDL_snprintf(val_txt,SDL_arraysize(val_txt),XSTR("Warning\nMission time limit is greater than max allowed (%d)",797),MULTI_HO_MAX_TIME_LIMIT); popup(PF_USE_AFFIRMATIVE_ICON | PF_TITLE_RED | PF_TITLE_BIG,1,POPUP_OK,val_txt); return 0; } @@ -6919,7 +6919,7 @@ int multi_ho_check_values() // if the value is invalid, force it to be valid if(atoi(val_txt) > MULTI_HO_MAX_OBS){ memset(val_txt,0,255); - SDL_snprintf(val_txt,sizeof(val_txt),XSTR("Warning\nObserver count is greater than max allowed (%d)",798),MULTI_HO_MAX_OBS); + SDL_snprintf(val_txt,SDL_arraysize(val_txt),XSTR("Warning\nObserver count is greater than max allowed (%d)",798),MULTI_HO_MAX_OBS); popup(PF_USE_AFFIRMATIVE_ICON | PF_TITLE_RED | PF_TITLE_BIG,1,POPUP_OK,val_txt); return 0; } @@ -6929,7 +6929,7 @@ int multi_ho_check_values() // if the value is invalid, force it to be valid if(atoi(val_txt) > MULTI_HO_MAX_KILL_LIMIT){ memset(val_txt,0,255); - SDL_snprintf(val_txt,sizeof(val_txt),XSTR("Warning\nMission kill limit is greater than max allowed (%d)",799),MULTI_HO_MAX_KILL_LIMIT); + SDL_snprintf(val_txt,SDL_arraysize(val_txt),XSTR("Warning\nMission kill limit is greater than max allowed (%d)",799),MULTI_HO_MAX_KILL_LIMIT); popup(PF_USE_AFFIRMATIVE_ICON | PF_TITLE_RED | PF_TITLE_BIG,1,POPUP_OK,val_txt); return 0; } @@ -6938,7 +6938,7 @@ int multi_ho_check_values() Multi_ho_voice_wait.get_text(val_txt); if(atoi(val_txt) > MULTI_HO_MAX_TOKEN_WAIT){ memset(val_txt,0,255); - SDL_snprintf(val_txt,sizeof(val_txt),XSTR("Warning\nvoice wait time is greater than max allowed (%d)",800),MULTI_HO_MAX_TOKEN_WAIT); + SDL_snprintf(val_txt,SDL_arraysize(val_txt),XSTR("Warning\nvoice wait time is greater than max allowed (%d)",800),MULTI_HO_MAX_TOKEN_WAIT); popup(PF_USE_AFFIRMATIVE_ICON | PF_TITLE_RED | PF_TITLE_BIG,1,POPUP_OK,val_txt); return 0; } @@ -6996,7 +6996,7 @@ void multi_ho_blit_max_respawns() } // otherwise blit the max as specified by the current mission file - SDL_snprintf(string,sizeof(string),"(%d)",Multi_ho_mission_respawn); + SDL_snprintf(string,SDL_arraysize(string),"(%d)",Multi_ho_mission_respawn); gr_set_color_fast(&Color_normal); gr_string(Ho_max_rsp_coords[gr_screen.res][MULTI_HO_X_COORD], Ho_max_rsp_coords[gr_screen.res][MULTI_HO_Y_COORD], string); } @@ -7334,11 +7334,11 @@ void multi_game_client_setup_do_frame() // blit the mission filename if possible if(Netgame.campaign_mode){ if(strlen(Netgame.campaign_name) > 0){ - SDL_strlcpy(mission_text, Netgame.campaign_name, sizeof(mission_text)); + SDL_strlcpy(mission_text, Netgame.campaign_name, SDL_arraysize(mission_text)); if(strlen(Netgame.title) > 0){ - SDL_strlcat(mission_text, ", ", sizeof(mission_text)); - SDL_strlcat(mission_text, Netgame.title, sizeof(mission_text)); + SDL_strlcat(mission_text, ", ", SDL_arraysize(mission_text)); + SDL_strlcat(mission_text, Netgame.title, SDL_arraysize(mission_text)); } gr_set_color_fast(&Color_bright_white); @@ -7346,11 +7346,11 @@ void multi_game_client_setup_do_frame() } } else { if(strlen(Netgame.mission_name) > 0){ - SDL_strlcpy(mission_text, Netgame.mission_name, sizeof(mission_text)); + SDL_strlcpy(mission_text, Netgame.mission_name, SDL_arraysize(mission_text)); if(strlen(Netgame.title) > 0){ - SDL_strlcat(mission_text, ", ", sizeof(mission_text)); - SDL_strlcat(mission_text, Netgame.title, sizeof(mission_text)); + SDL_strlcat(mission_text, ", ", SDL_arraysize(mission_text)); + SDL_strlcat(mission_text, Netgame.title, SDL_arraysize(mission_text)); } gr_set_color_fast(&Color_bright_white); @@ -7550,9 +7550,9 @@ void multi_jw_plist_blit_normal() } // make sure the string will fit, then display it - SDL_strlcpy(str, Net_players[idx].player->callsign, sizeof(str)); + SDL_strlcpy(str, Net_players[idx].player->callsign, SDL_arraysize(str)); if(Net_players[idx].flags & NETINFO_FLAG_OBSERVER){ - SDL_strlcat(str, "(0)", sizeof(str)); + SDL_strlcat(str, "(0)", SDL_arraysize(str)); } gr_force_fit_string(str,CALLSIGN_LEN,Mjw_players_coords[gr_screen.res][MJW_W_COORD] - total_offset); gr_string(Mjw_players_coords[gr_screen.res][MJW_X_COORD] + total_offset,y_start,str); @@ -7624,7 +7624,7 @@ void multi_jw_plist_blit_team() } // make sure the string will fit - SDL_strlcpy(str, Net_players[idx].player->callsign, sizeof(str)); + SDL_strlcpy(str, Net_players[idx].player->callsign, SDL_arraysize(str)); gr_force_fit_string(str,CALLSIGN_LEN,Mjw_players_coords[gr_screen.res][MJW_W_COORD] - total_offset); // display him in the correct half of the list depending on his team @@ -7681,9 +7681,9 @@ void multi_jw_plist_blit_team() } // make sure the string will fit - SDL_strlcpy(str, Net_players[idx].player->callsign, sizeof(str)); + SDL_strlcpy(str, Net_players[idx].player->callsign, SDL_arraysize(str)); if(Net_players[idx].flags & NETINFO_FLAG_OBSERVER){ - SDL_strlcat(str, "(0)", sizeof(str)); + SDL_strlcat(str, "(0)", SDL_arraysize(str)); } gr_force_fit_string(str,CALLSIGN_LEN,Mjw_players_coords[gr_screen.res][MJW_W_COORD] - total_offset); @@ -8307,14 +8307,14 @@ void multi_sync_blit_screen_all() // if we've got a valid xfer handle if((pct_complete >= 0.0) && (pct_complete <= 1.0)){ - SDL_snprintf(txt,sizeof(txt),XSTR("Mission file xfer %d%%",828),(int)(pct_complete * 100.0f)); + SDL_snprintf(txt,SDL_arraysize(txt),XSTR("Mission file xfer %d%%",828),(int)(pct_complete * 100.0f)); } // otherwise else { - SDL_strlcpy(txt, XSTR("Mission file xfer", 829), sizeof(txt)); + SDL_strlcpy(txt, XSTR("Mission file xfer", 829), SDL_arraysize(txt)); } } else { - SDL_strlcpy(txt, XSTR("Mission file xfer", 829), sizeof(txt)); + SDL_strlcpy(txt, XSTR("Mission file xfer", 829), SDL_arraysize(txt)); } } // clients should display only for themselves (which is the only thing they know) @@ -8325,16 +8325,16 @@ void multi_sync_blit_screen_all() // if we've got a valid xfer handle if((pct_complete >= 0.0) && (pct_complete <= 1.0)){ - SDL_snprintf(txt,sizeof(txt),XSTR("Mission file xfer %d%%",828),(int)(pct_complete * 100.0f)); + SDL_snprintf(txt,SDL_arraysize(txt),XSTR("Mission file xfer %d%%",828),(int)(pct_complete * 100.0f)); } // otherwise else { - SDL_strlcpy(txt, XSTR("Mission file xfer", 829), sizeof(txt)); + SDL_strlcpy(txt, XSTR("Mission file xfer", 829), SDL_arraysize(txt)); } } // otherwise else { - SDL_strlcpy(txt, XSTR("Mission file xfer", 829), sizeof(txt)); + SDL_strlcpy(txt, XSTR("Mission file xfer", 829), SDL_arraysize(txt)); } } @@ -8912,7 +8912,7 @@ void multi_sync_display_name(const char *name, int index, int np_index) char fit[CALLSIGN_LEN]; // make sure the string actually fits - SDL_strlcpy(fit, name, sizeof(fit)); + SDL_strlcpy(fit, name, SDL_arraysize(fit)); // if we're in team vs. team mode if(Netgame.type_flags & NG_TYPE_TEAM){ @@ -8989,7 +8989,7 @@ void multi_sync_display_status(const char *status, int index) char fit[250]; // make sure the string actually fits - SDL_strlcpy(fit, status, sizeof(fit)); + SDL_strlcpy(fit, status, SDL_arraysize(fit)); gr_force_fit_string(fit, 250, Ms_status2_coords[gr_screen.res][MS_W_COORD] - 20); gr_set_color_fast(&Color_bright); gr_string(Ms_status2_coords[gr_screen.res][MS_X_COORD], Ms_status2_coords[gr_screen.res][MS_Y_COORD] + (index * 10), fit); @@ -9271,7 +9271,7 @@ void multi_maybe_set_mission_loop() if ( (Campaign.missions[cur].has_mission_loop && (Campaign.loop_mission != -1)) && !require_repeat_mission ) { char buffer[512]; - debrief_assemble_optional_mission_popup_text(buffer, sizeof(buffer), Campaign.missions[cur].mission_loop_desc); + debrief_assemble_optional_mission_popup_text(buffer, SDL_arraysize(buffer), Campaign.missions[cur].mission_loop_desc); int choice = popup(0 , 2, POPUP_NO, POPUP_YES, buffer); if (choice == 1) { diff --git a/src/network/multiutil.cpp b/src/network/multiutil.cpp index 728bdc1..800c72f 100644 --- a/src/network/multiutil.cpp +++ b/src/network/multiutil.cpp @@ -969,7 +969,7 @@ int multi_create_player( int net_player_num, player *pl, char* name, net_addr_t* Net_players[net_player_num].s_info.reliable_buffer_size = 0; // various ack handles - SDL_strlcpy(pl->callsign, name, sizeof(pl->callsign)); + SDL_strlcpy(pl->callsign, name, SDL_arraysize(pl->callsign)); pilot_set_short_callsign(pl, SHORT_CALLSIGN_PIXEL_W); // calculate the short callsign pl->flags |= PLAYER_FLAGS_STRUCTURE_IN_USE; pl->objnum = -1; @@ -1090,7 +1090,7 @@ void delete_player(int player_num,int kicked_reason) if(Net_players[player_num].flags & NETINFO_FLAG_KICKED){ char str[512]; memset(str, 0, 512); - multi_kick_get_text(&Net_players[player_num], Net_players[player_num].s_info.kick_reason, str, sizeof(str)); + multi_kick_get_text(&Net_players[player_num], Net_players[player_num].s_info.kick_reason, str, SDL_arraysize(str)); multi_display_chat_msg(str, player_num, 0); } else { send_leave_game_packet(Net_players[player_num].player_id, kicked_reason); @@ -1138,7 +1138,7 @@ void delete_player(int player_num,int kicked_reason) // display a message that this guy has left if(Net_players[player_num].player->callsign){ - SDL_snprintf(notify_string,sizeof(notify_string),XSTR("<%s has left>",901),Net_players[player_num].player->callsign); + SDL_snprintf(notify_string,SDL_arraysize(notify_string),XSTR("<%s has left>",901),Net_players[player_num].player->callsign); multi_display_chat_msg(notify_string,0,0); } @@ -1501,7 +1501,7 @@ int multi_is_builtin_mission() // get the full filename memset(name,0,512); - SDL_strlcpy(name, Game_current_mission_filename, sizeof(name)); + SDL_strlcpy(name, Game_current_mission_filename, SDL_arraysize(name)); cf_add_ext(name, FS_MISSION_FILE_EXT); // if this mission is builtin @@ -1805,7 +1805,7 @@ void multi_create_standalone_object() // make ship hidden from sensors so that this observer cannot target it. Observers really have two ships // one observer, and one "Player_ship". Observer needs to ignore the Player_ship. Player_ship->flags |= SF_HIDDEN_FROM_SENSORS; - SDL_strlcpy(Player_ship->ship_name, XSTR("Standalone Ship",904), sizeof(Player_ship->ship_name)); + SDL_strlcpy(Player_ship->ship_name, XSTR("Standalone Ship",904), SDL_arraysize(Player_ship->ship_name)); Player_ai = &Ai_info[Ships[Objects[pobj_num].instance].ai_index]; } @@ -1874,9 +1874,9 @@ active_game *multi_update_active_games(active_game *ag) // copy in the game information memcpy(&gp->server_addr,&ag->server_addr,sizeof(net_addr_t)); - SDL_strlcpy(gp->name, ag->name, sizeof(gp->name)); - SDL_strlcpy(gp->mission_name, ag->mission_name, sizeof(gp->mission_name)); - SDL_strlcpy(gp->title, ag->title, sizeof(gp->title)); + SDL_strlcpy(gp->name, ag->name, SDL_arraysize(gp->name)); + SDL_strlcpy(gp->mission_name, ag->mission_name, SDL_arraysize(gp->mission_name)); + SDL_strlcpy(gp->title, ag->title, SDL_arraysize(gp->title)); gp->num_players = ag->num_players; gp->flags = ag->flags; @@ -1892,11 +1892,11 @@ active_game *multi_update_active_games(active_game *ag) // otherwise update the netgame info we have for this guy else { memset(gp->name,0,MAX_GAMENAME_LEN+1); - SDL_strlcpy(gp->name, ag->name, sizeof(gp->name)); + SDL_strlcpy(gp->name, ag->name, SDL_arraysize(gp->name)); memset(gp->mission_name,0,NAME_LENGTH+1); - SDL_strlcpy(gp->mission_name, ag->mission_name, sizeof(gp->mission_name)); + SDL_strlcpy(gp->mission_name, ag->mission_name, SDL_arraysize(gp->mission_name)); memset(gp->title,0,NAME_LENGTH+1); - SDL_strlcpy(gp->title, ag->title, sizeof(gp->title)); + SDL_strlcpy(gp->title, ag->title, SDL_arraysize(gp->title)); gp->num_players = ag->num_players; gp->flags = ag->flags; } @@ -1906,9 +1906,9 @@ active_game *multi_update_active_games(active_game *ag) // copy in the game information memcpy(&gp->server_addr,&ag->server_addr,sizeof(net_addr_t)); - SDL_strlcpy(gp->name, ag->name, sizeof(gp->name)); - SDL_strlcpy(gp->mission_name, ag->mission_name, sizeof(gp->mission_name)); - SDL_strlcpy(gp->title, ag->title, sizeof(gp->title)); + SDL_strlcpy(gp->name, ag->name, SDL_arraysize(gp->name)); + SDL_strlcpy(gp->mission_name, ag->mission_name, SDL_arraysize(gp->mission_name)); + SDL_strlcpy(gp->title, ag->title, SDL_arraysize(gp->title)); gp->num_players = ag->num_players; gp->flags = ag->flags; @@ -3183,10 +3183,10 @@ void multi_update_valid_missions() if(tok == NULL){ continue; } - SDL_strlcpy(temp, tok, sizeof(temp)); + SDL_strlcpy(temp, tok, SDL_arraysize(temp)); drop_trailing_white_space(temp); drop_leading_white_space(temp); - SDL_strlcpy(next_filename, temp, sizeof(next_filename)); + SDL_strlcpy(next_filename, temp, SDL_arraysize(next_filename)); // read in the status string memset(status_string, 0, 50); @@ -3195,10 +3195,10 @@ void multi_update_valid_missions() if(tok == NULL){ continue; } - SDL_strlcpy(temp, tok, sizeof(temp)); + SDL_strlcpy(temp, tok, SDL_arraysize(temp)); drop_trailing_white_space(temp); drop_leading_white_space(temp); - SDL_strlcpy(status_string, temp, sizeof(status_string)); + SDL_strlcpy(status_string, temp, SDL_arraysize(status_string)); // try and find the file file_index = multi_create_lookup_mission(next_filename); @@ -3356,7 +3356,7 @@ void multi_spew_pxo_checksums(int max_files, char *outfile) // allocate filename space file_names = (char**)malloc(sizeof(char*) * max_files); if(file_names != NULL){ - SDL_snprintf(wild_card, sizeof(wild_card), "*%s", FS_MISSION_FILE_EXT); + SDL_snprintf(wild_card, SDL_arraysize(wild_card), "*%s", FS_MISSION_FILE_EXT); count = cf_get_file_list(max_files, file_names, CF_TYPE_MISSIONS, wild_card); // open the outfile @@ -3368,7 +3368,7 @@ void multi_spew_pxo_checksums(int max_files, char *outfile) // do all the checksums for(idx=0; idxobjnum].type == OBJ_SHIP ) { - SDL_strlcpy(buf2, Ships[Objects[osp->objnum].instance].ship_name, sizeof(buf2)); + SDL_strlcpy(buf2, Ships[Objects[osp->objnum].instance].ship_name, SDL_arraysize(buf2)); } else if ( Objects[osp->objnum].type == OBJ_DEBRIS ) { - SDL_strlcpy(buf2, "Debris", sizeof(buf2)); + SDL_strlcpy(buf2, "Debris", SDL_arraysize(buf2)); } else { - SDL_strlcpy(buf2, "Unknown", sizeof(buf2)); + SDL_strlcpy(buf2, "Unknown", SDL_arraysize(buf2)); } vector source_pos; diff --git a/src/osapi/outwnd.cpp b/src/osapi/outwnd.cpp index 5f40aeb..76f5651 100644 --- a/src/osapi/outwnd.cpp +++ b/src/osapi/outwnd.cpp @@ -208,7 +208,7 @@ void load_filter_info(void) return; } - SDL_snprintf(pathname, sizeof(pathname), "%s%s%sdebug_filter.cfg", Cfile_user_dir, Pathtypes[CF_TYPE_DATA].path, DIR_SEPARATOR_STR); + SDL_snprintf(pathname, SDL_arraysize(pathname), "%s%s%sdebug_filter.cfg", Cfile_user_dir, Pathtypes[CF_TYPE_DATA].path, DIR_SEPARATOR_STR); fp = fopen(pathname, "rt"); if (!fp) { @@ -287,7 +287,7 @@ void save_filter_info(void) return; } - SDL_snprintf(pathname, sizeof(pathname), "%s%s%sdebug_filter.cfg", Cfile_user_dir, Pathtypes[CF_TYPE_DATA].path, DIR_SEPARATOR_STR); + SDL_snprintf(pathname, SDL_arraysize(pathname), "%s%s%sdebug_filter.cfg", Cfile_user_dir, Pathtypes[CF_TYPE_DATA].path, DIR_SEPARATOR_STR); fp = fopen(pathname, "wt"); if (fp) @@ -305,7 +305,7 @@ void outwnd_printf2(const char *format, ...) va_list args; va_start(args, format); - SDL_vsnprintf(tmp, sizeof(tmp), format, args); + SDL_vsnprintf(tmp, SDL_arraysize(tmp), format, args); va_end(args); outwnd_print("General", tmp); } @@ -316,7 +316,7 @@ void outwnd_printf(const char *id, const char *format, ...) va_list args; va_start(args, format); - SDL_vsnprintf(tmp, sizeof(tmp), format, args); + SDL_vsnprintf(tmp, SDL_arraysize(tmp), format, args); va_end(args); outwnd_print(id, tmp); } @@ -406,7 +406,7 @@ void outwnd_init(int display_under_freespace_window) char pathname[512]; - SDL_snprintf(pathname, sizeof(pathname), "%s%s%s%s", Cfile_user_dir, Pathtypes[CF_TYPE_DATA].path, DIR_SEPARATOR_STR, Freespace_logfilename); + SDL_snprintf(pathname, SDL_arraysize(pathname), "%s%s%s%s", Cfile_user_dir, Pathtypes[CF_TYPE_DATA].path, DIR_SEPARATOR_STR, Freespace_logfilename); cf_create_directory(CF_TYPE_DATA); if ( Log_fp == NULL ) { diff --git a/src/palman/palman.cpp b/src/palman/palman.cpp index 65055a0..d9bfad7 100644 --- a/src/palman/palman.cpp +++ b/src/palman/palman.cpp @@ -356,7 +356,7 @@ void palette_load_table( const char * filename ) int w, h; int pcx_error; - SDL_strlcpy( palette_base_filename, filename, sizeof(palette_base_filename) ); + SDL_strlcpy( palette_base_filename, filename, SDL_arraysize(palette_base_filename) ); char * p = SDL_strchr(palette_base_filename,'.'); if ( p ) { *p = 0; @@ -504,8 +504,8 @@ void palette_write_cached1( const char *name ) CFILE *fp; char new_name[128]; - SDL_strlcpy( new_name, name, sizeof(new_name) ); - SDL_strlcat( new_name, ".clr", sizeof(new_name) ); + SDL_strlcpy( new_name, name, SDL_arraysize(new_name) ); + SDL_strlcat( new_name, ".clr", SDL_arraysize(new_name) ); // mprintf(( "Writing palette cache file '%s'\n", new_name )); @@ -549,8 +549,8 @@ int palette_read_cached( const char *name ) uint id, new_checksum; ubyte new_palette[768]; - SDL_strlcpy( new_name, name, sizeof(new_name) ); - SDL_strlcat( new_name, ".clr", sizeof(new_name) ); + SDL_strlcpy( new_name, name, SDL_arraysize(new_name) ); + SDL_strlcat( new_name, ".clr", SDL_arraysize(new_name) ); // mprintf(( "Reading palette '%s'\n", name )); @@ -728,11 +728,11 @@ void palette_update(const char *name_with_extension, int restrict_font_to_128) // mprintf(( "<<<<<<<<< PALETTE UPDATE (%s) >>>>>>>>>>>\n", (name_with_extension?name_with_extension:"null") )); - SDL_strlcpy( name, name_with_extension, sizeof(name) ); + SDL_strlcpy( name, name_with_extension, SDL_arraysize(name) ); char *p = SDL_strchr( name, '.' ); if ( p ) *p = 0; - SDL_strlcpy( palette_name, name, sizeof(palette_name) ); + SDL_strlcpy( palette_name, name, SDL_arraysize(palette_name) ); tmp_checksum = palette_compute_checksum( gr_palette ); if ( tmp_checksum == gr_palette_checksum ) return; @@ -882,7 +882,7 @@ void palette_use_bm_palette(int n) ubyte tmp[768]; char name[128]; - bm_get_palette(n, tmp, name, sizeof(name)); // get the palette for this bitmap + bm_get_palette(n, tmp, name, SDL_arraysize(name)); // get the palette for this bitmap gr_set_palette(name, tmp); // load the new palette. } diff --git a/src/parse/parselo.cpp b/src/parse/parselo.cpp index fb44102..f8ed794 100644 --- a/src/parse/parselo.cpp +++ b/src/parse/parselo.cpp @@ -237,7 +237,7 @@ void diag_printf(const char *format, ...) va_list args; va_start(args, format); - SDL_vsnprintf(buffer, sizeof(buffer), format, args); + SDL_vsnprintf(buffer, SDL_arraysize(buffer), format, args); va_end(args); nprintf(("Parse", "%s", buffer)); @@ -319,17 +319,17 @@ void error_display(int error_level, const char *format, ...) va_list args; if (error_level == 0) { - SDL_strlcpy(error_text, "Warning", sizeof(error_text)); + SDL_strlcpy(error_text, "Warning", SDL_arraysize(error_text)); Warning_count++; } else { - SDL_strlcpy(error_text, "Error", sizeof(error_text)); + SDL_strlcpy(error_text, "Error", SDL_arraysize(error_text)); Error_count++; } nprintf((error_text, "%s(%i):%s: ", Current_filename, get_line_num(), error_text)); va_start(args, format); - SDL_vsnprintf(buffer, sizeof(buffer), format, args); + SDL_vsnprintf(buffer, SDL_arraysize(buffer), format, args); va_end(args); nprintf((error_text, "%s", buffer)); @@ -346,7 +346,7 @@ void advance_to_eoln(const char *more_terminators) terminators[0] = EOLN; terminators[1] = (char)EOF_CHAR; if (more_terminators != NULL) - SDL_strlcpy(&terminators[2], more_terminators, sizeof(terminators)); + SDL_strlcpy(&terminators[2], more_terminators, SDL_arraysize(terminators)); else terminators[2] = 0; @@ -668,7 +668,7 @@ void copy_to_eoln(char *outstr, const char *more_terminators, const char *instr, terminators[0] = EOLN; terminators[1] = (char)EOF_CHAR; if (more_terminators != NULL) - SDL_strlcpy(&terminators[2], more_terminators, sizeof(terminators)); + SDL_strlcpy(&terminators[2], more_terminators, SDL_arraysize(terminators)); else terminators[2] = 0; @@ -1152,7 +1152,7 @@ void read_file_text(const char *filename, int mode) if (!filename) throw PARSE_ERROR_EMPTY_FILENAME; - SDL_strlcpy(Current_filename, filename, sizeof(Current_filename)); + SDL_strlcpy(Current_filename, filename, SDL_arraysize(Current_filename)); mf = cfopen(filename, "rb", CFILE_NORMAL, mode); if (mf == NULL) { nprintf(("Error", "Wokka! Error opening mission.txt!\n")); diff --git a/src/parse/sexp.cpp b/src/parse/sexp.cpp index f5465cf..87a0ef0 100644 --- a/src/parse/sexp.cpp +++ b/src/parse/sexp.cpp @@ -2140,7 +2140,7 @@ int build_sexp_string(int cur_node, int level, int mode) SDL_assert(node >= 0 && node < MAX_SEXP_NODES); if (Sexp_nodes[node].first == -1) { // build text to string - build_sexp_text_string(pstr, sizeof(pstr), node, mode); + build_sexp_text_string(pstr, SDL_arraysize(pstr), node, mode); SDL_strlcat(Sexp_string, pstr, Sexp_string_len); } else { @@ -2176,7 +2176,7 @@ void build_extended_sexp_string(int cur_node, int level, int mode) flag = 1; SDL_assert(node >= 0 && node < MAX_SEXP_NODES); if (Sexp_nodes[node].first == -1) { - build_sexp_text_string(pstr, sizeof(pstr),node, mode); + build_sexp_text_string(pstr, SDL_arraysize(pstr),node, mode); SDL_strlcat(Sexp_string, pstr, Sexp_string_len); } else { @@ -4217,7 +4217,7 @@ int waypoint_lookup(char *name) while (ptr != END_OF_LIST(&obj_used_list)) { if (ptr->type == OBJ_WAYPOINT) { i = ptr->instance; - SDL_snprintf(buf, sizeof(buf), "%s:%d", Waypoint_lists[i / 65536].name, (i & 0xffff) + 1); + SDL_snprintf(buf, SDL_arraysize(buf), "%s:%d", Waypoint_lists[i / 65536].name, (i & 0xffff) + 1); if ( !SDL_strcasecmp(buf, name) ) return OBJ_INDEX(ptr); } @@ -9332,7 +9332,7 @@ const char *sexp_error_message(int num) return "Invalid Jump Node name"; } - SDL_snprintf(Sexp_error_text, sizeof(Sexp_error_text), "Sexp error code %d", num); + SDL_snprintf(Sexp_error_text, SDL_arraysize(Sexp_error_text), "Sexp error code %d", num); return Sexp_error_text; } @@ -9485,7 +9485,7 @@ void sexp_modify_variable(int n) // get new numerical value new_number = eval_sexp(Sexp_nodes[n].rest); - SDL_snprintf(number_as_str, sizeof(number_as_str), "%d", new_number); + SDL_snprintf(number_as_str, SDL_arraysize(number_as_str), "%d", new_number); sexp_modify_variable(number_as_str, sexp_variable_index); } else { // get new string diff --git a/src/pcxutils/pcxutils.cpp b/src/pcxutils/pcxutils.cpp index ee1fc9e..a340787 100644 --- a/src/pcxutils/pcxutils.cpp +++ b/src/pcxutils/pcxutils.cpp @@ -135,10 +135,10 @@ int pcx_read_header(char *real_filename, int *w, int *h, ubyte *pal ) CFILE * PCXfile; char filename[MAX_FILENAME_LEN]; - SDL_strlcpy( filename, real_filename, sizeof(filename) ); + SDL_strlcpy( filename, real_filename, SDL_arraysize(filename) ); char *p = SDL_strchr( filename, '.' ); if ( p ) *p = 0; - SDL_strlcat( filename, ".pcx", sizeof(filename) ); + SDL_strlcat( filename, ".pcx", SDL_arraysize(filename) ); PCXfile = cfopen( filename , "rb" ); if ( !PCXfile ) @@ -199,10 +199,10 @@ int pcx_read_bitmap_8bpp( char * real_filename, ubyte *org_data, ubyte *palette ubyte *pixdata; char filename[MAX_FILENAME_LEN]; - SDL_strlcpy( filename, real_filename, sizeof(filename) ); + SDL_strlcpy( filename, real_filename, SDL_arraysize(filename) ); char *p = SDL_strchr( filename, '.' ); if ( p ) *p = 0; - SDL_strlcat( filename, ".pcx", sizeof(filename) ); + SDL_strlcat( filename, ".pcx", SDL_arraysize(filename) ); PCXfile = cfopen( filename , "rb" ); if ( !PCXfile ) @@ -297,10 +297,10 @@ int pcx_read_bitmap_16bpp( char * real_filename, ubyte *org_data ) ushort bit_16; ubyte r, g, b, al; - SDL_strlcpy( filename, real_filename, sizeof(filename) ); + SDL_strlcpy( filename, real_filename, SDL_arraysize(filename) ); char *p = SDL_strchr( filename, '.' ); if ( p ) *p = 0; - SDL_strlcat( filename, ".pcx", sizeof(filename) ); + SDL_strlcat( filename, ".pcx", SDL_arraysize(filename) ); PCXfile = cfopen( filename , "rb" ); if ( !PCXfile ){ @@ -415,11 +415,11 @@ int pcx_read_bitmap_16bpp_aabitmap( char * real_filename, ubyte *org_data ) char filename[MAX_FILENAME_LEN]; ubyte palette[768]; - SDL_strlcpy( filename, real_filename, sizeof(filename) ); + SDL_strlcpy( filename, real_filename, SDL_arraysize(filename) ); char *p = SDL_strchr( filename, '.' ); if ( p ) *p = 0; - SDL_strlcat( filename, ".pcx", sizeof(filename) ); + SDL_strlcat( filename, ".pcx", SDL_arraysize(filename) ); PCXfile = cfopen( filename , "rb" ); if ( !PCXfile ){ @@ -519,10 +519,10 @@ int pcx_read_bitmap_16bpp_nondark( char * real_filename, ubyte *org_data ) ushort bit_16; ubyte r, g, b, al; - SDL_strlcpy( filename, real_filename, sizeof(filename) ); + SDL_strlcpy( filename, real_filename, SDL_arraysize(filename) ); char *p = SDL_strchr( filename, '.' ); if ( p ) *p = 0; - SDL_strlcat( filename, ".pcx", sizeof(filename) ); + SDL_strlcat( filename, ".pcx", SDL_arraysize(filename) ); PCXfile = cfopen( filename , "rb" ); if ( !PCXfile ){ @@ -697,10 +697,10 @@ int pcx_write_bitmap( char * real_filename, int w, int h, ubyte ** row_ptrs, uby FILE * PCXfile; char filename[MAX_FILENAME_LEN]; - SDL_strlcpy( filename, real_filename, sizeof(filename) ); + SDL_strlcpy( filename, real_filename, SDL_arraysize(filename) ); char *p = SDL_strchr( filename, '.' ); if ( p ) *p = 0; - SDL_strlcat( filename, ".pcx", sizeof(filename) ); + SDL_strlcat( filename, ".pcx", SDL_arraysize(filename) ); memset( &header, 0, sizeof( PCXHeader ) ); diff --git a/src/platform/platform.cpp b/src/platform/platform.cpp index 20fae88..9d41168 100644 --- a/src/platform/platform.cpp +++ b/src/platform/platform.cpp @@ -157,10 +157,10 @@ void Warning( const char * filename, int line, const char * format, ... ) va_list args; va_start(args, format); - SDL_vsnprintf(tmp, sizeof(tmp), format, args); + SDL_vsnprintf(tmp, SDL_arraysize(tmp), format, args); va_end(args); - SDL_snprintf(tmp2, sizeof(tmp2), "Warning: %s\n\nFile:%s\nLine: %d", tmp, filename, line); + SDL_snprintf(tmp2, SDL_arraysize(tmp2), "Warning: %s\n\nFile:%s\nLine: %d", tmp, filename, line); gr_force_windowed(); @@ -175,10 +175,10 @@ void Error( const char * filename, int line, const char * format, ... ) va_list args; va_start (args, format); - SDL_vsnprintf (tmp, sizeof(tmp), format, args); + SDL_vsnprintf (tmp, SDL_arraysize(tmp), format, args); va_end(args); - SDL_snprintf(tmp2, sizeof(tmp2), "Error: %s\n\nFile:%s\nLine: %d", tmp, filename, line); + SDL_snprintf(tmp2, SDL_arraysize(tmp2), "Error: %s\n\nFile:%s\nLine: %d", tmp, filename, line); gr_force_windowed(); diff --git a/src/playerman/managepilot.cpp b/src/playerman/managepilot.cpp index 9f046e8..c5d07c9 100644 --- a/src/playerman/managepilot.cpp +++ b/src/playerman/managepilot.cpp @@ -307,10 +307,10 @@ void delete_pilot_file( const char *pilot_name, int single ) // get the player file. - base_filename(pilot_name, basename, sizeof(basename)); + base_filename(pilot_name, basename, SDL_arraysize(basename)); - SDL_strlcpy( filename, basename, sizeof(filename) ); - SDL_strlcat(filename, NOX(".plr"), sizeof(filename) ); + SDL_strlcpy( filename, basename, SDL_arraysize(filename) ); + SDL_strlcat(filename, NOX(".plr"), SDL_arraysize(filename) ); if (Player_sel_mode == PLAYER_SELECT_MODE_SINGLE){ cf_delete(filename, CF_TYPE_SINGLE_PLAYERS); } else { @@ -563,14 +563,14 @@ int read_pilot_file(const char *callsign, int single, player *p) //sprintf(filename, "%-.8s.plr",Players[Player_num].callsign); SDL_assert(strlen(callsign) < MAX_FILENAME_LEN - 4); // ensure we won't overrun the buffer - SDL_strlcpy( filename, callsign, sizeof(filename) ); - SDL_strlcat( filename, NOX(".plr"), sizeof(filename) ); + SDL_strlcpy( filename, callsign, SDL_arraysize(filename) ); + SDL_strlcat( filename, NOX(".plr"), SDL_arraysize(filename) ); // if we're a standalone server in multiplayer, just fill in some bogus values since we don't have a pilot file if ((Game_mode & GM_MULTIPLAYER) && (Game_mode & GM_STANDALONE_SERVER)) { memset(Player, 0, sizeof(player)); - SDL_strlcpy(Player->callsign, NOX("Standalone"), sizeof(Player->callsign)); - SDL_strlcpy(Player->short_callsign, NOX("Standalone"), sizeof(Player->short_callsign)); + SDL_strlcpy(Player->callsign, NOX("Standalone"), SDL_arraysize(Player->callsign)); + SDL_strlcpy(Player->short_callsign, NOX("Standalone"), SDL_arraysize(Player->short_callsign)); return 0; } @@ -787,7 +787,7 @@ int read_pilot_file(const char *callsign, int single, player *p) return errno; // restore the callsign into the Player structure - SDL_strlcpy(p->callsign, callsign, sizeof(p->callsign)); + SDL_strlcpy(p->callsign, callsign, SDL_arraysize(p->callsign)); // restore the truncated callsign into Player structure pilot_set_short_callsign(p, SHORT_CALLSIGN_PIXEL_W); @@ -797,11 +797,11 @@ int read_pilot_file(const char *callsign, int single, player *p) // we'll distinguish them by putting an M and the end of the multiplayer callsign and a P at the end of a single player char cat[35]; - SDL_strlcpy(cat, p->callsign, sizeof(cat)); + SDL_strlcpy(cat, p->callsign, SDL_arraysize(cat)); if (is_multi) - SDL_strlcat(cat, NOX("M"), sizeof(cat)); + SDL_strlcat(cat, NOX("M"), SDL_arraysize(cat)); else - SDL_strlcat(cat, NOX("S"), sizeof(cat)); + SDL_strlcat(cat, NOX("S"), SDL_arraysize(cat)); os_config_write_string( NULL, "LastPlayer", cat ); /* @@ -930,8 +930,8 @@ int write_pilot_file_core(player *p) return 0; // This means there is no player, probably meaning he was deleted and game exited from same screen. SDL_assert((i > 0) && (i <= MAX_FILENAME_LEN - 4)); // ensure we won't overrun the buffer - SDL_strlcpy( filename, p->callsign, sizeof(filename)); - SDL_strlcat( filename, NOX(".plr"), sizeof(filename) ); + SDL_strlcpy( filename, p->callsign, SDL_arraysize(filename)); + SDL_strlcat( filename, NOX(".plr"), SDL_arraysize(filename) ); // determine if this pilot is a multiplayer pilot or not if (p->flags & PLAYER_FLAGS_IS_MULTI){ @@ -1304,8 +1304,8 @@ void init_new_pilot(player *p, int reset) } // unassigned squadron - SDL_strlcpy(p->squad_name, XSTR("Unassigned", 1255), sizeof(p->squad_name)); - SDL_strlcpy(p->squad_filename, "", sizeof(p->squad_filename)); + SDL_strlcpy(p->squad_name, XSTR("Unassigned", 1255), SDL_arraysize(p->squad_name)); + SDL_strlcpy(p->squad_filename, "", SDL_arraysize(p->squad_filename)); // set him to be a single player pilot by default (the actual creation routines will change this if necessary) p->flags &= ~PLAYER_FLAGS_IS_MULTI; @@ -1344,7 +1344,7 @@ void init_new_pilot(player *p, int reset) void pilot_set_short_callsign(player *p, int max_width) { - SDL_strlcpy(p->short_callsign, p->callsign, sizeof(p->short_callsign)); + SDL_strlcpy(p->short_callsign, p->callsign, SDL_arraysize(p->short_callsign)); gr_set_font(FONT1); gr_force_fit_string(p->short_callsign, CALLSIGN_LEN - 1, max_width); gr_get_string_size( &(p->short_callsign_width), NULL, p->short_callsign ); @@ -1355,12 +1355,12 @@ void pilot_set_random_pic(player *p) { // if there are no available pilot pics, set the image filename to null if (Num_pilot_images <= 0) { - SDL_strlcpy(p->image_filename, "", sizeof(p->image_filename)); + SDL_strlcpy(p->image_filename, "", SDL_arraysize(p->image_filename)); } else { // pick a random name from the list int random_index = rand() % Num_pilot_images; SDL_assert((random_index >= 0) && (random_index < Num_pilot_images)); - SDL_strlcpy(p->image_filename, Pilot_images_arr[random_index], sizeof(p->image_filename)); + SDL_strlcpy(p->image_filename, Pilot_images_arr[random_index], SDL_arraysize(p->image_filename)); } } @@ -1450,7 +1450,7 @@ void player_set_squad_bitmap(player *p, const char *fname) // try and set the new one if (fname != p->squad_filename) { - SDL_strlcpy(p->squad_filename, fname, sizeof(p->squad_filename)); + SDL_strlcpy(p->squad_filename, fname, SDL_arraysize(p->squad_filename)); } if(strlen(p->squad_filename) > 0){ @@ -1483,7 +1483,7 @@ void player_set_squad(player *p, const char *squad_name) return; } - SDL_strlcpy(p->squad_name, squad_name, sizeof(p->squad_name)); + SDL_strlcpy(p->squad_name, squad_name, SDL_arraysize(p->squad_name)); } DCF(pilot,"Changes pilot stats. (Like reset campaign)" ) diff --git a/src/playerman/playercontrol.cpp b/src/playerman/playercontrol.cpp index 460ffd8..67ebe37 100644 --- a/src/playerman/playercontrol.cpp +++ b/src/playerman/playercontrol.cpp @@ -1867,7 +1867,7 @@ char *player_generate_death_text( player *player_p, char *death_text, const int char weapon_name[NAME_LENGTH]; weapon_name[0] = 0; - player_generate_killer_weapon_name(player_p->killer_weapon_index, player_p->killer_species, weapon_name, sizeof(weapon_name)); + player_generate_killer_weapon_name(player_p->killer_weapon_index, player_p->killer_species, weapon_name, SDL_arraysize(weapon_name)); switch ( player_p->killer_objtype ) { case OBJ_SHOCKWAVE: @@ -1937,17 +1937,17 @@ void player_show_death_message() if ( Player->flags & PLAYER_KILLED_SELF ) { // reasons he killed himself if(Player->flags & PLAYER_FLAGS_KILLED_SELF_SHOCKWAVE){ - SDL_strlcpy(death_text, XSTR( "You have killed yourself with a shockwave from your own weapon", 1421), sizeof(death_text)); + SDL_strlcpy(death_text, XSTR( "You have killed yourself with a shockwave from your own weapon", 1421), SDL_arraysize(death_text)); } else if(Player->flags & PLAYER_FLAGS_KILLED_SELF_MISSILES){ - SDL_strlcpy(death_text, XSTR( "You have killed yourself with your own missiles", 1422), sizeof(death_text)); + SDL_strlcpy(death_text, XSTR( "You have killed yourself with your own missiles", 1422), SDL_arraysize(death_text)); } else { - SDL_strlcpy(death_text, XSTR( "You have killed yourself", 100), sizeof(death_text)); + SDL_strlcpy(death_text, XSTR( "You have killed yourself", 100), SDL_arraysize(death_text)); } Player->flags &= ~(PLAYER_FLAGS_KILLED_SELF_MISSILES | PLAYER_FLAGS_KILLED_SELF_SHOCKWAVE); } else { - player_generate_death_text( Player, death_text, sizeof(death_text) ); + player_generate_death_text( Player, death_text, SDL_arraysize(death_text) ); } HUD_fixed_printf(30.0f, death_text); @@ -2132,13 +2132,13 @@ void player_display_packlock_view() if ( !(Viewer_mode & (VM_CHASE|VM_EXTERNAL|VM_SLEWED)) ) { switch (padlock_view_index) { case 0: - SDL_strlcpy(str, XSTR( "top view", 101), sizeof(str)); break; + SDL_strlcpy(str, XSTR( "top view", 101), SDL_arraysize(str)); break; case 1: - SDL_strlcpy(str, XSTR( "rear view", 102), sizeof(str)); break; + SDL_strlcpy(str, XSTR( "rear view", 102), SDL_arraysize(str)); break; case 2: - SDL_strlcpy(str, XSTR( "left view", 103), sizeof(str)); break; + SDL_strlcpy(str, XSTR( "left view", 103), SDL_arraysize(str)); break; case 3: - SDL_strlcpy(str, XSTR( "right view", 104), sizeof(str)); break; + SDL_strlcpy(str, XSTR( "right view", 104), SDL_arraysize(str)); break; } HUD_fixed_printf(0.01f, str); diff --git a/src/popup/popup.cpp b/src/popup/popup.cpp index 2625aed..c34f896 100644 --- a/src/popup/popup.cpp +++ b/src/popup/popup.cpp @@ -1235,7 +1235,7 @@ int popup(int flags, int nchoices, ... ) // get msg text format = va_arg( args, char * ); Popup_info.raw_text[0] = 0; - SDL_vsnprintf(Popup_info.raw_text, sizeof(Popup_info.raw_text), format, args); + SDL_vsnprintf(Popup_info.raw_text, SDL_arraysize(Popup_info.raw_text), format, args); va_end(args); gamesnd_play_iface(SND_POPUP_APPEAR); // play sound when popup appears @@ -1288,7 +1288,7 @@ int popup_till_condition(int (*condition)(), ...) // get msg text format = va_arg( args, char * ); Popup_info.raw_text[0] = 0; - SDL_vsnprintf(Popup_info.raw_text, sizeof(Popup_info.raw_text), format, args); + SDL_vsnprintf(Popup_info.raw_text, SDL_arraysize(Popup_info.raw_text), format, args); va_end(args); gamesnd_play_iface(SND_POPUP_APPEAR); // play sound when popup appears @@ -1323,7 +1323,7 @@ char *popup_input(int flags, const char *caption, int max_output_len) // get msg text SDL_assert(caption != NULL); - SDL_strlcpy(Popup_info.raw_text, caption, sizeof(Popup_info.raw_text)); + SDL_strlcpy(Popup_info.raw_text, caption, SDL_arraysize(Popup_info.raw_text)); SDL_assert(strlen(Popup_info.raw_text) < POPUP_MAX_CHARS ); // set input text length @@ -1367,7 +1367,7 @@ void popup_kill_any_active() void popup_change_text(const char *new_text) { // copy the raw text - SDL_strlcpy(Popup_info.raw_text, new_text, sizeof(Popup_info.raw_text)); + SDL_strlcpy(Popup_info.raw_text, new_text, SDL_arraysize(Popup_info.raw_text)); // recalculate all display information popup_split_lines(&Popup_info,Popup_flags); diff --git a/src/radar/radar.cpp b/src/radar/radar.cpp index e6624be..35cc0c7 100644 --- a/src/radar/radar.cpp +++ b/src/radar/radar.cpp @@ -786,7 +786,7 @@ void radar_draw_range() break; case RR_INFINITY: - SDL_snprintf(buf, sizeof(buf), NOX("%c"), Lcl_special_chars); + SDL_snprintf(buf, SDL_arraysize(buf), NOX("%c"), Lcl_special_chars); gr_printf(Radar_dist_coords[gr_screen.res][RR_INFINITY][0], Radar_dist_coords[gr_screen.res][RR_INFINITY][1], buf); break; diff --git a/src/ship/aigoals.cpp b/src/ship/aigoals.cpp index 711c6b4..5c7b3ac 100644 --- a/src/ship/aigoals.cpp +++ b/src/ship/aigoals.cpp @@ -1633,7 +1633,7 @@ int ai_mission_goal_achievable( int objnum, ai_goal *aigp ) // debug code to save off the name of the dockpoints (if they exist). docker_name[0] = dockee_name[0] = '\0'; if ( aigp->flags & AIGF_DOCKER_NAME_VALID ) { - SDL_strlcpy(docker_name, aigp->docker.name, sizeof(docker_name)); + SDL_strlcpy(docker_name, aigp->docker.name, SDL_arraysize(docker_name)); modelnum = Ships[objp->instance].modelnum; index = model_find_dock_name_index(modelnum, aigp->docker.name); aigp->docker.index = index; @@ -1642,7 +1642,7 @@ int ai_mission_goal_achievable( int objnum, ai_goal *aigp ) if ( aigp->flags & AIGF_DOCKEE_NAME_VALID ) { shipnum = ship_name_lookup(aigp->ship_name); if ( shipnum != -1 ) { - SDL_strlcpy(dockee_name, aigp->dockee.name, sizeof(dockee_name)); + SDL_strlcpy(dockee_name, aigp->dockee.name, SDL_arraysize(dockee_name)); modelnum = Ships[shipnum].modelnum; index = model_find_dock_name_index(modelnum, aigp->dockee.name); aigp->dockee.index = index; diff --git a/src/ship/ship.cpp b/src/ship/ship.cpp index 58ead57..2e90d62 100644 --- a/src/ship/ship.cpp +++ b/src/ship/ship.cpp @@ -1083,8 +1083,8 @@ int parse_ship() if ( sip->name[0] == '@' ) { char old_name[NAME_LENGTH]; - SDL_strlcpy(old_name, sip->name, sizeof(old_name)); - SDL_strlcpy(sip->name, old_name+1, sizeof(sip->name)); + SDL_strlcpy(old_name, sip->name, SDL_arraysize(old_name)); + SDL_strlcpy(sip->name, old_name+1, SDL_arraysize(sip->name)); } diag_printf ("Ship name -- %s\n", sip->name); @@ -1161,7 +1161,7 @@ int parse_ship() stuff_string( sip->pof_file, F_NAME, NULL ); // optional hud targeting model - SDL_strlcpy(sip->pof_file_hud, "", sizeof(sip->pof_file_hud)); + SDL_strlcpy(sip->pof_file_hud, "", SDL_arraysize(sip->pof_file_hud)); if(optional_string( "$POF target file:")){ stuff_string(sip->pof_file_hud, F_NAME, NULL); } @@ -1660,7 +1660,7 @@ int parse_ship() if ( index == -1 ) { char *p, name[NAME_LENGTH];; - SDL_strlcpy( name, sip->name, sizeof(name) ); + SDL_strlcpy( name, sip->name, SDL_arraysize(name) ); p = SDL_strchr(name, '#'); if ( p ) *p = '\0'; @@ -1844,7 +1844,7 @@ void ship_add_exited_ship( ship *sp, int reason ) Num_exited_ships++; } - SDL_strlcpy( Ships_exited[entry].ship_name, sp->ship_name, sizeof(Ships_exited[0].ship_name) ); + SDL_strlcpy( Ships_exited[entry].ship_name, sp->ship_name, SDL_arraysize(Ships_exited[0].ship_name) ); Ships_exited[entry].obj_signature = Objects[sp->objnum].signature; Ships_exited[entry].team = sp->team; Ships_exited[entry].flags = reason; @@ -4449,7 +4449,7 @@ void ship_set_bay_path_nums(ship_info *sip, polymodel *pm) // iterate through the paths that exist in the polymodel, searching for $bayN pathnames for ( i = 0; i < pm->n_paths; i++ ) { if ( !SDL_strncasecmp(pm->paths[i].name, NOX("$bay"), 4) ) { - SDL_strlcpy(bay_num_str, pm->paths[i].name+4, sizeof(bay_num_str)); + SDL_strlcpy(bay_num_str, pm->paths[i].name+4, SDL_arraysize(bay_num_str)); bay_num = atoi(bay_num_str); SDL_assert(bay_num >= 1 && bay_num <= MAX_SHIP_BAY_PATHS); pm->ship_bay->paths[bay_num-1] = i; @@ -4611,7 +4611,7 @@ int ship_create(matrix *orient, vector *pos, int ship_type) shipp->ai_index = ai_get_slot(n); SDL_assert( shipp->ai_index >= 0 ); - SDL_snprintf(shipp->ship_name, sizeof(shipp->ship_name), NOX("%s %d"), Ship_info[ship_type].name, n); + SDL_snprintf(shipp->ship_name, SDL_arraysize(shipp->ship_name), NOX("%s %d"), Ship_info[ship_type].name, n); ship_set_default_weapons(shipp, sip); // Moved up here because ship_set requires that weapon info be valid. MK, 4/28/98 ship_set(n, objnum, ship_type); @@ -5680,7 +5680,7 @@ int ship_fire_secondary( object *obj, int allow_swarm ) HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "Too far from target to acquire lock", 487)); } else { char missile_name[NAME_LENGTH]; - SDL_strlcpy(missile_name, wip->name, sizeof(missile_name)); + SDL_strlcpy(missile_name, wip->name, SDL_arraysize(missile_name)); hud_end_string_at_first_hash_symbol(missile_name); HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "Cannot fire %s without a lock", 488), missile_name); } @@ -5725,7 +5725,7 @@ int ship_fire_secondary( object *obj, int allow_swarm ) if ( obj == Player_obj ) if ( ship_maybe_play_secondary_fail_sound(wip) ) { char missile_name[NAME_LENGTH]; - SDL_strlcpy(missile_name, Weapon_info[weapon].name, sizeof(missile_name)); + SDL_strlcpy(missile_name, Weapon_info[weapon].name, SDL_arraysize(missile_name)); hud_end_string_at_first_hash_symbol(missile_name); HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "Cannot fire %s due to weapons system damage", 489), missile_name); } @@ -6134,7 +6134,7 @@ int ship_info_base_lookup(int si_index) int i; char name[NAME_LENGTH], *p; - SDL_strlcpy( name, Ship_info[si_index].name, sizeof(name) ); + SDL_strlcpy( name, Ship_info[si_index].name, SDL_arraysize(name) ); p = SDL_strchr( name, '#' ); SDL_assert( p ); // get allender -- something bogus with ship copy *p = '\0'; @@ -8096,7 +8096,7 @@ char *ship_return_orders(char *outbuf, const int max_outbuf, ship *sp) case AI_GOAL_DESTROY_SUBSYSTEM: { char name[NAME_LENGTH]; if ( aip->targeted_subsys != NULL ) { - SDL_snprintf(outbuf, max_outbuf, XSTR( "atk %s %s", 496), aigp->ship_name, hud_targetbox_truncate_subsys_name(aip->targeted_subsys->system_info->name, sizeof(aip->targeted_subsys->system_info->name))); + SDL_snprintf(outbuf, max_outbuf, XSTR( "atk %s %s", 496), aigp->ship_name, hud_targetbox_truncate_subsys_name(aip->targeted_subsys->system_info->name, SDL_arraysize(aip->targeted_subsys->system_info->name))); SDL_strlcat(outbuf, name, max_outbuf); } else { SDL_strlcpy(outbuf, XSTR( "no orders", 495), max_outbuf); diff --git a/src/ship/shiphit.cpp b/src/ship/shiphit.cpp index 0c5f16e..77408b6 100644 --- a/src/ship/shiphit.cpp +++ b/src/ship/shiphit.cpp @@ -1010,12 +1010,12 @@ void shiphit_record_player_killer(object *killer_objp, player *p) pnum = multi_find_player_by_object( &Objects[killer_objp->parent] ); if ( pnum != -1 ) { - SDL_strlcpy(p->killer_parent_name, Net_players[pnum].player->callsign, sizeof(p->killer_parent_name)); + SDL_strlcpy(p->killer_parent_name, Net_players[pnum].player->callsign, SDL_arraysize(p->killer_parent_name)); } else { nprintf(("Network", "Couldn't find player object of weapon for killer of %s\n", p->callsign)); } } else { - SDL_strlcpy(p->killer_parent_name, Ships[Objects[killer_objp->parent].instance].ship_name, sizeof(p->killer_parent_name)); + SDL_strlcpy(p->killer_parent_name, Ships[Objects[killer_objp->parent].instance].ship_name, SDL_arraysize(p->killer_parent_name)); } break; @@ -1033,12 +1033,12 @@ void shiphit_record_player_killer(object *killer_objp, player *p) pnum = multi_find_player_by_object( &Objects[killer_objp->parent] ); if ( pnum != -1 ) { - SDL_strlcpy(p->killer_parent_name, Net_players[pnum].player->callsign, sizeof(p->killer_parent_name)); + SDL_strlcpy(p->killer_parent_name, Net_players[pnum].player->callsign, SDL_arraysize(p->killer_parent_name)); } else { nprintf(("Network", "Couldn't find player object of shockwave for killer of %s\n", p->callsign)); } } else { - SDL_strlcpy(p->killer_parent_name, Ships[Objects[killer_objp->parent].instance].ship_name, sizeof(p->killer_parent_name)); + SDL_strlcpy(p->killer_parent_name, Ships[Objects[killer_objp->parent].instance].ship_name, SDL_arraysize(p->killer_parent_name)); } break; @@ -1061,12 +1061,12 @@ void shiphit_record_player_killer(object *killer_objp, player *p) pnum = multi_find_player_by_object( killer_objp ); if ( pnum != -1 ) { - SDL_strlcpy(p->killer_parent_name, Net_players[pnum].player->callsign, sizeof(p->killer_parent_name)); + SDL_strlcpy(p->killer_parent_name, Net_players[pnum].player->callsign, SDL_arraysize(p->killer_parent_name)); } else { nprintf(("Network", "Couldn't find player object for killer of %s\n", p->callsign)); } } else { - SDL_strlcpy(p->killer_parent_name, Ships[killer_objp->instance].ship_name, sizeof(p->killer_parent_name)); + SDL_strlcpy(p->killer_parent_name, Ships[killer_objp->instance].ship_name, SDL_arraysize(p->killer_parent_name)); } break; @@ -1089,11 +1089,11 @@ void shiphit_record_player_killer(object *killer_objp, player *p) p->killer_objtype = OBJ_BEAM; if(beam_obj != -1){ if((Objects[beam_obj].type == OBJ_SHIP) && (Objects[beam_obj].instance >= 0)){ - SDL_strlcpy(p->killer_parent_name, Ships[Objects[beam_obj].instance].ship_name, sizeof(p->killer_parent_name)); + SDL_strlcpy(p->killer_parent_name, Ships[Objects[beam_obj].instance].ship_name, SDL_arraysize(p->killer_parent_name)); } p->killer_species = Ship_info[Ships[Objects[beam_obj].instance].ship_info_index].species; } else { - SDL_strlcpy(p->killer_parent_name, "", sizeof(p->killer_parent_name)); + SDL_strlcpy(p->killer_parent_name, "", SDL_arraysize(p->killer_parent_name)); } break; @@ -1806,9 +1806,9 @@ void ship_hit_kill(object *ship_obj, object *other_obj, float percent_killed, in // get first name np_index = multi_find_player_by_object(ship_obj); if((np_index >= 0) && (np_index < MAX_PLAYERS) && (Net_players[np_index].player != NULL)){ - SDL_strlcpy(name1, Net_players[np_index].player->callsign, sizeof(name1)); + SDL_strlcpy(name1, Net_players[np_index].player->callsign, SDL_arraysize(name1)); } else { - SDL_strlcpy(name1, sp->ship_name, sizeof(name1)); + SDL_strlcpy(name1, sp->ship_name, SDL_arraysize(name1)); } // argh @@ -1816,13 +1816,13 @@ void ship_hit_kill(object *ship_obj, object *other_obj, float percent_killed, in // second name if(killer_objp == NULL){ - SDL_strlcpy(name2, killer_ship_name, sizeof(name2)); + SDL_strlcpy(name2, killer_ship_name, SDL_arraysize(name2)); } else { np_index = multi_find_player_by_object(killer_objp); if((np_index >= 0) && (np_index < MAX_PLAYERS) && (Net_players[np_index].player != NULL)){ - SDL_strlcpy(name2, Net_players[np_index].player->callsign, sizeof(name2)); + SDL_strlcpy(name2, Net_players[np_index].player->callsign, SDL_arraysize(name2)); } else { - SDL_strlcpy(name2, killer_ship_name, sizeof(name2)); + SDL_strlcpy(name2, killer_ship_name, SDL_arraysize(name2)); } } } @@ -1889,7 +1889,7 @@ void ship_self_destruct( object *objp ) int np_index = multi_find_player_by_object(objp); if((np_index >= 0) && (np_index < MAX_PLAYERS) && MULTI_CONNECTED(Net_players[np_index]) && (Net_players[np_index].player != NULL)){ char msg[512] = ""; - SDL_snprintf(msg, sizeof(msg), "%s %s", Net_players[np_index].player->callsign, XSTR("Self destructed", 1476)); + SDL_snprintf(msg, SDL_arraysize(msg), "%s %s", Net_players[np_index].player->callsign, XSTR("Self destructed", 1476)); // send a message send_game_chat_packet(Net_player, msg, MULTI_MSG_ALL, NULL, NULL, 2); diff --git a/src/sound/sound.cpp b/src/sound/sound.cpp index 3b60c3c..8ef3420 100644 --- a/src/sound/sound.cpp +++ b/src/sound/sound.cpp @@ -443,7 +443,7 @@ void snd_spew_info() continue; } - SDL_snprintf(txt, sizeof(txt), "%s (%ds)\n", Sounds[idx].filename, Sounds[idx].info.duration); + SDL_snprintf(txt, SDL_arraysize(txt), "%s (%ds)\n", Sounds[idx].filename, Sounds[idx].info.duration); cfwrite_string(txt, out); } @@ -592,7 +592,7 @@ int snd_load(game_snd *gs) if ( rc == -1 ) return -1; - SDL_strlcpy( snd->filename, gs->filename, sizeof(snd->filename) ); + SDL_strlcpy( snd->filename, gs->filename, SDL_arraysize(snd->filename) ); snd->flags = SND_F_USED; snd->sig = snd_next_sig++; diff --git a/src/starfield/starfield.cpp b/src/starfield/starfield.cpp index f9c5d92..c68ac55 100644 --- a/src/starfield/starfield.cpp +++ b/src/starfield/starfield.cpp @@ -391,13 +391,13 @@ void stars_init() for(idx=0; idxfilename, filename, sizeof(bm->filename)); + SDL_strlcpy(bm->filename, filename, SDL_arraysize(bm->filename)); bm->xparent = 0; bm->bitmap = bm_load(bm->filename); SDL_assert(bm->bitmap != -1); @@ -425,7 +425,7 @@ void stars_init() stuff_string(filename, F_NAME, NULL); if(count < MAX_STARFIELD_BITMAPS){ bm = &Starfield_bitmaps[count++]; - SDL_strlcpy(bm->filename, filename, sizeof(bm->filename)); + SDL_strlcpy(bm->filename, filename, SDL_arraysize(bm->filename)); bm->xparent = 1; bm->bitmap = bm_load(bm->filename); SDL_assert(bm->bitmap != -1); @@ -458,8 +458,8 @@ void stars_init() if(count < MAX_STARFIELD_BITMAPS){ bm = &Sun_bitmaps[count++]; - SDL_strlcpy(bm->filename, filename, sizeof(bm->filename)); - SDL_strlcpy(bm->glow_filename, glow_filename, sizeof(bm->glow_filename)); + SDL_strlcpy(bm->filename, filename, SDL_arraysize(bm->filename)); + SDL_strlcpy(bm->glow_filename, glow_filename, SDL_arraysize(bm->glow_filename)); bm->xparent = 1; bm->bitmap = bm_load(bm->filename); bm->glow_bitmap = bm_load(bm->glow_filename); @@ -492,7 +492,7 @@ void stars_init() stuff_string(filename, F_NAME, NULL); if(count < MAX_DEBRIS_VCLIPS){ - SDL_strlcpy(debris_vclips_normal[count++].name, filename, sizeof(debris_vclips_normal[0].name)); + SDL_strlcpy(debris_vclips_normal[count++].name, filename, SDL_arraysize(debris_vclips_normal[0].name)); } } SDL_assert(count == 4); @@ -504,7 +504,7 @@ void stars_init() stuff_string(filename, F_NAME, NULL); if(count < MAX_DEBRIS_VCLIPS){ - SDL_strlcpy(debris_vclips_nebula[count++].name, filename, sizeof(debris_vclips_nebula[0].name)); + SDL_strlcpy(debris_vclips_nebula[count++].name, filename, SDL_arraysize(debris_vclips_nebula[0].name)); } } @@ -521,21 +521,21 @@ void stars_init() for (idx=0; idxfilename, "Sun01", sizeof(bm->filename)); - SDL_strlcpy(bm->glow_filename, "Sunglow01", sizeof(bm->glow_filename)); + SDL_strlcpy(bm->filename, "Sun01", SDL_arraysize(bm->filename)); + SDL_strlcpy(bm->glow_filename, "Sunglow01", SDL_arraysize(bm->glow_filename)); bm->xparent = 1; bm->bitmap = bm_load(bm->filename); bm->glow_bitmap = bm_load(bm->glow_filename); @@ -602,7 +602,7 @@ void stars_level_init() mprintf(("Adding default sun\n")); // stuff some values - SDL_strlcpy(Suns[0].filename, Sun_bitmaps[0].filename, sizeof(Suns[0].filename)); + SDL_strlcpy(Suns[0].filename, Sun_bitmaps[0].filename, SDL_arraysize(Suns[0].filename)); Suns[0].scale_x = 1.0f; Suns[0].scale_y = 1.0f; Suns[0].div_x = 1; diff --git a/src/stats/medals.cpp b/src/stats/medals.cpp index 806c839..7ab1a5c 100644 --- a/src/stats/medals.cpp +++ b/src/stats/medals.cpp @@ -784,31 +784,31 @@ void blit_label(char *label, int *coords, int num) // translate medal names before displaying // cant translate in table cuz the names are used in comparisons if (Lcl_gr) { - SDL_strlcpy(translated_label, label, sizeof(translated_label)); - medals_translate_name(translated_label, sizeof(translated_label)); + SDL_strlcpy(translated_label, label, SDL_arraysize(translated_label)); + medals_translate_name(translated_label, SDL_arraysize(translated_label)); // set correct string if ( num > 1 ) { - SDL_snprintf( text, sizeof(text), NOX("%s (%d)"), translated_label, num ); + SDL_snprintf( text, SDL_arraysize(text), NOX("%s (%d)"), translated_label, num ); } else { - SDL_snprintf( text, sizeof(text), "%s", translated_label ); + SDL_snprintf( text, SDL_arraysize(text), "%s", translated_label ); } } else if(Lcl_pl) { - SDL_strlcpy(translated_label, label, sizeof(translated_label)); - medals_translate_name_pl(translated_label, sizeof(translated_label)); + SDL_strlcpy(translated_label, label, SDL_arraysize(translated_label)); + medals_translate_name_pl(translated_label, SDL_arraysize(translated_label)); // set correct string if ( num > 1 ) { - SDL_snprintf( text, sizeof(text), NOX("%s (%d)"), translated_label, num ); + SDL_snprintf( text, SDL_arraysize(text), NOX("%s (%d)"), translated_label, num ); } else { - SDL_snprintf( text, sizeof(text), "%s", translated_label ); + SDL_snprintf( text, SDL_arraysize(text), "%s", translated_label ); } } else { // set correct string if ( num > 1 ) { - SDL_snprintf( text, sizeof(text), NOX("%s (%d)"), label, num ); + SDL_snprintf( text, SDL_arraysize(text), NOX("%s (%d)"), label, num ); } else { - SDL_snprintf( text, sizeof(text), "%s", label ); + SDL_snprintf( text, SDL_arraysize(text), "%s", label ); } } @@ -971,9 +971,9 @@ void init_medal_bitmaps() // possibly load a different filename that is specified by the bitmap filename // for this medal. if the player has > 1 of these types of medals, then determien // which of the possible version to use based on the player's count of this medal - SDL_strlcpy( filename, Medals[idx].bitmap, sizeof(filename) ); + SDL_strlcpy( filename, Medals[idx].bitmap, SDL_arraysize(filename) ); - base_filename(filename, base, sizeof(base)); + base_filename(filename, base, SDL_arraysize(base)); num_medals = Player_score->medals[idx]; @@ -984,12 +984,12 @@ void init_medal_bitmaps() if ( num_medals > 1 ) { // append the proper character onto the end of the medal filename. Base version // has no character. next version is a, then b, etc. - SDL_snprintf( base, sizeof(base), "%s%c", base, (num_medals-2)+'a'); + SDL_snprintf( base, SDL_arraysize(base), "%s%c", base, (num_medals-2)+'a'); } // hi-res support if (gr_screen.res == GR_1024) { - SDL_snprintf( filename, sizeof(filename), "2_%s", base ); + SDL_snprintf( filename, SDL_arraysize(filename), "2_%s", base ); } // base now contains the actual medal bitmap filename needed to load @@ -1003,7 +1003,7 @@ void init_medal_bitmaps() // load up rank insignia if (gr_screen.res == GR_1024) { char filename[NAME_LENGTH]; - SDL_snprintf(filename, sizeof(filename), "2_%s", Ranks[Player_score->rank].bitmap); + SDL_snprintf(filename, SDL_arraysize(filename), "2_%s", Ranks[Player_score->rank].bitmap); Rank_bm = bm_load(filename); } else { Rank_bm = bm_load(Ranks[Player_score->rank].bitmap); diff --git a/src/stats/scoring.cpp b/src/stats/scoring.cpp index 40c8ae5..f6ac973 100644 --- a/src/stats/scoring.cpp +++ b/src/stats/scoring.cpp @@ -918,7 +918,7 @@ void scoring_eval_kill(object *ship_obj) if((Net_player != NULL) && (Net_player->flags & NETINFO_FLAG_AM_MASTER) && (net_plr != NULL) && (dead_plr != NULL) && (net_plr->player != NULL) && (dead_plr->player != NULL)){ char dead_text[1024] = ""; - SDL_snprintf(dead_text, sizeof(dead_text), "%s gets the kill for %s", net_plr->player->callsign, dead_plr->player->callsign); + SDL_snprintf(dead_text, SDL_arraysize(dead_text), "%s gets the kill for %s", net_plr->player->callsign, dead_plr->player->callsign); send_game_chat_packet(Net_player, dead_text, MULTI_MSG_ALL, NULL, NULL, 2); HUD_printf(dead_text); } diff --git a/src/stats/stats.cpp b/src/stats/stats.cpp index 68d41ea..fb46669 100644 --- a/src/stats/stats.cpp +++ b/src/stats/stats.cpp @@ -322,63 +322,63 @@ void show_stats_numbers(int stage, int sx, int sy, int dy,int add_mission) switch ( stage ) { case MISSION_STATS: // mission kills stats - SDL_snprintf(text,sizeof(text),"%d",Active_player->stats.m_kill_count_ok); + SDL_snprintf(text,SDL_arraysize(text),"%d",Active_player->stats.m_kill_count_ok); gr_printf(sx,sy,text); // stats_underline_text(sx,sy,text); sy += 2*dy; // mission primary weapon stats - SDL_snprintf(text,sizeof(text),"%d",Active_player->stats.mp_shots_fired); + SDL_snprintf(text,SDL_arraysize(text),"%d",Active_player->stats.mp_shots_fired); gr_printf(sx,sy,text); sy += dy; - SDL_snprintf(text,sizeof(text),"%d",Active_player->stats.mp_shots_hit); + SDL_snprintf(text,SDL_arraysize(text),"%d",Active_player->stats.mp_shots_hit); gr_printf(sx,sy,text); sy += dy; - SDL_snprintf(text,sizeof(text),"%d",Active_player->stats.mp_bonehead_hits); + SDL_snprintf(text,SDL_arraysize(text),"%d",Active_player->stats.mp_bonehead_hits); gr_printf(sx,sy,text); sy += dy; if(Active_player->stats.mp_shots_fired>0) pct=(float)100.0*((float)Active_player->stats.mp_shots_hit/(float)Active_player->stats.mp_shots_fired); else pct=(float)0.0; - SDL_snprintf(text,sizeof(text),"%d",(int)pct); SDL_strlcat(text," %%", sizeof(text)); + SDL_snprintf(text,SDL_arraysize(text),"%d",(int)pct); SDL_strlcat(text," %%", SDL_arraysize(text)); gr_printf(sx,sy,text); sy += dy; if(Active_player->stats.mp_bonehead_hits>0) pct=(float)100.0*((float)Active_player->stats.mp_bonehead_hits/(float)Active_player->stats.mp_shots_fired); else pct=(float)0.0; - SDL_snprintf(text,sizeof(text),"%d",(int)pct); SDL_strlcat(text," %%", sizeof(text)); + SDL_snprintf(text,SDL_arraysize(text),"%d",(int)pct); SDL_strlcat(text," %%", SDL_arraysize(text)); gr_printf(sx,sy,text); sy += 2*dy; // mission secondary weapon stats - SDL_snprintf(text,sizeof(text),"%d",Active_player->stats.ms_shots_fired); + SDL_snprintf(text,SDL_arraysize(text),"%d",Active_player->stats.ms_shots_fired); gr_printf(sx,sy,text); sy += dy; - SDL_snprintf(text,sizeof(text),"%d",Active_player->stats.ms_shots_hit); + SDL_snprintf(text,SDL_arraysize(text),"%d",Active_player->stats.ms_shots_hit); gr_printf(sx,sy,text); sy += dy; - SDL_snprintf(text,sizeof(text),"%d",Active_player->stats.ms_bonehead_hits); + SDL_snprintf(text,SDL_arraysize(text),"%d",Active_player->stats.ms_bonehead_hits); gr_printf(sx,sy,text); sy += dy; if(Active_player->stats.ms_shots_fired>0) pct=(float)100.0*((float)Active_player->stats.ms_shots_hit/(float)Active_player->stats.ms_shots_fired); else pct=(float)0.0; - SDL_snprintf(text,sizeof(text),"%d",(int)pct); SDL_strlcat(text," %%", sizeof(text)); + SDL_snprintf(text,SDL_arraysize(text),"%d",(int)pct); SDL_strlcat(text," %%", SDL_arraysize(text)); gr_printf(sx,sy,text); sy += dy; if(Active_player->stats.ms_bonehead_hits>0) pct=(float)100.0*((float)Active_player->stats.ms_bonehead_hits/(float)Active_player->stats.ms_shots_fired); else pct=(float)0.0; - SDL_snprintf(text,sizeof(text),"%d",(int)pct); SDL_strlcat(text," %%", sizeof(text)); + SDL_snprintf(text,SDL_arraysize(text),"%d",(int)pct); SDL_strlcat(text," %%", SDL_arraysize(text)); gr_printf(sx,sy,text); sy += 2*dy; // mission assists and player rescues (respawns) - SDL_snprintf(text,sizeof(text),"%d",(int)Active_player->stats.m_assists); + SDL_snprintf(text,SDL_arraysize(text),"%d",(int)Active_player->stats.m_assists); gr_printf(sx,sy,text); sy += 2*dy; if(Game_mode & GM_MULTIPLAYER){ - SDL_snprintf(text,sizeof(text),"%d",(int)Active_player->stats.m_player_deaths); + SDL_snprintf(text,SDL_arraysize(text),"%d",(int)Active_player->stats.m_player_deaths); gr_printf(sx,sy,text); sy += 2*dy; @@ -407,59 +407,59 @@ void show_stats_numbers(int stage, int sx, int sy, int dy,int add_mission) } // mission kills stats - SDL_snprintf(text,sizeof(text),"%d",Active_player->stats.kill_count_ok + add.kill_count_ok); + SDL_snprintf(text,SDL_arraysize(text),"%d",Active_player->stats.kill_count_ok + add.kill_count_ok); hud_num_make_mono(text); gr_printf(sx,sy,text); // stats_underline_text(sx,sy,text); sy += 2*dy; // alltime primary weapon stats - SDL_snprintf(text,sizeof(text),"%d",Active_player->stats.p_shots_fired + add.p_shots_fired); + SDL_snprintf(text,SDL_arraysize(text),"%d",Active_player->stats.p_shots_fired + add.p_shots_fired); gr_printf(sx,sy,text); sy += dy; - SDL_snprintf(text,sizeof(text),"%d",Active_player->stats.p_shots_hit + add.p_shots_hit); + SDL_snprintf(text,SDL_arraysize(text),"%d",Active_player->stats.p_shots_hit + add.p_shots_hit); gr_printf(sx,sy,text); sy += dy; - SDL_snprintf(text,sizeof(text),"%d",Active_player->stats.p_bonehead_hits + add.p_bonehead_hits); + SDL_snprintf(text,SDL_arraysize(text),"%d",Active_player->stats.p_bonehead_hits + add.p_bonehead_hits); gr_printf(sx,sy,text); sy += dy; if((Active_player->stats.p_shots_fired + add.p_shots_fired)>0) pct=(float)100.0*((float)(Active_player->stats.p_shots_hit+add.p_shots_hit)/(float)(Active_player->stats.p_shots_fired + add.p_shots_fired)); else pct=(float)0.0; - SDL_snprintf(text,sizeof(text),"%d",(int)pct); SDL_strlcat(text," %%", sizeof(text)); + SDL_snprintf(text,SDL_arraysize(text),"%d",(int)pct); SDL_strlcat(text," %%", SDL_arraysize(text)); gr_printf(sx,sy,text); sy += dy; if((Active_player->stats.p_bonehead_hits + add.p_bonehead_hits)>0) pct=(float)100.0*((float)(Active_player->stats.p_bonehead_hits+add.p_bonehead_hits)/(float)(Active_player->stats.p_shots_fired + add.p_shots_fired)); else pct=(float)0.0; - SDL_snprintf(text,sizeof(text),"%d",(int)pct); SDL_strlcat(text," %%", sizeof(text)); + SDL_snprintf(text,SDL_arraysize(text),"%d",(int)pct); SDL_strlcat(text," %%", SDL_arraysize(text)); gr_printf(sx,sy,text); sy += 2*dy; // alltime secondary weapon stats - SDL_snprintf(text,sizeof(text),"%d",Active_player->stats.s_shots_fired + add.s_shots_fired); + SDL_snprintf(text,SDL_arraysize(text),"%d",Active_player->stats.s_shots_fired + add.s_shots_fired); gr_printf(sx,sy,text); sy += dy; - SDL_snprintf(text,sizeof(text),"%d",Active_player->stats.s_shots_hit + add.s_shots_hit); + SDL_snprintf(text,SDL_arraysize(text),"%d",Active_player->stats.s_shots_hit + add.s_shots_hit); gr_printf(sx,sy,text); sy += dy; - SDL_snprintf(text,sizeof(text),"%d",Active_player->stats.s_bonehead_hits + add.s_bonehead_hits); + SDL_snprintf(text,SDL_arraysize(text),"%d",Active_player->stats.s_bonehead_hits + add.s_bonehead_hits); gr_printf(sx,sy,text); sy += dy; if((Active_player->stats.s_shots_fired+add.s_shots_fired)>0) pct=(float)100.0*((float)(Active_player->stats.s_shots_hit + add.s_shots_hit)/(float)(Active_player->stats.s_shots_fired + add.s_shots_fired)); else pct=(float)0.0; - SDL_snprintf(text,sizeof(text),"%d",(int)pct); SDL_strlcat(text," %%", sizeof(text)); + SDL_snprintf(text,SDL_arraysize(text),"%d",(int)pct); SDL_strlcat(text," %%", SDL_arraysize(text)); gr_printf(sx,sy,text); sy += dy; if((Active_player->stats.s_bonehead_hits + add.s_bonehead_hits)>0) pct=(float)100.0*((float)(Active_player->stats.s_bonehead_hits+add.s_bonehead_hits)/(float)(Active_player->stats.s_shots_fired+add.s_shots_fired)); else pct=(float)0.0; - SDL_snprintf(text,sizeof(text),"%d",(int)pct); SDL_strlcat(text," %%", sizeof(text)); + SDL_snprintf(text,SDL_arraysize(text),"%d",(int)pct); SDL_strlcat(text," %%", SDL_arraysize(text)); gr_printf(sx,sy,text); sy += 2*dy; // alltime assists - SDL_snprintf(text,sizeof(text),"%d",(int)Active_player->stats.assists + add.assists); + SDL_snprintf(text,SDL_arraysize(text),"%d",(int)Active_player->stats.assists + add.assists); gr_printf(sx,sy,text); sy += 2*dy; diff --git a/src/tgautils/tgautils.cpp b/src/tgautils/tgautils.cpp index 59874f3..5e30081 100644 --- a/src/tgautils/tgautils.cpp +++ b/src/tgautils/tgautils.cpp @@ -368,10 +368,10 @@ int targa_read_header(char *real_filename, int *w, int *h, int *bpp, ubyte *pale CFILE *targa_file; char filename[MAX_FILENAME_LEN]; - SDL_strlcpy( filename, real_filename, sizeof(filename) ); + SDL_strlcpy( filename, real_filename, SDL_arraysize(filename) ); char *p = SDL_strchr( filename, '.' ); if ( p ) *p = 0; - SDL_strlcat( filename, ".tga", sizeof(filename) ); + SDL_strlcat( filename, ".tga", SDL_arraysize(filename) ); targa_file = cfopen( filename , "rb" ); if ( !targa_file ){ @@ -503,10 +503,10 @@ int targa_read_bitmap(char *real_filename, ubyte *image_data, ubyte *palette, in ubyte r, g, b; // open the file - SDL_strlcpy( filename, real_filename, sizeof(filename) ); + SDL_strlcpy( filename, real_filename, SDL_arraysize(filename) ); char *p = SDL_strchr( filename, '.' ); if ( p ) *p = 0; - SDL_strlcat( filename, ".tga", sizeof(filename) ); + SDL_strlcat( filename, ".tga", SDL_arraysize(filename) ); targa_file = cfopen( filename , "rb" ); if ( !targa_file ){ @@ -708,10 +708,10 @@ int targa_write_bitmap(char *real_filename, ubyte *data, ubyte *palette, int w, int bytes_per_pixel = BYTES_PER_PIXEL(bpp); // open the file - SDL_strlcpy( filename, real_filename, sizeof(filename) ); + SDL_strlcpy( filename, real_filename, SDL_arraysize(filename) ); char *p = SDL_strchr( filename, '.' ); if ( p ) *p = 0; - SDL_strlcat( filename, ".tga", sizeof(filename) ); + SDL_strlcat( filename, ".tga", SDL_arraysize(filename) ); f = cfopen( filename , "wb" ); if ( !f ){ diff --git a/src/ui/gadget.cpp b/src/ui/gadget.cpp index fd7e06f..e960475 100644 --- a/src/ui/gadget.cpp +++ b/src/ui/gadget.cpp @@ -249,19 +249,19 @@ int UI_GADGET::set_bmaps(const char *ani_fname, int nframes, int start_frame) // searching and therefore loading for(idx=start_frame; idxxstr_id, gr_screen.res); - SDL_strlcpy(str, XSTR(x->xstr, x->xstr_id), sizeof(str)); + SDL_strlcpy(str, XSTR(x->xstr, x->xstr_id), SDL_arraysize(str)); if(str[0] == '&'){ if(strlen(str) > 1){ gr_string((x->x) + xoffset, x->y, str + 1); diff --git a/src/vcodec/codec1.cpp b/src/vcodec/codec1.cpp index 42694b5..839cc48 100644 --- a/src/vcodec/codec1.cpp +++ b/src/vcodec/codec1.cpp @@ -737,7 +737,7 @@ static void Decode1(t_Sample* bufIn, t_Sample* bufOut, int size, int sizeOut) int leftIn = bufEnd - p, leftOut = bufOutEnd - q; char str[80]; - SDL_snprintf(str, sizeof(str), "%d bytes left in source, %d bytes left in dest", + SDL_snprintf(str, SDL_arraysize(str), "%d bytes left in source, %d bytes left in dest", leftIn, leftOut); AfxMessageBox(str); diff --git a/src/weapon/emp.cpp b/src/weapon/emp.cpp index 3bed391..de4d392 100644 --- a/src/weapon/emp.cpp +++ b/src/weapon/emp.cpp @@ -517,7 +517,7 @@ void emp_hud_string(int x, int y, int gauge_id, const char *str) char tmp[256] = ""; // copy the string - SDL_strlcpy(tmp, str, sizeof(tmp)); + SDL_strlcpy(tmp, str, SDL_arraysize(tmp)); // if the emp effect is not active, don't even bother messing with the text if(emp_active_local()){ @@ -539,7 +539,7 @@ void emp_hud_printf(int x, int y, int gauge_id, const char *format, ...) // format the text va_start(args, format); - SDL_vsnprintf(tmp, sizeof(tmp), format, args); + SDL_vsnprintf(tmp, SDL_arraysize(tmp), format, args); va_end(args); // if the emp effect is not active, don't even bother messing with the text @@ -586,7 +586,7 @@ void emp_maybe_reformat_text(char *text, const int max_len, int gauge_id) case EG_WEAPON_TITLE: case EG_WEAPON_P1: case EG_WEAPON_P2: case EG_WEAPON_P3: case EG_WEAPON_S1: case EG_WEAPON_S2: int wep_index; wep_index = (int)frand_range(0.0f, (float)(MAX_WEAPON_TYPES - 1)); - SDL_strlcpy(wt->str, Weapon_info[ wep_index >= MAX_WEAPON_TYPES ? 0 : wep_index ].name, sizeof(wt->str)); + SDL_strlcpy(wt->str, Weapon_info[ wep_index >= MAX_WEAPON_TYPES ? 0 : wep_index ].name, SDL_arraysize(wt->str)); break; // escort list @@ -595,32 +595,32 @@ void emp_maybe_reformat_text(char *text, const int max_len, int gauge_id) int shipnum; shipnum = ship_get_random_ship(); if(shipnum >= 0){ - SDL_strlcpy(wt->str, Ships[shipnum].ship_name, sizeof(wt->str)); + SDL_strlcpy(wt->str, Ships[shipnum].ship_name, SDL_arraysize(wt->str)); } break; // directives title case EG_OBJ_TITLE: - SDL_strlcpy(wt->str, "", sizeof(wt->str)); + SDL_strlcpy(wt->str, "", SDL_arraysize(wt->str)); break; // directives themselves case EG_OBJ1: case EG_OBJ2: case EG_OBJ3: case EG_OBJ4: case EG_OBJ5: - SDL_strlcpy(wt->str, text, sizeof(wt->str)); + SDL_strlcpy(wt->str, text, SDL_arraysize(wt->str)); emp_randomize_chars(wt->str); break; // target box info case EG_TBOX_EXTRA1: case EG_TBOX_EXTRA2: case EG_TBOX_EXTRA3: case EG_TBOX_CLASS: case EG_TBOX_DIST: case EG_TBOX_CARGO: case EG_TBOX_HULL: case EG_TBOX_NAME: case EG_TBOX_INTEG: - SDL_strlcpy(wt->str, text, sizeof(wt->str)); + SDL_strlcpy(wt->str, text, SDL_arraysize(wt->str)); emp_randomize_chars(wt->str); break; // squadmsg menu case EG_SQ1: case EG_SQ2: case EG_SQ3: case EG_SQ4: case EG_SQ5: case EG_SQ6: case EG_SQ7: case EG_SQ8: case EG_SQ9: case EG_SQ10: - SDL_strlcpy(wt->str, text, sizeof(wt->str)); + SDL_strlcpy(wt->str, text, SDL_arraysize(wt->str)); emp_randomize_chars(wt->str); break; diff --git a/src/weapon/weapons.cpp b/src/weapon/weapons.cpp index 7f464eb..f582a3c 100644 --- a/src/weapon/weapons.cpp +++ b/src/weapon/weapons.cpp @@ -843,8 +843,8 @@ int parse_weapon() if ( wip->name[0] == '@' ) { char old_name[NAME_LENGTH]; - SDL_strlcpy(old_name, wip->name, sizeof(old_name)); - SDL_strlcpy(wip->name, old_name+1, sizeof(wip->name)); + SDL_strlcpy(old_name, wip->name, SDL_arraysize(old_name)); + SDL_strlcpy(wip->name, old_name+1, SDL_arraysize(wip->name)); } wip->title[0] = 0; -- 2.39.2