diff --git a/components/asset_util/cmds/cmd_ents.cpp b/components/asset_util/cmds/cmd_ents.cpp index 6928cb3b..3721144d 100644 --- a/components/asset_util/cmds/cmd_ents.cpp +++ b/components/asset_util/cmds/cmd_ents.cpp @@ -35,8 +35,6 @@ struct EntityTable int ParseEnts(const char* ents_str, EntityTable* ents_table) { - std::vector stack; - const char* str_start = NULL; const char* ent_start = NULL; int ent_level = 0; // Its like ESP but for ents! @@ -66,7 +64,7 @@ int ParseEnts(const char* ents_str, EntityTable* ents_table) } else if (strType == ParseEnts_StrType::VALUE) { - kv.value = str; + kv.value = std::move(str); ent.push_back(kv); kv.key.clear(); kv.value.clear(); @@ -193,10 +191,10 @@ int AddBrushes(EntityTable* ents_table) continue; KeyValuePair kv; - kv.key = ""; + kv.key.clear(); std::string value = FormatBrush(offset, 64); - kv.value = value; + kv.value = std::move(value); ent.push_back(kv); } @@ -316,6 +314,7 @@ int Ents_ExtractFromFastfile(const char* filepath, const char* outpath = NULL) { //Any fastfiles that claim they decompress to a file >= 1GB //are either corrupt or do not belong to the vanilla game Con_Error("ERROR: Skipping %s\n", filepath); + delete[] cBuf; return 1; } diff --git a/components/asset_util/cmds/cmd_search.cpp b/components/asset_util/cmds/cmd_search.cpp index f9464505..848d8b75 100644 --- a/components/asset_util/cmds/cmd_search.cpp +++ b/components/asset_util/cmds/cmd_search.cpp @@ -13,7 +13,6 @@ enum class FileType { IWD, FF, - ERR, }; @@ -24,11 +23,23 @@ struct FileEntry std::string name; std::string path; + FileEntry(FileType t, std::string n, std::string p) + { + type = std::move(t); + name = std::move(n); + path = std::move(p); + } + + FileEntry(void) + { + Clear(); + } + void Clear(void) { type = FileType::ERR; - path = ""; - name = ""; + name.clear(); + path.clear(); } }; @@ -52,7 +63,7 @@ class CachedFile public: std::string test; - CachedFile(void) : data(NULL), size(0) + CachedFile(void) : entry(), data(NULL), size(0) { } diff --git a/components/asset_util/cmds/ripper/snd_ripper.cpp b/components/asset_util/cmds/ripper/snd_ripper.cpp index 43762f21..7644c27d 100644 --- a/components/asset_util/cmds/ripper/snd_ripper.cpp +++ b/components/asset_util/cmds/ripper/snd_ripper.cpp @@ -482,7 +482,7 @@ int Rip_SoundBank_Soundalias_Callback_f(ForeignPointer& bank, ForeignPo std::string language = ""; - auto _offset = name.find_last_of("."); + auto _offset = name.find_last_of('.'); if (_offset != std::string::npos && _offset + 1 < name.size()) language = std::string(name, _offset + 1); else @@ -510,7 +510,7 @@ int Rip_SoundBank_Callback_f(ForeignPointer& asset, ForeignPointer>& snapshots) +int Rip_Snapshot_Callback_f(const std::string& name, std::vector>& snapshots) { Con_Print("Exporting snapshot %s.snapshot.csv...\n", name.c_str()); @@ -564,7 +564,7 @@ int Rip_Snapshot_Callback_f(std::string name, std::vector>& radverbs) +int Rip_Radverb_Callback_f(const std::string& name, std::vector>& radverbs) { Con_Print("Exporting snapshot %s.radverb.csv...\n", name.c_str()); diff --git a/components/asset_util/cmds/ripper/snd_ripper.h b/components/asset_util/cmds/ripper/snd_ripper.h index bdfd910e..87990dc4 100644 --- a/components/asset_util/cmds/ripper/snd_ripper.h +++ b/components/asset_util/cmds/ripper/snd_ripper.h @@ -36,5 +36,5 @@ int Rip_SoundBank_GatherSnapshots_Callback_f(ForeignPointer& asset, Fore int Rip_SoundBank_GatherRadverbs_Callback_f(ForeignPointer& asset, ForeignPointer& zoneName, void* data); int Rip_SoundBank_Callback_f(ForeignPointer& asset, ForeignPointer& zoneName, void* data); -int Rip_Snapshot_Callback_f(std::string name, std::vector>& snapshots); -int Rip_Radverb_Callback_f(std::string name, std::vector>& radverbs); +int Rip_Snapshot_Callback_f(const std::string& name, std::vector>& snapshots); +int Rip_Radverb_Callback_f(const std::string& name, std::vector>& radverbs); diff --git a/components/asset_util/cmds/search/handler.h b/components/asset_util/cmds/search/handler.h index a669875e..114607a7 100644 --- a/components/asset_util/cmds/search/handler.h +++ b/components/asset_util/cmds/search/handler.h @@ -211,17 +211,14 @@ class Handler _SlotHandleData_f HandlerCallback=Handler::_SlotHandleData_DefaultCallback, _SlotInit_f InitCallback = Handler::_SlotInit_DefaultCallback, _SlotPostInit_f PostInitCallback = Handler::_SlotPostInit_DefaultCallback) + : input_data(source_data), input_index(0), + _SlotInit_Callback(InitCallback), + _SlotPostInit_Callback(PostInitCallback), + _SlotHandleData_Callback(HandlerCallback) { numSlots = _slotCount; slots = new _SLOT_T *[numSlots]; memset(slots, 0, sizeof(_SLOT_T *) * numSlots); - - input_data = source_data; - input_index = 0; - - _SlotInit_Callback = InitCallback; - _SlotPostInit_Callback = PostInitCallback; - _SlotHandleData_Callback = HandlerCallback; } ~Handler() diff --git a/components/asset_util/common/ff.cpp b/components/asset_util/common/ff.cpp index 1e9dc448..b43afa98 100644 --- a/components/asset_util/common/ff.cpp +++ b/components/asset_util/common/ff.cpp @@ -509,6 +509,7 @@ int FF_FFExtract(const char* filepath, const char* filename) //Any fastfiles that claim they decompress to a file >= 1GB //are either corrupt or do not belong to the vanilla game Con_Error("ERROR: Skipping %s\n", filename); + delete[] cBuf; return 1; } diff --git a/components/asset_util/common/fs.cpp b/components/asset_util/common/fs.cpp index bb2510bc..9465fa94 100644 --- a/components/asset_util/common/fs.cpp +++ b/components/asset_util/common/fs.cpp @@ -219,7 +219,7 @@ int FS_CreatePath(const char* _targetPath) strncpy(buf + strlen(buf), targetPath, i); char* qpath = buf; - if (strlen(qpath) == 0) + if (qpath[0] == '\0') continue; FS_SanitizePath(qpath); diff --git a/components/asset_util/common/iwd.cpp b/components/asset_util/common/iwd.cpp index 7d5685f7..74199c6b 100644 --- a/components/asset_util/common/iwd.cpp +++ b/components/asset_util/common/iwd.cpp @@ -24,11 +24,12 @@ int __cdecl IWD_IWDHandler(const char* iwdPath, const char* iwdName) } else if (g_extractImages.ValueBool()) { - sprintf_s(sub, "IMAGE"); + char subdst[MAX_PATH]; + sprintf_s(subdst, "IMAGE"); if (g_extractSounds.ValueBool()) { - sprintf_s(sub, "%s and %s", sub, "AUDIO"); + sprintf_s(sub, "%s and %s", subdst, "AUDIO"); } } else @@ -92,6 +93,8 @@ int __cdecl IWD_IWDExtract(const char* iwdPath, const char* iwdName) } int extractedCount = 0; + size_t lenDirImage = strlen(IWD_DIR_IMAGE); + size_t lenDirSound = strlen(IWD_DIR_SOUND); for (int f = 0; f < (int)mz_zip_reader_get_num_files(&iwd); f++) { mz_zip_archive_file_stat file_stat; @@ -102,12 +105,12 @@ int __cdecl IWD_IWDExtract(const char* iwdPath, const char* iwdName) return -1; } - if (g_extractImages.ValueBool() && _strnicmp(IWD_DIR_IMAGE, file_stat.m_filename, strlen(IWD_DIR_IMAGE)) == 0) + if (g_extractImages.ValueBool() && _strnicmp(IWD_DIR_IMAGE, file_stat.m_filename, lenDirImage) == 0) { IWD_IWDExtractFile(&iwd, file_stat.m_filename); continue; } - else if (g_extractSounds.ValueBool() && _strnicmp(IWD_DIR_SOUND, file_stat.m_filename, strlen(IWD_DIR_SOUND)) == 0) + else if (g_extractSounds.ValueBool() && _strnicmp(IWD_DIR_SOUND, file_stat.m_filename, lenDirSound) == 0) { IWD_IWDExtractFile(&iwd, file_stat.m_filename); continue; diff --git a/components/asset_util/gdt/assettype/character.cpp b/components/asset_util/gdt/assettype/character.cpp index 12d6e77a..96a6c892 100644 --- a/components/asset_util/gdt/assettype/character.cpp +++ b/components/asset_util/gdt/assettype/character.cpp @@ -35,9 +35,9 @@ int Character::ExtractFromGSC(const char* qpath) GSC_Character_ExtractAliasEntry("legDmg4", str.c_str(), &this->legDmg[3], ""); // misc models arent supported right now - this->misc[0].model = ""; - this->misc[1].model = ""; - this->misc[2].model = ""; + this->misc[0].model.clear(); + this->misc[1].model.clear(); + this->misc[2].model.clear(); /* Unsupported - Can't find any examples of these diff --git a/components/asset_util/gdt/assettype/xmodelalias.cpp b/components/asset_util/gdt/assettype/xmodelalias.cpp index 664d6ed7..9caa725d 100644 --- a/components/asset_util/gdt/assettype/xmodelalias.cpp +++ b/components/asset_util/gdt/assettype/xmodelalias.cpp @@ -11,7 +11,7 @@ XModelAlias::XModelAlias() { for (int i = 0; i < XMODELALIAS_MODELCOUNT; i++) { - this->model[i] = ""; + this->model[i].clear(); } } diff --git a/components/asset_util/sys/AppInfo.cpp b/components/asset_util/sys/AppInfo.cpp index 2a8d6ea7..b4059306 100644 --- a/components/asset_util/sys/AppInfo.cpp +++ b/components/asset_util/sys/AppInfo.cpp @@ -86,10 +86,10 @@ const char* AppInfo_RawDir() const char* AppInfo_OutDir() { - if (strlen(fs_outdir.ValueString()) == 0) + if (fs_outdir.ValueString()[0] == '\0') return AppInfo_RawDir(); - if (strstr(fs_outdir.ValueString(), ":") != NULL && strstr(fs_outdir.ValueString(), ":") != fs_outdir.ValueString() + 1) + if (strchr(fs_outdir.ValueString(), ':') != NULL && strchr(fs_outdir.ValueString(), ':') != fs_outdir.ValueString() + 1) { Con_Warning("Invalid output directory - falling back to default\n"); fs_outdir.AssignRawString(""); diff --git a/components/asset_viewer/dllmain.cpp b/components/asset_viewer/dllmain.cpp index 93edc2aa..1caaa101 100644 --- a/components/asset_viewer/dllmain.cpp +++ b/components/asset_viewer/dllmain.cpp @@ -43,9 +43,12 @@ BOOL AssetViewerMod_Init() // if (AllocConsole()) { - freopen("CONOUT$", "w", stdout); - freopen("CONOUT$", "w", stderr); - freopen("CONIN$", "r", stdin); + if (freopen("CONOUT$", "w", stdout) == NULL) + return FALSE; + if (freopen("CONOUT$", "w", stderr) == NULL) + return FALSE; + if (freopen("CONIN$", "r", stdin) == NULL) + return FALSE; } #if USE_NSIGHT_FIX @@ -102,13 +105,34 @@ BOOL AssetViewerMod_Init() return TRUE; } +BOOL AssetViewerMod_Destroy() +{ + // + // Destroy an external console for AssetViewer + // + if (AllocConsole()) + { + fclose(stdout); + fclose(stderr); + fclose(stdin); + } + + return TRUE; +} + BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { - if (ul_reason_for_call == DLL_PROCESS_ATTACH) + BOOL initialized = TRUE; + switch (ul_reason_for_call) { + case DLL_PROCESS_ATTACH: DisableThreadLibraryCalls(hModule); - return AssetViewerMod_Init(); + initialized = AssetViewerMod_Init(); + break; + case DLL_PROCESS_DETACH: + initialized = AssetViewerMod_Destroy(); + break; } - return TRUE; + return initialized; } diff --git a/components/cod2rad/r_lightmaps.cpp b/components/cod2rad/r_lightmaps.cpp index 21b53b4b..d9daf703 100644 --- a/components/cod2rad/r_lightmaps.cpp +++ b/components/cod2rad/r_lightmaps.cpp @@ -1,4 +1,4 @@ -#include "stdafx.h" +#include "stdafx.h" #define LOG_VEC_EQ(A,B) if (A != B) { printf("(%f) %f %f %f == %f %f %f\n", Vec3Variance(&A, &B), A.x, A.y, A.z, B.x, B.y, B.z); } @@ -467,13 +467,13 @@ void ImproveLightingApproximation(vec3* lighting, vec3 *highlightDir, vec3* pel_ } } - *pel_amb = new_pel_amb; - *pel_dir = new_pel_dir; + *pel_amb = std::move(new_pel_amb); + *pel_dir = std::move(new_pel_dir); initialByteDir[0] = updatedByteDir[0]; initialByteDir[1] = updatedByteDir[1]; - *highlightDir = dir; + *highlightDir = std::move(dir); error = curError; } diff --git a/components/game_mod/patch_reflections.cpp b/components/game_mod/patch_reflections.cpp index 5526fb55..92083dbb 100644 --- a/components/game_mod/patch_reflections.cpp +++ b/components/game_mod/patch_reflections.cpp @@ -215,12 +215,15 @@ BOOL LoadBSPReflectionData(const char* bspPath, BYTE* dest, size_t destSize) if (padded(size) != padded(destSize)) { printf("ERROR: Fastfile probe count does not match the BSP probe count - please rebuild fastfile\n"); + delete[] index; fclose(h); + return FALSE; } fseek(h, offset, SEEK_SET); fread(dest, 1, size, h); + delete[] index; fclose(h); return TRUE; diff --git a/components/installer/bootstrap/exports.cpp b/components/installer/bootstrap/exports.cpp index 11d1f37e..23d7fe68 100644 --- a/components/installer/bootstrap/exports.cpp +++ b/components/installer/bootstrap/exports.cpp @@ -33,7 +33,7 @@ extern "C" { bool __stdcall LMI_SetInstallPath(const char* path) { const std::string binaryPath = FS::JoinPath(path, "BlackOps.exe"); - return FS::FileExists(binaryPath.c_str()); + return FS::FileExists(binaryPath); } int __stdcall LMI_CompareVersions(const char* a, const char* b) diff --git a/components/installer/bootstrap/pe.cpp b/components/installer/bootstrap/pe.cpp index 633c8f1d..5dccb12a 100644 --- a/components/installer/bootstrap/pe.cpp +++ b/components/installer/bootstrap/pe.cpp @@ -41,7 +41,7 @@ namespace pe { }; const auto _module = FormatName(moduleName); - const auto _symbol = symbolName != nullptr ? FormatName(symbolName) : std::string(""); + const auto _symbol = symbolName != nullptr ? FormatName(symbolName) : std::string(); // Iterate over all modules used by the given image const auto moduleList = get_imported_functions(image); diff --git a/components/installer/bootstrap/process.cpp b/components/installer/bootstrap/process.cpp index ecd9f1d0..6fe8db1c 100644 --- a/components/installer/bootstrap/process.cpp +++ b/components/installer/bootstrap/process.cpp @@ -46,7 +46,7 @@ bool Pipe::Read(std::string& dst) { // CloseHandle_s(_hWrite); - dst = ""; + dst.clear(); dst.resize(bufLen); DWORD dwRead = 0; diff --git a/components/radiant_mod/r_draw_shadowablelight.cpp b/components/radiant_mod/r_draw_shadowablelight.cpp index ee6333ff..4a4d263e 100644 --- a/components/radiant_mod/r_draw_shadowablelight.cpp +++ b/components/radiant_mod/r_draw_shadowablelight.cpp @@ -104,10 +104,10 @@ void R_BuildSpotLightInfo(float* source, GfxLight* light, float spotShadowFade) const float farEdge = g_lightInfo.kvs.far_edge; //0.0f; vec4 aAbB; // = { 0.0f, 1.0f, 0.0f, 1.0f }; - memcpy(&aAbB, &g_lightInfo.kvs.superellipse, sizeof(vec4)); + memcpy(&aAbB, &g_lightInfo.kvs.superellipse, sizeof(aAbB)); vec4 attenuation; // = { 1.0f, 0.0f, 0.0f, 0.0f }; - memcpy(&attenuation, &g_lightInfo.kvs.attenuation, sizeof(vec3)); + memcpy(&attenuation, &g_lightInfo.kvs.attenuation, sizeof(attenuation)); vec4 fallOff; fallOff.x = cutOn; @@ -115,8 +115,8 @@ void R_BuildSpotLightInfo(float* source, GfxLight* light, float spotShadowFade) fallOff.z = ((light->radius - cutOn) * nearEdge) + cutOn; fallOff.w = ((light->radius - cutOn) * farEdge) + cutOn; - memcpy(&g_lightInfo.aAbB, &aAbB, sizeof(vec4)); - memcpy(&g_lightInfo.attenuation, &attenuation, sizeof(vec4)); + memcpy(&g_lightInfo.aAbB, &aAbB, sizeof(g_lightInfo.aAbB)); + memcpy(&g_lightInfo.attenuation, &attenuation, sizeof(g_lightInfo.attenuation)); vec4 angles = { 0.0f, 0.0f, 0.0f, 0.0f }; memcpy(&angles, light->angles, sizeof(float) * 3); diff --git a/components/radiant_mod/r_image_load_obj.cpp b/components/radiant_mod/r_image_load_obj.cpp index 1fcbe561..2fe1cfb3 100644 --- a/components/radiant_mod/r_image_load_obj.cpp +++ b/components/radiant_mod/r_image_load_obj.cpp @@ -342,7 +342,7 @@ bool Image_LoadFromFileWithReader(GfxImage *image, int (__cdecl * OpenFileRead)( int picmip = image->picmip.platform[/*useFastFile->current.enabled == 0*/0]; char streamedMipLevels = picmip > 0; - int readSize = fileHeader.fileSizeForPicmip[picmip > 0] - 48; + int readSize = fileHeader.fileSizeForPicmip[streamedMipLevels] - 48; char *imageData = (char *)Z_Malloc(readSize); if (FS_Read(imageData, readSize, fileHandle) == readSize) diff --git a/components/shared/detours/AsmGen.cpp b/components/shared/detours/AsmGen.cpp index ce729a94..70b364c0 100644 --- a/components/shared/detours/AsmGen.cpp +++ b/components/shared/detours/AsmGen.cpp @@ -88,7 +88,7 @@ BYTE *AsmGen::GetStream(bool Free) BYTE *data = (BYTE *)malloc(m_Stream.size() * sizeof(BYTE)); for (size_t i = 0; i < m_Stream.size(); i++) - data[i] = m_Stream.at(i); + data[i] = m_Stream[i]; m_StreamData = (Free) ? data : nullptr; diff --git a/components/shared/pe_lib/pe_base.cpp b/components/shared/pe_lib/pe_base.cpp index c6ff2236..a08157a0 100644 --- a/components/shared/pe_lib/pe_base.cpp +++ b/components/shared/pe_lib/pe_base.cpp @@ -994,7 +994,7 @@ void pe_base::read_pe(std::istream& file, bool read_debug_raw_data) if(file.bad() || file.eof()) throw pe_exception("Error reading file", pe_exception::error_reading_file); - debug_data_.insert(std::make_pair(directory.PointerToRawData, data)); + debug_data_.emplace(directory.PointerToRawData, data); } //Go to next debug entry diff --git a/components/shared/pe_lib/pe_exports.cpp b/components/shared/pe_lib/pe_exports.cpp index 4a1bc1d8..bf0c231e 100644 --- a/components/shared/pe_lib/pe_exports.cpp +++ b/components/shared/pe_lib/pe_exports.cpp @@ -622,7 +622,7 @@ const image_directory rebuild_exports(pe_base& pe, const export_info& info, expo //If function is named, save its name ordinal and name in sorted alphabetically order if(func.has_name()) - funcs.insert(std::make_pair(func.get_name(), static_cast(func.get_ordinal() - ordinal_base))); //Calculate name ordinal + funcs.emplace(func.get_name(), static_cast(func.get_ordinal() - ordinal_base)); //Calculate name ordinal //If function is forwarded to another DLL if(func.is_forwarded()) diff --git a/components/shared/pe_lib/pe_resource_viewer.cpp b/components/shared/pe_lib/pe_resource_viewer.cpp index 1414c33f..b62a12bd 100644 --- a/components/shared/pe_lib/pe_resource_viewer.cpp +++ b/components/shared/pe_lib/pe_resource_viewer.cpp @@ -308,7 +308,7 @@ const resource_data_info pe_resource_viewer::get_resource_data_by_name(resource_ if(entries.size() <= index) throw pe_exception("Resource data entry not found", pe_exception::resource_data_entry_not_found); - return resource_data_info(entries.at(index).get_data_entry()); //Data directory + return resource_data_info(entries[index].get_data_entry()); //Data directory } //Returns raw resource data by root name, name and index in language directory (instead of language) @@ -324,7 +324,7 @@ const resource_data_info pe_resource_viewer::get_resource_data_by_name(const std if(entries.size() <= index) throw pe_exception("Resource data entry not found", pe_exception::resource_data_entry_not_found); - return resource_data_info(entries.at(index).get_data_entry()); //Data directory + return resource_data_info(entries[index].get_data_entry()); //Data directory } //Returns raw resource data by type, ID and index in language directory (instead of language) @@ -340,7 +340,7 @@ const resource_data_info pe_resource_viewer::get_resource_data_by_id(resource_ty if(entries.size() <= index) throw pe_exception("Resource data entry not found", pe_exception::resource_data_entry_not_found); - return resource_data_info(entries.at(index).get_data_entry()); //Data directory + return resource_data_info(entries[index].get_data_entry()); //Data directory } //Returns raw resource data by root name, ID and index in language directory (instead of language) @@ -356,6 +356,6 @@ const resource_data_info pe_resource_viewer::get_resource_data_by_id(const std:: if(entries.size() <= index) throw pe_exception("Resource data entry not found", pe_exception::resource_data_entry_not_found); - return resource_data_info(entries.at(index).get_data_entry()); //Data directory + return resource_data_info(entries[index].get_data_entry()); //Data directory } } diff --git a/components/shared/pe_lib/resource_cursor_icon_reader.cpp b/components/shared/pe_lib/resource_cursor_icon_reader.cpp index 514e288c..0241be37 100644 --- a/components/shared/pe_lib/resource_cursor_icon_reader.cpp +++ b/components/shared/pe_lib/resource_cursor_icon_reader.cpp @@ -75,7 +75,7 @@ const std::string resource_cursor_icon_reader::get_single_icon_by_id(uint32_t id throw pe_exception("Resource data entry not found", pe_exception::resource_data_entry_not_found); //Get icon headers - std::string icon_data(lookup_icon_group_data_by_icon(id, languages.at(index))); + std::string icon_data(lookup_icon_group_data_by_icon(id, languages[index])); //Append icon data icon_data.append(res_.get_resource_data_by_id(pe_resource_viewer::resource_icon, id, index).get_data()); return icon_data; @@ -263,7 +263,7 @@ const std::string resource_cursor_icon_reader::get_single_cursor_by_id(uint32_t std::string raw_cursor_data(res_.get_resource_data_by_id(pe_resource_viewer::resource_cursor, id, index).get_data()); //Get cursor headers - std::string cursor_data(lookup_cursor_group_data_by_cursor(id, languages.at(index), raw_cursor_data)); + std::string cursor_data(lookup_cursor_group_data_by_cursor(id, languages[index], raw_cursor_data)); //Append cursor data cursor_data.append(raw_cursor_data.substr(sizeof(uint16_t) * 2 /* hotspot position */)); return cursor_data; diff --git a/components/shared/pe_lib/resource_message_list_reader.cpp b/components/shared/pe_lib/resource_message_list_reader.cpp index ff9a5dd8..df4bae65 100644 --- a/components/shared/pe_lib/resource_message_list_reader.cpp +++ b/components/shared/pe_lib/resource_message_list_reader.cpp @@ -67,25 +67,25 @@ const resource_message_list resource_message_list_reader::parse_message_list(con //Add ID and string to message table #ifdef PE_BLISS_WINDOWS - ret.insert(std::make_pair(curr_id, message_table_item( + ret.emplace(curr_id, message_table_item( std::wstring(reinterpret_cast(resource_data.data() + block->OffsetToEntries + current_pos + size_of_entry_headers), (entry->Length - size_of_entry_headers) / 2) - ))); + )); #else - ret.insert(std::make_pair(curr_id, message_table_item( + ret.emplace(curr_id, message_table_item( pe_utils::from_ucs2(u16string(reinterpret_cast(resource_data.data() + block->OffsetToEntries + current_pos + size_of_entry_headers), (entry->Length - size_of_entry_headers) / 2)) - ))); + )); #endif } else { //If string is ANSI //Add ID and string to message table - ret.insert(std::make_pair(curr_id, message_table_item( + ret.emplace(curr_id, message_table_item( std::string(resource_data.data() + block->OffsetToEntries + current_pos + size_of_entry_headers, entry->Length - size_of_entry_headers) - ))); + )); } //Go to next entry diff --git a/components/shared/pe_lib/resource_string_table_reader.cpp b/components/shared/pe_lib/resource_string_table_reader.cpp index 33eace19..c33d469d 100644 --- a/components/shared/pe_lib/resource_string_table_reader.cpp +++ b/components/shared/pe_lib/resource_string_table_reader.cpp @@ -45,13 +45,13 @@ const resource_string_list resource_string_table_reader::parse_string_list(uint3 { //Create and save string (UNICODE) #ifdef PE_BLISS_WINDOWS - ret.insert( - std::make_pair(static_cast(((id - 1) << 4) + i), //ID of string is calculated such way - std::wstring(reinterpret_cast(resource_data.data() + passed_bytes), string_length))); + ret.emplace( + static_cast(((id - 1) << 4) + i), //ID of string is calculated such way + std::wstring(reinterpret_cast(resource_data.data() + passed_bytes), string_length)); #else - ret.insert( - std::make_pair(static_cast(((id - 1) << 4) + i), //ID of string is calculated such way - pe_utils::from_ucs2(u16string(reinterpret_cast(resource_data.data() + passed_bytes), string_length)))); + ret.emplace( + static_cast(((id - 1) << 4) + i), //ID of string is calculated such way + pe_utils::from_ucs2(u16string(reinterpret_cast(resource_data.data() + passed_bytes), string_length))); #endif } diff --git a/components/shared/pe_lib/resource_version_info_reader.cpp b/components/shared/pe_lib/resource_version_info_reader.cpp index 4a8a2723..26a28e93 100644 --- a/components/shared/pe_lib/resource_version_info_reader.cpp +++ b/components/shared/pe_lib/resource_version_info_reader.cpp @@ -175,10 +175,10 @@ const file_version_info resource_version_info_reader::get_version_info(lang_stri //Save name-value pair #ifdef PE_BLISS_WINDOWS - new_values.insert(std::make_pair(reinterpret_cast(string_block->Key), data)); + new_values.emplace(reinterpret_cast(string_block->Key), data); #else - new_values.insert(std::make_pair(pe_utils::from_ucs2(reinterpret_cast(string_block->Key)), - pe_utils::from_ucs2(data))); + new_values.emplace(pe_utils::from_ucs2(reinterpret_cast(string_block->Key)), + pe_utils::from_ucs2(data)); #endif //Navigate to next string block @@ -186,9 +186,9 @@ const file_version_info resource_version_info_reader::get_version_info(lang_stri } #ifdef PE_BLISS_WINDOWS - string_values.insert(std::make_pair(reinterpret_cast(string_table->Key), new_values)); + string_values.emplace(reinterpret_cast(string_table->Key), new_values); #else - string_values.insert(std::make_pair(pe_utils::from_ucs2(reinterpret_cast(string_table->Key)), new_values)); + string_values.emplace(pe_utils::from_ucs2(reinterpret_cast(string_table->Key)), new_values); #endif //Navigate to next string table block @@ -231,7 +231,7 @@ const file_version_info resource_version_info_reader::get_version_info(lang_stri uint16_t lang_id = *reinterpret_cast(resource_data.data() + value_pos + i); uint16_t codepage_id = *reinterpret_cast(resource_data.data() + value_pos + sizeof(uint16_t) + i); //Save translation - translations.insert(std::make_pair(lang_id, codepage_id)); + translations.emplace(lang_id, codepage_id); } } @@ -285,6 +285,6 @@ const file_version_info resource_version_info_reader::get_version_info(lang_stri if(entries.size() <= index) throw pe_exception("Resource data entry not found", pe_exception::resource_data_entry_not_found); - return get_version_info(string_values, translations, entries.at(index).get_data_entry().get_data()); //Data directory + return get_version_info(string_values, translations, entries[index].get_data_entry().get_data()); //Data directory } } diff --git a/components/shared/pe_lib/version_info_editor.cpp b/components/shared/pe_lib/version_info_editor.cpp index 9e5c9b7a..1844eaca 100644 --- a/components/shared/pe_lib/version_info_editor.cpp +++ b/components/shared/pe_lib/version_info_editor.cpp @@ -85,7 +85,7 @@ void version_info_editor::set_property(const std::wstring& property_name, const it = strings_edit_.begin(); if(it == strings_edit_.end()) //If there's no any translation table, add default one { - it = strings_edit_.insert(std::make_pair(default_language_translation, string_values_map())).first; + it = strings_edit_.emplace(default_language_translation, string_values_map()).first; //Also add it to translations list add_translation(default_language_translation); } @@ -96,7 +96,7 @@ void version_info_editor::set_property(const std::wstring& property_name, const it = strings_edit_.find(translation); //Find specified translation table if(it == strings_edit_.end()) //If there's no translation, add it { - it = strings_edit_.insert(std::make_pair(translation, string_values_map())).first; + it = strings_edit_.emplace(translation, string_values_map()).first; //Also add it to translations list add_translation(translation); } @@ -125,7 +125,7 @@ void version_info_editor::add_translation(uint16_t language_id, uint16_t codepag return; } - translations_edit_.insert(std::make_pair(language_id, codepage_id)); + translations_edit_.emplace(language_id, codepage_id); } //Removes translation from translations and strings lists diff --git a/components/shared/pe_lib/version_info_viewer.cpp b/components/shared/pe_lib/version_info_viewer.cpp index 3f6a2573..4789b472 100644 --- a/components/shared/pe_lib/version_info_viewer.cpp +++ b/components/shared/pe_lib/version_info_viewer.cpp @@ -82,7 +82,7 @@ const version_info_viewer::translation_list version_info_viewer::get_translation << std::setw(4) << std::setfill(L'0') << (*it).second; //Save it - ret.push_back(ss.str()); + ret.emplace_back(ss.str()); } return ret; diff --git a/components/shared/shared_utility.h b/components/shared/shared_utility.h index 8c813fcd..f99e7a8c 100644 --- a/components/shared/shared_utility.h +++ b/components/shared/shared_utility.h @@ -101,7 +101,7 @@ static void FixupFunction(ULONG_PTR Address, ULONG_PTR DestAddress) PatchMemory(Address + 1, (PBYTE)&data, 4); } -static bool StrEndsWith (std::string str, std::string substr) +static bool StrEndsWith (const std::string &str, const std::string &substr) { if (str.length() >= substr.length()) return (0 == str.compare (str.length() - substr.length(), substr.length(), substr));