diff --git a/code/graphics/paths/NVGRenderer.cpp b/code/graphics/paths/NVGRenderer.cpp index 6ee1be6ea1..75e32dad94 100644 --- a/code/graphics/paths/NVGRenderer.cpp +++ b/code/graphics/paths/NVGRenderer.cpp @@ -1,7 +1,12 @@ +#include "globalincs/pstypes.h" + +#if SCP_COMPILER_IS_GNU // Disable warnings inside the NanoVG implementation #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wshadow" +#endif + #include "graphics/paths/NVGRenderer.h" #include "graphics/gropengl.h" @@ -14,7 +19,10 @@ #define NANOVG_GL2_IMPLEMENTATION #include "nanovg/nanovg_gl.h" + +#if SCP_COMPILER_IS_GNU #pragma GCC diagnostic pop +#endif namespace { diff --git a/code/graphics/paths/nanovg/fontstash.h b/code/graphics/paths/nanovg/fontstash.h index 53cfc1b61a..ba120aa909 100644 --- a/code/graphics/paths/nanovg/fontstash.h +++ b/code/graphics/paths/nanovg/fontstash.h @@ -865,7 +865,7 @@ int fonsAddFont(FONScontext* stash, const char* name, const char* path) fseek(fp,0,SEEK_SET); data = (unsigned char*)malloc(dataSize); if (data == NULL) goto error; - if (fread(data, 1, dataSize, fp) != dataSize) goto error; + if (fread(data, 1, dataSize, fp) != (size_t)dataSize) goto error; fclose(fp); fp = 0; diff --git a/code/graphics/paths/nanovg/stb_image.h b/code/graphics/paths/nanovg/stb_image.h index a3c1129932..094c148486 100644 --- a/code/graphics/paths/nanovg/stb_image.h +++ b/code/graphics/paths/nanovg/stb_image.h @@ -4500,7 +4500,7 @@ static int stbi__parse_png_file(stbi__png *z, int scan, int req_comp) if (c.length != (stbi__uint32) s->img_n*2) return stbi__err("bad tRNS len","Corrupt PNG"); has_trans = 1; if (z->depth == 16) { - for (k = 0; k < s->img_n; ++k) tc16[k] = stbi__get16be(s); // copy the values as-is + for (k = 0; k < s->img_n; ++k) tc16[k] = (stbi__uint16)stbi__get16be(s); // copy the values as-is } else { for (k = 0; k < s->img_n; ++k) tc[k] = (stbi_uc)(stbi__get16be(s) & 255) * stbi__depth_scale_table[z->depth]; // non 8-bit images will be larger } @@ -5079,16 +5079,16 @@ errorEnd: // read 16bit value and convert to 24bit RGB void stbi__tga_read_rgb16(stbi__context *s, stbi_uc* out) { - stbi__uint16 px = stbi__get16le(s); + stbi__uint16 px = (stbi__uint16)stbi__get16le(s); stbi__uint16 fiveBitMask = 31; // we have 3 channels with 5bits each int r = (px >> 10) & fiveBitMask; int g = (px >> 5) & fiveBitMask; int b = px & fiveBitMask; // Note that this saves the data in RGB(A) order, so it doesn't need to be swapped later - out[0] = (r * 255)/31; - out[1] = (g * 255)/31; - out[2] = (b * 255)/31; + out[0] = (stbi_uc)(r * 255)/31; + out[1] = (stbi_uc)(g * 255)/31; + out[2] = (stbi_uc)(b * 255)/31; // some people claim that the most significant bit might be used for alpha // (possibly if an alpha-bit is set in the "image descriptor byte") diff --git a/code/io/joy-sdl.cpp b/code/io/joy-sdl.cpp index f8713327ec..68f06918d2 100644 --- a/code/io/joy-sdl.cpp +++ b/code/io/joy-sdl.cpp @@ -88,7 +88,7 @@ SCP_string getJoystickGUID(SDL_Joystick *stick) bool isCurrentJoystick(Joystick* testStick) { auto currentGUID = os_config_read_string(nullptr, "CurrentJoystickGUID", nullptr); - auto currentId = os_config_read_uint(nullptr, "CurrentJoystick", 0); + auto currentId = (int)os_config_read_uint(nullptr, "CurrentJoystick", 0); if ((currentGUID == nullptr) || !strcmp(currentGUID, "")) { // Only use the id diff --git a/code/parse/lua.cpp b/code/parse/lua.cpp index 6591a2f22a..c9ddef976c 100644 --- a/code/parse/lua.cpp +++ b/code/parse/lua.cpp @@ -10741,7 +10741,7 @@ ADE_VIRTVAR(DestroyedByWeapon, l_Weapon, "boolean", "Whether weapon was destroye wp->weapon_flags.set(Weapon::Weapon_Flags::Destroyed_by_weapon, b); } - return ade_set_args(L, "b", (wp->weapon_flags[Weapon::Weapon_Flags::Destroyed_by_weapon]) > 0); + return ade_set_args(L, "b", wp->weapon_flags[Weapon::Weapon_Flags::Destroyed_by_weapon]); } ADE_VIRTVAR(LifeLeft, l_Weapon, "number", "Weapon life left (in seconds)", "number", "Life left (seconds) or 0 if weapon handle is invalid") diff --git a/code/parse/parselo.cpp b/code/parse/parselo.cpp index c7a14f974f..4da4a3c4c4 100644 --- a/code/parse/parselo.cpp +++ b/code/parse/parselo.cpp @@ -1115,7 +1115,7 @@ int get_string(char *str, int max) { auto len = strcspn(Mp + 1, "\""); - if (max >= 0 && len >= max) + if (max >= 0 && len >= (size_t)max) error_display(0, "String too long. Length = " SIZE_T_ARG ". Max is %i.\n", len, max); strncpy(str, Mp + 1, len); diff --git a/code/pcxutils/pcxutils.cpp b/code/pcxutils/pcxutils.cpp index c08c798599..a59064b4e9 100644 --- a/code/pcxutils/pcxutils.cpp +++ b/code/pcxutils/pcxutils.cpp @@ -454,7 +454,6 @@ int pcx_encode_line(ubyte *inBuff, int inLen, FILE * fp) int pcx_write_bitmap( const char * real_filename, int w, int h, ubyte ** row_ptrs, ubyte * palette ) { - int retval; int i; ubyte data; PCXHeader header; @@ -506,7 +505,7 @@ int pcx_write_bitmap( const char * real_filename, int w, int h, ubyte ** row_ptr // for (i=0; i<768; i++ ) // palette[i] <<= 2; - retval = fwrite( palette, 768, 1, PCXfile ); + auto retval = fwrite( palette, 768, 1, PCXfile ); // for (i=0; i<768; i++ ) // palette[i] >>= 2; diff --git a/code/pilotfile/JSONFileHandler.cpp b/code/pilotfile/JSONFileHandler.cpp index 50c7c276e4..fb206d985e 100644 --- a/code/pilotfile/JSONFileHandler.cpp +++ b/code/pilotfile/JSONFileHandler.cpp @@ -5,7 +5,7 @@ namespace { int json_write_callback(const char *buffer, size_t size, void *data) { CFILE* cfp = (CFILE*)data; - if (cfwrite(buffer, 1, (int)size, cfp) != size) { + if ((size_t)cfwrite(buffer, 1, (int)size, cfp) != size) { return -1; // Error } else { return 0; // Success diff --git a/code/pilotfile/csg_convert.cpp b/code/pilotfile/csg_convert.cpp index 8226150136..11e196baa9 100644 --- a/code/pilotfile/csg_convert.cpp +++ b/code/pilotfile/csg_convert.cpp @@ -788,7 +788,7 @@ void pilotfile_convert::csg_export_missions() // goals size_t count = csg->missions[idx].goals.size(); - cfwrite_int(count, cfp); + cfwrite_int((int)count, cfp); for (size_t j = 0; j < count; j++) { cfwrite_string_len(csg->missions[idx].goals[j].name, cfp); @@ -797,7 +797,7 @@ void pilotfile_convert::csg_export_missions() // events count = csg->missions[idx].events.size(); - cfwrite_int(count, cfp); + cfwrite_int((int)count, cfp); for (size_t j = 0; j < count; j++) { cfwrite_string_len(csg->missions[idx].events[j].name, cfp); @@ -806,7 +806,7 @@ void pilotfile_convert::csg_export_missions() // variables count = csg->missions[idx].variables.size(); - cfwrite_int(count, cfp); + cfwrite_int((int)count, cfp); for (size_t j = 0; j < count; j++) { cfwrite_int(csg->missions[idx].variables[j].type, cfp); diff --git a/code/pilotfile/pilotfile.cpp b/code/pilotfile/pilotfile.cpp index 72faa18c3b..436ea1ccf7 100644 --- a/code/pilotfile/pilotfile.cpp +++ b/code/pilotfile/pilotfile.cpp @@ -55,11 +55,11 @@ void pilotfile::endSection() if (section_size) { // go back to section size in file and write proper value - cfseek(cfp, cur - section_size - sizeof(int), CF_SEEK_SET); + cfseek(cfp, (int)(cur - section_size - sizeof(int)), CF_SEEK_SET); cfwrite_int((int)section_size, cfp); // go back to previous location for next section - cfseek(cfp, cur, CF_SEEK_SET); + cfseek(cfp, (int)cur, CF_SEEK_SET); } } diff --git a/code/pilotfile/pilotfile_convert.cpp b/code/pilotfile/pilotfile_convert.cpp index 512dedd7d3..f524ced022 100644 --- a/code/pilotfile/pilotfile_convert.cpp +++ b/code/pilotfile/pilotfile_convert.cpp @@ -57,11 +57,11 @@ void pilotfile_convert::endSection() if (section_size) { // go back to section size in file and write proper value - cfseek(cfp, cur - section_size - sizeof(int), CF_SEEK_SET); + cfseek(cfp, (int)(cur - section_size - sizeof(int)), CF_SEEK_SET); cfwrite_int((int)section_size, cfp); // go back to previous location for next section - cfseek(cfp, cur, CF_SEEK_SET); + cfseek(cfp, (int)cur, CF_SEEK_SET); } } @@ -104,7 +104,7 @@ void convert_pilot_files() } // don't convert enough pilots to exceed the pilot limit - max_convert = MAX_PILOTS - existing.size(); + max_convert = MAX_PILOTS - (int)existing.size(); // if everything is already converted then bail // also bail if MAX_PILOTS (or more!) already exist diff --git a/code/pilotfile/plr.cpp b/code/pilotfile/plr.cpp index c233e0c240..d8291e4784 100644 --- a/code/pilotfile/plr.cpp +++ b/code/pilotfile/plr.cpp @@ -919,7 +919,7 @@ bool pilotfile::load_player(const char *callsign, player *_p) size_t offset_pos = (start_pos + section_size) - cftell(cfp); if (offset_pos) { - cfseek(cfp, offset_pos, CF_SEEK_CUR); + cfseek(cfp, (int)offset_pos, CF_SEEK_CUR); mprintf(("PLR => WARNING: Advancing to the next section. " SIZE_T_ARG " bytes were skipped!\n", offset_pos)); } } @@ -1109,7 +1109,7 @@ bool pilotfile::verify(const char *fname, int *rank, char *valid_language) if (offset_pos) { mprintf(("PLR => Warning: (0x%04x) Short read, information may have been lost!\n", section_id)); - cfseek(cfp, offset_pos, CF_SEEK_CUR); + cfseek(cfp, (int)offset_pos, CF_SEEK_CUR); } } diff --git a/code/pngutils/pngutils.cpp b/code/pngutils/pngutils.cpp index 1ffa277e1f..6f861da443 100644 --- a/code/pngutils/pngutils.cpp +++ b/code/pngutils/pngutils.cpp @@ -22,7 +22,7 @@ void png_scp_read_data(png_structp png_ptr, png_bytep data, png_size_t length) /* fread() returns 0 on error, so it is OK to store this in a png_size_t * instead of an int, which is what fread() actually returns. */ - check = (png_size_t)cfread(data, (png_size_t)1, length, png_file); + check = (png_size_t)cfread(data, (png_size_t)1, (int)length, png_file); if (check != length) png_error(png_ptr, "Read Error"); } @@ -140,7 +140,7 @@ int png_read_bitmap(const char *real_filename, ubyte *image_data, int *bpp, int png_infop info_ptr; png_structp png_ptr; png_bytepp row_pointers; - unsigned int i, len; + unsigned int i; png_file = NULL; @@ -192,7 +192,7 @@ int png_read_bitmap(const char *real_filename, ubyte *image_data, int *bpp, int png_set_read_fn(png_ptr, &png_file, png_scp_read_data); png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_BGR | PNG_TRANSFORM_EXPAND | PNG_TRANSFORM_STRIP_16, NULL); - len = png_get_rowbytes(png_ptr, info_ptr); + auto len = png_get_rowbytes(png_ptr, info_ptr); row_pointers = png_get_rows(png_ptr, info_ptr); @@ -485,7 +485,7 @@ void apng_ani::_process_chunk() if (_reading) { anim_time+= frame_delay; - _frame_offsets.push_back(_offset); + _frame_offsets.push_back((int)_offset); } else { if (_got_IDAT && _processing_start()) { diff --git a/code/popup/popup.cpp b/code/popup/popup.cpp index 7759efc6f1..980bae9343 100644 --- a/code/popup/popup.cpp +++ b/code/popup/popup.cpp @@ -953,7 +953,7 @@ void popup_maybe_assign_keypress(popup_info *pi, int n, char *str) pi->keypress[n]=-1; pi->shortcut_index[n]=-1; - len=strlen(str)+1; + len=(int)strlen(str)+1; pi->button_text[n] = (char*)vm_malloc(len); memset(pi->button_text[n], 0, len); diff --git a/code/ship/shield.cpp b/code/ship/shield.cpp index b25f9ef3d9..f572a80748 100644 --- a/code/ship/shield.cpp +++ b/code/ship/shield.cpp @@ -840,7 +840,7 @@ void create_shield_explosion_all(object *objp) shipp = &Ships[num]; count = shipp->shield_hits; - objnum = objp-Objects; + objnum = OBJ_INDEX(objp); for (i=0; i= 0) { sip->damage_lightning_type = j; } else { @@ -2905,7 +2904,7 @@ int parse_ship_values(ship_info* sip, const bool is_template, const bool first_t if(optional_string("$Warpin type:")) { stuff_string(buf, F_NAME, SHIP_MULTITEXT_LENGTH); - j = warptype_match(buf); + auto j = warptype_match(buf); if(j >= 0) { sip->warpin_type = j; } else { @@ -2957,7 +2956,7 @@ int parse_ship_values(ship_info* sip, const bool is_template, const bool first_t if(optional_string("$Warpout type:")) { stuff_string(buf, F_NAME, SHIP_MULTITEXT_LENGTH); - j = warptype_match(buf); + auto j = warptype_match(buf); if(j >= 0) { sip->warpout_type = j; } else { @@ -3213,7 +3212,7 @@ int parse_ship_values(ship_info* sip, const bool is_template, const bool first_t sip->shield_point_augment_ctrls[LEFT_QUAD] = -1; sip->shield_point_augment_ctrls[RIGHT_QUAD] = -1; - for (i = 0; i < num_strings; i++) { + for (auto i = 0; i < num_strings; i++) { const char *str = ctrl_strings[i].c_str(); if (!stricmp(str, "front")) @@ -3372,7 +3371,7 @@ int parse_ship_values(ship_info* sip, const bool is_template, const bool first_t sip->flags.set(Ship::Info_Flags::Draw_weapon_models, draw_weapon_models); } - for (i = 0; i < num_strings; i++) + for (auto i = 0; i < num_strings; i++) { // get ship type from ship flags char *ship_type = ship_strings[i]; @@ -3431,9 +3430,9 @@ int parse_ship_values(ship_info* sip, const bool is_template, const bool first_t memset(sip->allowed_weapons, 0, sizeof(int) * MAX_WEAPON_TYPES); // copy to regular allowed_weapons array - for (i = 0; i < MAX_SHIP_WEAPONS; i++) + for (auto i = 0; i < MAX_SHIP_WEAPONS; i++) { - for (j = 0; j < Num_weapon_types; j++) + for (auto j = 0; j < Num_weapon_types; j++) { if (sip->allowed_bank_restricted_weapons[i][j] & REGULAR_WEAPON) sip->allowed_weapons[j] |= REGULAR_WEAPON; @@ -3974,12 +3973,12 @@ int parse_ship_values(ship_info* sip, const bool is_template, const bool first_t continue; } SCP_string banktoken; - int start = -1; - int end = -1; + size_t start = 0; + size_t end; do { - end = banks.find_first_of(',', ++start); + end = banks.find_first_of(',', start); banktoken = banks.substr(start, end); - start = end; + start = end + 1; size_t fromtopos; fromtopos = banktoken.find_first_of('-'); @@ -3997,7 +3996,7 @@ int parse_ship_values(ship_info* sip, const bool is_template, const bool first_t int bank = atoi(banktoken.data()) - 1; sip->glowpoint_bank_override_map[bank] = (void*)(&(*gpo)); } - } while(start!=-1); + } while(end !=SCP_string::npos); } } @@ -4050,14 +4049,15 @@ int parse_ship_values(ship_info* sip, const bool is_template, const bool first_t if (optional_string("$Target Priority Groups:") ) { SCP_vector target_group_strings; int num_strings = stuff_string_list(target_group_strings); - int num_groups = Ai_tp_list.size(); + size_t num_groups = Ai_tp_list.size(); bool override_strings = false; if (optional_string("+Override")) { override_strings = true; } - for(j = 0; j < num_strings; j++) { + for(auto j = 0; j < num_strings; j++) { + size_t i; for(i = 0; i < num_groups; i++) { if ( !stricmp(target_group_strings[j].c_str(), Ai_tp_list[i].name) ) { //so now the string from the list above as well as the ai priority group name match @@ -4069,7 +4069,7 @@ int parse_ship_values(ship_info* sip, const bool is_template, const bool first_t for (auto it = Ship_info.cbegin(); it != Ship_info.cend(); ++it) { //find the index number of the current ship info type if (it->name == sip->name) { - Ai_tp_list[i].ship_class.push_back(std::distance(Ship_info.cbegin(), it)); + Ai_tp_list[i].ship_class.push_back((int)std::distance(Ship_info.cbegin(), it)); break; } } @@ -4124,14 +4124,14 @@ int parse_ship_values(ship_info* sip, const bool is_template, const bool first_t int n_subsystems = 0; int cont_flag = 1; model_subsystem subsystems[MAX_MODEL_SUBSYSTEMS]; // see model.h for max_model_subsystems - for (i=0; in_subsystems; i++) { + for(auto i=0; i < sip->n_subsystems; i++) { hull_percentage_of_hits -= sip->subsystems[i].max_subsys_strength / sip->max_hull_strength; } @@ -4152,7 +4152,7 @@ int parse_ship_values(ship_info* sip, const bool is_template, const bool first_t required_string("$Subsystem:"); stuff_string(name_tmp, F_NAME, sizeof(name_tmp), ","); Mp++; - for(i = 0;i < sip->n_subsystems; i++) + for(auto i = 0;i < sip->n_subsystems; i++) { if(!subsystem_stricmp(sip->subsystems[i].subobj_name, name_tmp)) sp = &sip->subsystems[i]; @@ -4176,12 +4176,12 @@ int parse_ship_values(ship_info* sip, const bool is_template, const bool first_t memset(sp->alt_sub_name, 0, sizeof(sp->alt_sub_name)); memset(sp->alt_dmg_sub_name, 0, sizeof(sp->alt_dmg_sub_name)); - for (i=0; iprimary_banks[i] = -1; sp->primary_bank_capacity[i] = 0; } - for (i=0; isecondary_banks[i] = -1; sp->secondary_bank_capacity[i] = 0; } @@ -4209,7 +4209,7 @@ int parse_ship_values(ship_info* sip, const bool is_template, const bool first_t sp->turret_reset_delay = 2000; sp->num_target_priorities = 0; - for (i = 0; i < 32; i++) { + for (auto i = 0; i < 32; i++) { sp->target_priority[i] = -1; } sp->optimum_range = 0.0f; @@ -4343,9 +4343,10 @@ int parse_ship_values(ship_info* sip, const bool is_template, const bool first_t if (num_strings > 32) num_strings = 32; - int num_groups = Ai_tp_list.size(); + int num_groups = (int)Ai_tp_list.size(); - for(i = 0; i < num_strings; i++) { + for(auto i = 0; i < num_strings; i++) { + int j; for(j = 0; j < num_groups; j++) { if ( !stricmp(Ai_tp_list[j].name, tgt_priorities[i].c_str())) { sp->target_priority[i] = j; @@ -4658,7 +4659,7 @@ int parse_ship_values(ship_info* sip, const bool is_template, const bool first_t Assert(sip->subsystems != NULL); } - for ( i = 0; i < n_subsystems; i++ ){ + for ( int i = 0; i < n_subsystems; i++ ){ sip->subsystems[orig_n_subsystems+i] = subsystems[i]; } @@ -4730,15 +4731,15 @@ void parse_ship_type() if (optional_string("$Target Priority Groups:") ) { SCP_vector target_group_strings; int num_strings = stuff_string_list(target_group_strings); - int num_groups = Ai_tp_list.size(); - int i, j; + auto num_groups = Ai_tp_list.size(); bool override_strings = false; if (optional_string("+Override")) { override_strings = true; } - for(j = 0; j < num_strings; j++) { + for(auto j = 0; j < num_strings; j++) { + size_t i; for(i = 0; i < num_groups; i++) { if ( !stricmp(target_group_strings[j].c_str(), Ai_tp_list[i].name) ) { //so now the string from the list above as well as the ai priority group name match @@ -4959,7 +4960,7 @@ int get_default_player_ship_index() for (auto it = Ship_info.cbegin(); it != Ship_info.cend(); ++it) { if (stricmp(default_player_ship, it->name) == 0) - return std::distance(Ship_info.cbegin(), it); + return (int)std::distance(Ship_info.cbegin(), it); } return 0; } else @@ -5089,7 +5090,7 @@ bool ballistic_possible_for_this_ship(const ship_info *sip) */ void ship_parse_post_cleanup() { - int i, j; + int j; char name_tmp[NAME_LENGTH]; for (auto sip = Ship_info.begin(); sip != Ship_info.end(); ++sip) @@ -5185,10 +5186,10 @@ void ship_parse_post_cleanup() } // check also target groups here - int n_tgt_groups = Ai_tp_list.size(); + size_t n_tgt_groups = Ai_tp_list.size(); if (n_tgt_groups > 0) { - for(i = 0; i < n_tgt_groups; i++) { + for(size_t i = 0; i < n_tgt_groups; i++) { if (!(Ai_tp_list[i].obj_flags.any_set() || Ai_tp_list[i].sif_flags.any_set() || Ai_tp_list[i].wif_flags.any_set())) { //had none of these, check next if (Ai_tp_list[i].obj_type == -1) { @@ -6077,7 +6078,7 @@ void ship_set(int ship_index, int objnum, int ship_type) } if (sip->flags[Ship::Info_Flags::Model_point_shields]) { - objp->n_quadrants = pm->shield_points.size(); + objp->n_quadrants = (int)pm->shield_points.size(); shipp->shield_points = pm->shield_points; objp->shield_quadrant.resize(objp->n_quadrants); } @@ -6683,7 +6684,7 @@ int subsys_set(int objnum, int ignore_subsys_info) // Allocate a triggered rotation instance if we need it if (model_system->flags[Model::Subsystem_Flags::Triggered]) { - ship_system->triggered_rotation_index = Triggered_rotations.size(); + ship_system->triggered_rotation_index = (int)Triggered_rotations.size(); triggered_rotation tr; Triggered_rotations.push_back(tr); } @@ -9366,7 +9367,7 @@ int ship_create(matrix *orient, vec3d *pos, int ship_type, char *ship_name) sprintf(suffix, NOX(" %d"), n); // ensure complete ship name doesn't overflow the buffer - int name_len = MIN(NAME_LENGTH - strlen(suffix) - 1, strlen(Ship_info[ship_type].name)); + auto name_len = std::min(NAME_LENGTH - strlen(suffix) - 1, strlen(Ship_info[ship_type].name)); Assert(name_len > 0); strncpy(shipp->ship_name, Ship_info[ship_type].name, name_len); @@ -9527,7 +9528,7 @@ void ship_model_change(int n, int ship_type) pm->detail_depth[i] = (i < sip->num_detail_levels) ? i2fl(sip->detail_distance[i]) : 0.0f; if (sip->flags[Ship::Info_Flags::Model_point_shields]) { - objp->n_quadrants = pm->shield_points.size(); + objp->n_quadrants = (int)pm->shield_points.size(); sp->shield_points = pm->shield_points; } else { objp->n_quadrants = DEFAULT_SHIELD_SECTIONS; @@ -11239,7 +11240,7 @@ int ship_fire_primary(object * obj, int stream_weapons, int force) if (winfo_p->wi_flags[Weapon::Info_Flags::Apply_recoil]){ vec3d avg_firepoint; - vm_vec_avg_n(&avg_firepoint, current_firepoint, firepoint_list); + vm_vec_avg_n(&avg_firepoint, (int)current_firepoint, firepoint_list); ship_apply_whack(&total_impulse, &avg_firepoint, obj); delete[] firepoint_list; @@ -12553,7 +12554,7 @@ int ship_info_lookup_sub(const char *token) { for (auto it = Ship_info.cbegin(); it != Ship_info.cend(); ++it) if (!stricmp(token, it->name)) - return std::distance(Ship_info.cbegin(), it); + return (int)std::distance(Ship_info.cbegin(), it); return -1; } @@ -12565,7 +12566,7 @@ int ship_template_lookup(const char *token) { for ( auto it = Ship_templates.cbegin(); it != Ship_templates.cend(); ++it ) { if ( !stricmp(token, it->name) ) { - return std::distance(Ship_templates.cbegin(), it); + return (int)std::distance(Ship_templates.cbegin(), it); } } return -1; @@ -12731,10 +12732,10 @@ int ship_type_name_lookup(const char *name) } //Look through Ship_types array - uint max_size = Ship_types.size(); - for(uint idx=0; idx < max_size; idx++){ + size_t max_size = Ship_types.size(); + for(size_t idx=0; idx < max_size; idx++){ if(!stricmp(name, Ship_types[idx].name)){ - return idx; + return (int)idx; } } // couldn't find it @@ -15439,13 +15440,13 @@ void awacs_maybe_ask_for_help(ship *sp, int multi_team_filter) int message = -1; objp = &Objects[sp->objnum]; - if ( objp->hull_strength < ( (AWACS_HELP_HULL_LOW + 0.01f *(static_rand(objp-Objects) & 5)) * sp->ship_max_hull_strength) ) { + if ( objp->hull_strength < ( (AWACS_HELP_HULL_LOW + 0.01f *(static_rand(OBJ_INDEX(objp)) & 5)) * sp->ship_max_hull_strength) ) { // awacs ship below 25 + (0-4) % if (!(sp->awacs_warning_flag[Ship::Awacs_Warning_Flags::Warn_25])) { message = MESSAGE_AWACS_25; sp->awacs_warning_flag.set(Ship::Awacs_Warning_Flags::Warn_25); } - } else if ( objp->hull_strength < ( (AWACS_HELP_HULL_HI + 0.01f*(static_rand(objp-Objects) & 5)) * sp->ship_max_hull_strength) ) { + } else if ( objp->hull_strength < ( (AWACS_HELP_HULL_HI + 0.01f*(static_rand(OBJ_INDEX(objp)) & 5)) * sp->ship_max_hull_strength) ) { // awacs ship below 75 + (0-4) % if (!(sp->awacs_warning_flag[Ship::Awacs_Warning_Flags::Warn_75])) { message = MESSAGE_AWACS_75; @@ -16122,7 +16123,7 @@ void ship_page_in() for (auto sip = Ship_info.begin(); sip != Ship_info.end(); ++sip) { if (sip->flags[Ship::Info_Flags::Support]) { nprintf(( "Paging", "Found support ship '%s'\n", sip->name )); - i = std::distance(Ship_info.begin(), sip); + i = (int)std::distance(Ship_info.begin(), sip); ship_class_used[i]++; num_subsystems_needed += sip->n_subsystems; @@ -16248,7 +16249,7 @@ void ship_page_in() model_previously_loaded = it->model_num; if ((sip->n_subsystems > 0) && (sip->subsystems[0].model_num > -1)) { - ship_previously_loaded = std::distance(Ship_info.begin(), it); + ship_previously_loaded = (int)std::distance(Ship_info.begin(), it); // It is possible in some cases for sip->model_num to change, and for subsystems->model_num // to still point to the old model index; this makes sure it doesn't happen. -zookeeper @@ -16341,12 +16342,12 @@ void ship_page_in() // Page in the shockwave stuff. -C shockwave_create_info_load(&sip->shockwave); if(sip->explosion_bitmap_anims.size() > 0) { - int num_fireballs = sip->explosion_bitmap_anims.size(); + int num_fireballs = (int)sip->explosion_bitmap_anims.size(); for(j = 0; j < num_fireballs; j++){ fireball_used[sip->explosion_bitmap_anims[j]] = 1; } } else if(sip->class_type >= 0 && Ship_types[sip->class_type].explosion_bitmap_anims.size() > 0) { - int num_fireballs = Ship_types[sip->class_type].explosion_bitmap_anims.size(); + int num_fireballs = (int)Ship_types[sip->class_type].explosion_bitmap_anims.size(); for(j = 0; j < num_fireballs; j++){ fireball_used[Ship_types[sip->class_type].explosion_bitmap_anims[j]] = 1; } @@ -16897,7 +16898,7 @@ int ship_get_texture(int bitmap) // check all ship types for (auto it = Ship_info.cbegin(); it != Ship_info.cend(); ++it) { if ((it->model_num >= 0) && model_find_texture(it->model_num, bitmap) == 1) { - return std::distance(Ship_info.cbegin(), it); + return (int)std::distance(Ship_info.cbegin(), it); } } @@ -17532,7 +17533,7 @@ int damage_type_add(char *name) } Damage_types.push_back(dts); - return Damage_types.size()-1; + return (int)(Damage_types.size() - 1); } void ArmorDamageType::clear() @@ -17699,12 +17700,11 @@ float ArmorType::GetDamage(float damage_applied, int in_damage_type_idx, float d } //Initialize vars - uint i,num; ArmorDamageType *adtp = NULL; //Find the entry in the weapon that corresponds to the given weapon damage type - num = DamageTypes.size(); - for(i = 0; i < num; i++) + size_t num = DamageTypes.size(); + for(size_t i = 0; i < num; i++) { if(DamageTypes[i].DamageTypeIndex == in_damage_type_idx) { @@ -17734,7 +17734,7 @@ float ArmorType::GetDamage(float damage_applied, int in_damage_type_idx, float d bool using_constant = false; // set storage locations to zero - for (i = 0; i < AT_NUM_STORAGE_LOCATIONS; i++) { + for (size_t i = 0; i < AT_NUM_STORAGE_LOCATIONS; i++) { storage[i]=0.0f; } @@ -17746,7 +17746,7 @@ float ArmorType::GetDamage(float damage_applied, int in_damage_type_idx, float d // user may want to use base damage as a constant base_damage = damage_applied; // LOOP! - for (i = 0; i < num; i++) { + for (size_t i = 0; i < num; i++) { storage_idx = adtp->altArguments[i]; //Set curr_arg // use storage index at +Stored Value: @@ -17884,12 +17884,11 @@ float ArmorType::GetShieldPiercePCT(int damage_type_idx) return 0.0f; //Initialize vars - uint i,num; ArmorDamageType *adtp = NULL; //Find the entry in the weapon that corresponds to the given weapon damage type - num = DamageTypes.size(); - for(i = 0; i < num; i++) + size_t num = DamageTypes.size(); + for(size_t i = 0; i < num; i++) { if(DamageTypes[i].DamageTypeIndex == damage_type_idx) { @@ -17910,12 +17909,11 @@ int ArmorType::GetPiercingType(int damage_type_idx) return 0; //Initialize vars - uint i,num; ArmorDamageType *adtp = NULL; //Find the entry in the weapon that corresponds to the given weapon damage type - num = DamageTypes.size(); - for(i = 0; i < num; i++) + size_t num = DamageTypes.size(); + for(size_t i = 0; i < num; i++) { if(DamageTypes[i].DamageTypeIndex == damage_type_idx) { @@ -17936,12 +17934,11 @@ float ArmorType::GetPiercingLimit(int damage_type_idx) return 0.0f; //Initialize vars - uint i,num; ArmorDamageType *adtp = NULL; //Find the entry in the weapon that corresponds to the given weapon damage type - num = DamageTypes.size(); - for(i = 0; i < num; i++) + size_t num = DamageTypes.size(); + for(size_t i = 0; i < num; i++) { if(DamageTypes[i].DamageTypeIndex == damage_type_idx) { @@ -17960,9 +17957,9 @@ float ArmorType::GetPiercingLimit(int damage_type_idx) ArmorType::ArmorType(char* in_name) { - uint len = strlen(in_name); + auto len = strlen(in_name); if(len >= NAME_LENGTH) { - Warning(LOCATION, "Armor name %s is %d characters too long, and will be truncated", in_name, len - NAME_LENGTH); + Warning(LOCATION, "Armor name %s is " SIZE_T_ARG " characters too long, and will be truncated", in_name, len - NAME_LENGTH); } strncpy(Name, in_name, NAME_LENGTH-1); @@ -18101,12 +18098,11 @@ void ArmorType::ParseData() int armor_type_get_idx(char* name) { - int i, num; - num = Armor_types.size(); - for(i = 0; i < num; i++) + auto num = Armor_types.size(); + for(size_t i = 0; i < num; i++) { if(Armor_types[i].IsName(name)) - return i; + return (int)i; } //Didn't find anything. @@ -18178,7 +18174,7 @@ void armor_init() void parse_ai_target_priorities() { int i, j, num_strings; - int n_entries = Ai_tp_list.size(); + int n_entries = (int)Ai_tp_list.size(); SCP_vector temp_strings; bool first_time = false; @@ -18331,7 +18327,7 @@ void parse_weapon_targeting_priorities() if (num_strings > 32) num_strings = 32; - int num_groups = Ai_tp_list.size(); + int num_groups = (int)Ai_tp_list.size(); for(i = 0; i < num_strings; i++) { for(j = 0; j < num_groups; j++) { diff --git a/code/ship/shipfx.cpp b/code/ship/shipfx.cpp index b8d473025e..5cad5534e2 100644 --- a/code/ship/shipfx.cpp +++ b/code/ship/shipfx.cpp @@ -1681,7 +1681,7 @@ static int get_split_ship() Split_ships.push_back(addition); - return (Split_ships.size() - 1); + return (int)(Split_ships.size() - 1); } static void maybe_fireball_wipe(clip_ship* half_ship, int* sound_handle); diff --git a/code/sound/audiostr.cpp b/code/sound/audiostr.cpp index 390307b164..b17aaf78e4 100644 --- a/code/sound/audiostr.cpp +++ b/code/sound/audiostr.cpp @@ -2,7 +2,9 @@ #ifdef _WIN32 #define VC_EXTRALEAN +#ifndef STRICT #define STRICT +#endif #include #include diff --git a/code/sound/ogg/ogg.cpp b/code/sound/ogg/ogg.cpp index 6f32acae62..6243439014 100644 --- a/code/sound/ogg/ogg.cpp +++ b/code/sound/ogg/ogg.cpp @@ -16,7 +16,7 @@ ov_callbacks cfile_callbacks; //Encapsulation funcs to please the almighty ov_callbacks struct size_t ogg_cfread(void *buf, size_t elsize, size_t elnem, void* cfile) { - return cfread(buf, elsize, elnem, (CFILE*)cfile); + return (size_t)cfread(buf, (int)elsize, (int)elnem, (CFILE*)cfile); } int ogg_cfseek(void* cfile, ogg_int64_t offset, int where) diff --git a/code/sound/openal.cpp b/code/sound/openal.cpp index effb1c778d..4bf826d0db 100644 --- a/code/sound/openal.cpp +++ b/code/sound/openal.cpp @@ -134,7 +134,7 @@ static void find_playback_device() } const char *str_list = all_devices; - int ext_length = 0; + size_t ext_length = 0; if ( (str_list != NULL) && ((ext_length = strlen(str_list)) > 0) ) { while (ext_length) { @@ -259,7 +259,7 @@ static void find_capture_device() const char *all_devices = (const char*) alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER); const char *str_list = all_devices; - int ext_length = 0; + size_t ext_length = 0; if ( (str_list != NULL) && ((ext_length = strlen(str_list)) > 0) ) { while (ext_length) { diff --git a/code/sound/sound.cpp b/code/sound/sound.cpp index fe73ffefe7..221c9c639b 100644 --- a/code/sound/sound.cpp +++ b/code/sound/sound.cpp @@ -448,7 +448,7 @@ int snd_unload( int n ) void snd_unload_all() { while ( !Sounds.empty() ) { - snd_unload( Sounds.size()-1 ); + snd_unload( (int)(Sounds.size()-1) ); } } diff --git a/code/sound/speech.cpp b/code/sound/speech.cpp index b442ebde48..abf664c3a8 100644 --- a/code/sound/speech.cpp +++ b/code/sound/speech.cpp @@ -106,15 +106,15 @@ bool speech_play(const char *text) } #ifdef _WIN32 - int len = strlen(text); + size_t len = strlen(text); wchar_t Conversion_buffer[MAX_SPEECH_CHAR_LEN]; if(len > (MAX_SPEECH_CHAR_LEN - 1)) { len = MAX_SPEECH_CHAR_LEN - 1; } - int count = 0; - for(int i = 0; i < len; i++) { + size_t count = 0; + for(size_t i = 0; i < len; i++) { if(text[i] == '$') { i++; continue; diff --git a/code/sound/speech.h b/code/sound/speech.h index 35ddf0f55a..b78bc91755 100644 --- a/code/sound/speech.h +++ b/code/sound/speech.h @@ -12,7 +12,7 @@ #if FS2_SPEECH -const int MAX_SPEECH_CHAR_LEN = 10000; +const size_t MAX_SPEECH_CHAR_LEN = 10000; bool speech_init(); void speech_deinit(); diff --git a/code/starfield/starfield.cpp b/code/starfield/starfield.cpp index 6965af368e..2ba7980c47 100644 --- a/code/starfield/starfield.cpp +++ b/code/starfield/starfield.cpp @@ -2173,7 +2173,7 @@ int stars_add_sun_entry(starfield_list_entry *sun_ptr) // ... or add a new one Suns.push_back(sbi); - return Suns.size() - 1; + return (int)(Suns.size() - 1); } // add an instance for a starfield bitmap (something actually used in a mission) @@ -2230,9 +2230,9 @@ int stars_add_bitmap_entry(starfield_list_entry *sle) // ... or add a new one Starfield_bitmap_instances.push_back(sbi); - starfield_create_bitmap_buffer(Starfield_bitmap_instances.size() - 1); + starfield_create_bitmap_buffer((int)(Starfield_bitmap_instances.size() - 1)); - return Starfield_bitmap_instances.size() - 1; + return (int)(Starfield_bitmap_instances.size() - 1); } // get the number of entries that each vector contains diff --git a/code/tgautils/tgautils.cpp b/code/tgautils/tgautils.cpp index f8563dc07d..a2e81eba85 100644 --- a/code/tgautils/tgautils.cpp +++ b/code/tgautils/tgautils.cpp @@ -260,7 +260,7 @@ int targa_compress(char *out, char *in, int outsize, int pixsize, int bytecount) ++flagbyte; flagbyte += targa_copy_data(flagbyte, copyloc, pixcount, pixsize, outsize); } - return(flagbyte-out); + return (int)(flagbyte-out); } // Reads a pixel of the specified bytes_per_pixel into memory and @@ -489,7 +489,7 @@ int targa_uncompress( ubyte *dst, ubyte *src, int bitmap_width, int bytes_per_pi Assert( pixel_count == bitmap_width ); - return src_pixels - src; + return (int)(src_pixels - src); } diff --git a/code/weapon/muzzleflash.cpp b/code/weapon/muzzleflash.cpp index f1a8ca6073..3fc40230ef 100644 --- a/code/weapon/muzzleflash.cpp +++ b/code/weapon/muzzleflash.cpp @@ -185,7 +185,7 @@ void mflash_page_in(bool load_all) continue; // blobs - int original_num_blobs = Mflash_info[i].blobs.size(); + size_t original_num_blobs = Mflash_info[i].blobs.size(); int original_idx = 1; for ( idx = 0; idx < Mflash_info[i].blobs.size(); ) { mflash_blob_info* mfbip = &Mflash_info[i].blobs[idx]; @@ -195,7 +195,7 @@ void mflash_page_in(bool load_all) ++idx; } else { - Warning(LOCATION, "Muzleflash \"%s\", blob [%d/%d]\nMuzzleflash blob \"%s\" not found! Deleting.", + Warning(LOCATION, "Muzleflash \"%s\", blob [%d/" SIZE_T_ARG "]\nMuzzleflash blob \"%s\" not found! Deleting.", Mflash_info[i].name, original_idx, original_num_blobs, Mflash_info[i].blobs[idx].name); Mflash_info[i].blobs.erase( Mflash_info[i].blobs.begin() + idx ); } diff --git a/code/weapon/shockwave.cpp b/code/weapon/shockwave.cpp index e10f39c55d..c3152e8b23 100644 --- a/code/weapon/shockwave.cpp +++ b/code/weapon/shockwave.cpp @@ -447,7 +447,7 @@ int shockwave_load(char *s_name, bool shock_3D) for (i = 0; i < Shockwave_info.size(); i++) { if ( !stricmp(Shockwave_info[i].filename, s_name) ) { - s_index = i; + s_index = (int)i; break; } } diff --git a/code/weapon/weapons.cpp b/code/weapon/weapons.cpp index ec36a26675..26cbf6e0c3 100644 --- a/code/weapon/weapons.cpp +++ b/code/weapon/weapons.cpp @@ -591,7 +591,7 @@ void parse_wi_flags(weapon_info *weaponp, flagset wi_flags) Spawn_names = (char **)vm_realloc(Spawn_names, (Num_spawn_types + 10) * sizeof(*Spawn_names)); } - int skip_length, name_length; + size_t skip_length, name_length; std::unique_ptr temp_string(new char[flag_text.size() + 1]); strcpy(temp_string.get(), flag_text.c_str()); @@ -2413,7 +2413,7 @@ int parse_weapon(int subtype, bool replace, const char *filename) //find a free slot in the pspew info array for (size_t s = 0; s < MAX_PARTICLE_SPEWERS; s++) { if (wip->particle_spewers[s].particle_spew_type == PSPEW_NONE) { - spew_index = s; + spew_index = (int)s; break; } } @@ -4170,7 +4170,7 @@ void weapon_home(object *obj, int num, float frame_time) aip = &Ai_info[Ships[hobjp->instance].ai_index]; if ((aip->nearest_locked_object == -1) || (dist < aip->nearest_locked_distance)) { - aip->nearest_locked_object = obj-Objects; + aip->nearest_locked_object = OBJ_INDEX(obj); aip->nearest_locked_distance = dist; } } diff --git a/freespace2/freespace.cpp b/freespace2/freespace.cpp index b90f33a8b8..7d4e470ba9 100644 --- a/freespace2/freespace.cpp +++ b/freespace2/freespace.cpp @@ -1219,10 +1219,10 @@ void game_loading_callback(int count) short_name++; sprintf(mem_buffer,"%s:\t" SIZE_T_ARG " K", short_name, size); - gr_string( 20, 220 + (i*line_height), mem_buffer, GR_RESIZE_MENU); + gr_string( 20, 220 + (int)(i*line_height), mem_buffer, GR_RESIZE_MENU); } sprintf(mem_buffer,"Total RAM:\t" SIZE_T_ARG " K", memory::get_used_memory() / 1024); - gr_string( 20, 230 + (i*line_height), mem_buffer, GR_RESIZE_MENU); + gr_string( 20, 230 + (int)(i*line_height), mem_buffer, GR_RESIZE_MENU); } #endif // !NDEBUG @@ -2344,10 +2344,10 @@ void game_show_framerate() short_name++; sprintf(mem_buffer,"%s:\t" SIZE_T_ARG " K", short_name, size); - gr_string( 20, 220 + (i*line_height), mem_buffer, GR_RESIZE_MENU); + gr_string( 20, 220 + (int)(i*line_height), mem_buffer, GR_RESIZE_MENU); } sprintf(mem_buffer,"Total RAM:\t" SIZE_T_ARG " K", memory::get_used_memory() / 1024); - gr_string( 20, 230 + (i*line_height), mem_buffer, GR_RESIZE_MENU); + gr_string( 20, 230 + (int)(i*line_height), mem_buffer, GR_RESIZE_MENU); } MONITOR_INC(NumPolys, modelstats_num_polys); @@ -7436,7 +7436,7 @@ void Time_model( int modelnum ) polymodel *pm = model_get( modelnum ); - int l = strlen(pm->filename); + size_t l = strlen(pm->filename); while( (l>0) ) { if ( (l == '/') || (l=='\\') || (l==':')) { l++; @@ -7800,7 +7800,6 @@ int find_freespace_cd(char *volume_name) int cdrom_drive=-1; int volume_match = 0; _finddata_t find; - int find_handle; GetCurrentDirectory(MAX_PATH-1, oldpath); @@ -7826,7 +7825,7 @@ int find_freespace_cd(char *volume_name) // look for setup.exe strcpy_s(full_check, path); strcat_s(full_check, "setup.exe"); - find_handle = _findfirst(full_check, &find); + auto find_handle = _findfirst(full_check, &find); if(find_handle != -1){ volume1_present = 1; _findclose(find_handle);