diff --git a/amxmodx/CLibrarySys.cpp b/amxmodx/CLibrarySys.cpp index 75bb5ac6..5330a944 100644 --- a/amxmodx/CLibrarySys.cpp +++ b/amxmodx/CLibrarySys.cpp @@ -24,7 +24,7 @@ CDirectory::CDirectory(const char *path) #if defined PLATFORM_WINDOWS char newpath[PLATFORM_MAX_PATH]; - ke::SafeSprintf(newpath, sizeof(newpath) - 1, "%s\\*.*", path); + ke::SafeSprintf(newpath, sizeof(newpath), "%s\\*.*", path); m_dir = FindFirstFile(newpath, &m_fd); @@ -40,7 +40,7 @@ CDirectory::CDirectory(const char *path) if (IsValid()) { m_ep = readdir(m_dir); // TODO: we need to read past "." and ".."! - ke::SafeSprintf(m_origpath, sizeof(m_origpath) - 1, "%s", path); + ke::SafeSprintf(m_origpath, sizeof(m_origpath), "%s", path); } else { @@ -121,7 +121,7 @@ bool CDirectory::IsEntryFile() char temppath[PLATFORM_MAX_PATH]; ke::SafeSprintf(temppath, sizeof(temppath), "%s/%s", m_origpath, GetEntryName()); - return ke::file::IsDirectory(temppath); + return ke::file::IsFile(temppath); #endif } diff --git a/amxmodx/cvars.cpp b/amxmodx/cvars.cpp index c7319bf1..8e272095 100644 --- a/amxmodx/cvars.cpp +++ b/amxmodx/cvars.cpp @@ -240,7 +240,7 @@ static cell AMX_NATIVE_CALL set_cvar_float(AMX *amx, cell *params) if (info) { - ke::SafeSprintf(CVarTempBuffer, sizeof(CVarTempBuffer) - 1, "%f", amx_ctof(params[2])); + ke::SafeSprintf(CVarTempBuffer, sizeof(CVarTempBuffer), "%f", amx_ctof(params[2])); CVAR_DIRECTSET(info->var, &CVarTempBuffer[0]); } @@ -258,7 +258,7 @@ static cell AMX_NATIVE_CALL set_cvar_num(AMX *amx, cell *params) if (info) { - ke::SafeSprintf(CVarTempBuffer, sizeof(CVarTempBuffer) - 1, "%d", value); + ke::SafeSprintf(CVarTempBuffer, sizeof(CVarTempBuffer), "%d", value); CVAR_DIRECTSET(info->var, &CVarTempBuffer[0]); } @@ -444,7 +444,7 @@ static cell AMX_NATIVE_CALL set_pcvar_float(AMX *amx, cell *params) return 0; } - ke::SafeSprintf(CVarTempBuffer, sizeof(CVarTempBuffer) - 1, "%f", amx_ctof(params[2])); + ke::SafeSprintf(CVarTempBuffer, sizeof(CVarTempBuffer), "%f", amx_ctof(params[2])); CVAR_DIRECTSET(ptr, &CVarTempBuffer[0]); return 1; @@ -460,7 +460,7 @@ static cell AMX_NATIVE_CALL set_pcvar_num(AMX *amx, cell *params) return 0; } - ke::SafeSprintf(CVarTempBuffer, sizeof(CVarTempBuffer) - 1, "%d", params[2]); + ke::SafeSprintf(CVarTempBuffer, sizeof(CVarTempBuffer), "%d", params[2]); CVAR_DIRECTSET(ptr, &CVarTempBuffer[0]); return 1; diff --git a/amxmodx/format.cpp b/amxmodx/format.cpp index 1dc43e4e..b4a46d10 100644 --- a/amxmodx/format.cpp +++ b/amxmodx/format.cpp @@ -673,7 +673,7 @@ reswitch: if (!def) { static char buf[255]; - ke::SafeSprintf(buf, sizeof(buf) - 1, "ML_NOTFOUND: %s", key); + ke::SafeSprintf(buf, sizeof(buf), "ML_NOTFOUND: %s", key); def = buf; } size_t written = atcprintf(buf_p, llen, def, amx, params, &arg); diff --git a/amxmodx/libraries.cpp b/amxmodx/libraries.cpp index 5e6211b8..b9035e5a 100644 --- a/amxmodx/libraries.cpp +++ b/amxmodx/libraries.cpp @@ -97,7 +97,7 @@ size_t AddLibrariesFromString(const char *name, LibType type, LibSource src, voi char *ptr, *p, s; size_t count = 0; - ke::SafeSprintf(buffer, sizeof(buffer)-1, "%s", name); + ke::SafeSprintf(buffer, sizeof(buffer), "%s", name); ptr = buffer; p = buffer; diff --git a/amxmodx/meta_api.cpp b/amxmodx/meta_api.cpp index bdcbf2d5..ec19f877 100755 --- a/amxmodx/meta_api.cpp +++ b/amxmodx/meta_api.cpp @@ -226,7 +226,7 @@ void LoadExtraPluginsToPCALM(const char *initialdir) while (!files.empty()) { ke::AString *pString = files.front(); - ke::SafeSprintf(path, sizeof(path)-1, "%s/%s", + ke::SafeSprintf(path, sizeof(path), "%s/%s", initialdir, pString->chars()); g_plugins.CALMFromFile(path); @@ -243,7 +243,7 @@ void LoadExtraPluginsFromDir(const char *initialdir) while (!files.empty()) { ke::AString *pString = files.front(); - ke::SafeSprintf(path, sizeof(path)-1, "%s/%s", + ke::SafeSprintf(path, sizeof(path), "%s/%s", initialdir, pString->chars()); g_plugins.loadPluginsFromFile(path); diff --git a/amxmodx/modules.cpp b/amxmodx/modules.cpp index f4bcf4a1..62a15566 100755 --- a/amxmodx/modules.cpp +++ b/amxmodx/modules.cpp @@ -670,7 +670,7 @@ char* build_pathname(const char *fmt, ...) { static char string[256]; int b; - int a = b = ke::SafeSprintf(string, 255, "%s%c", g_mod_name.chars(), PATH_SEP_CHAR); + int a = b = ke::SafeSprintf(string, sizeof(string), "%s%c", g_mod_name.chars(), PATH_SEP_CHAR); va_list argptr; va_start(argptr, fmt); diff --git a/amxmodx/newmenus.cpp b/amxmodx/newmenus.cpp index 75e90b08..899b0d43 100755 --- a/amxmodx/newmenus.cpp +++ b/amxmodx/newmenus.cpp @@ -289,7 +289,7 @@ bool Menu::Display(int player, page_t page) return false; static char buffer[2048]; - int len = ke::SafeSprintf(buffer, sizeof(buffer)-1, "%s", str); + int len = ke::SafeSprintf(buffer, sizeof(buffer), "%s", str); CPlayer *pPlayer = GET_PLAYER_POINTER_I(player); @@ -342,14 +342,14 @@ const char *Menu::GetTextString(int player, page_t page, int &keys) if (items_per_page && (pages != 1)) { if (m_AutoColors) - ke::SafeSprintf(buffer, sizeof(buffer)-1, "\\y%s %d/%d\n\\w\n", m_Title.chars(), page + 1, pages); + ke::SafeSprintf(buffer, sizeof(buffer), "\\y%s %d/%d\n\\w\n", m_Title.chars(), page + 1, pages); else - ke::SafeSprintf(buffer, sizeof(buffer)-1, "%s %d/%d\n\n", m_Title.chars(), page + 1, pages); + ke::SafeSprintf(buffer, sizeof(buffer), "%s %d/%d\n\n", m_Title.chars(), page + 1, pages); } else { if (m_AutoColors) - ke::SafeSprintf(buffer, sizeof(buffer)-1, "\\y%s\n\\w\n", m_Title.chars()); + ke::SafeSprintf(buffer, sizeof(buffer), "\\y%s\n\\w\n", m_Title.chars()); else - ke::SafeSprintf(buffer, sizeof(buffer)-1, "%s\n\n", m_Title.chars()); + ke::SafeSprintf(buffer, sizeof(buffer), "%s\n\n", m_Title.chars()); } m_Text = m_Text + buffer; @@ -446,22 +446,22 @@ const char *Menu::GetTextString(int player, page_t page, int &keys) if (pItem->isBlank) { - ke::SafeSprintf(buffer, sizeof(buffer)-1, "%s\n", pItem->name.chars()); + ke::SafeSprintf(buffer, sizeof(buffer), "%s\n", pItem->name.chars()); } else if (enabled) { if (m_AutoColors) { - ke::SafeSprintf(buffer, sizeof(buffer)-1, "%s%d.\\w %s\n", m_ItemColor.chars(),option_display, pItem->name.chars()); + ke::SafeSprintf(buffer, sizeof(buffer), "%s%d.\\w %s\n", m_ItemColor.chars(),option_display, pItem->name.chars()); } else { - ke::SafeSprintf(buffer, sizeof(buffer)-1, "%d. %s\n", option_display, pItem->name.chars()); + ke::SafeSprintf(buffer, sizeof(buffer), "%d. %s\n", option_display, pItem->name.chars()); } } else { if (m_AutoColors) { - ke::SafeSprintf(buffer, sizeof(buffer)-1, "\\d%d. %s\n\\w", option_display, pItem->name.chars()); + ke::SafeSprintf(buffer, sizeof(buffer), "\\d%d. %s\n\\w", option_display, pItem->name.chars()); } else { - ke::SafeSprintf(buffer, sizeof(buffer)-1, "#. %s\n", pItem->name.chars()); + ke::SafeSprintf(buffer, sizeof(buffer), "#. %s\n", pItem->name.chars()); } } slots++; @@ -504,14 +504,14 @@ const char *Menu::GetTextString(int player, page_t page, int &keys) if (m_AutoColors) { ke::SafeSprintf(buffer, - sizeof(buffer)-1, + sizeof(buffer), "%s%d. \\w%s\n", m_ItemColor.chars(), option == 10 ? 0 : option, m_OptNames[abs(MENU_BACK)].chars()); } else { ke::SafeSprintf(buffer, - sizeof(buffer)-1, + sizeof(buffer), "%d. %s\n", option == 10 ? 0 : option, m_OptNames[abs(MENU_BACK)].chars()); @@ -521,12 +521,12 @@ const char *Menu::GetTextString(int player, page_t page, int &keys) if (m_AutoColors) { ke::SafeSprintf(buffer, - sizeof(buffer)-1, + sizeof(buffer), "\\d%d. %s\n\\w", option == 10 ? 0 : option, m_OptNames[abs(MENU_BACK)].chars()); } else { - ke::SafeSprintf(buffer, sizeof(buffer)-1, "#. %s\n", m_OptNames[abs(MENU_BACK)].chars()); + ke::SafeSprintf(buffer, sizeof(buffer), "#. %s\n", m_OptNames[abs(MENU_BACK)].chars()); } } m_Text = m_Text + buffer; @@ -537,14 +537,14 @@ const char *Menu::GetTextString(int player, page_t page, int &keys) if (m_AutoColors) { ke::SafeSprintf(buffer, - sizeof(buffer)-1, + sizeof(buffer), "%s%d. \\w%s\n", m_ItemColor.chars(), option == 10 ? 0 : option, m_OptNames[abs(MENU_MORE)].chars()); } else { ke::SafeSprintf(buffer, - sizeof(buffer)-1, + sizeof(buffer), "%d. %s\n", option == 10 ? 0 : option, m_OptNames[abs(MENU_MORE)].chars()); @@ -554,12 +554,12 @@ const char *Menu::GetTextString(int player, page_t page, int &keys) if (m_AutoColors) { ke::SafeSprintf(buffer, - sizeof(buffer)-1, + sizeof(buffer), "\\d%d. %s\n\\w", option == 10 ? 0 : option, m_OptNames[abs(MENU_MORE)].chars()); } else { - ke::SafeSprintf(buffer, sizeof(buffer)-1, "#. %s\n", m_OptNames[abs(MENU_MORE)].chars()); + ke::SafeSprintf(buffer, sizeof(buffer), "#. %s\n", m_OptNames[abs(MENU_MORE)].chars()); } } m_Text = m_Text + buffer; @@ -579,14 +579,14 @@ const char *Menu::GetTextString(int player, page_t page, int &keys) if (m_AutoColors) { ke::SafeSprintf(buffer, - sizeof(buffer)-1, + sizeof(buffer), "%s%d. \\w%s\n", m_ItemColor.chars(), option == 10 ? 0 : option, m_OptNames[abs(MENU_EXIT)].chars()); } else { ke::SafeSprintf(buffer, - sizeof(buffer)-1, + sizeof(buffer), "%d. %s\n", option == 10 ? 0 : option, m_OptNames[abs(MENU_EXIT)].chars()); diff --git a/amxmodx/util.cpp b/amxmodx/util.cpp index 14ef3b1a..7ca7bc81 100755 --- a/amxmodx/util.cpp +++ b/amxmodx/util.cpp @@ -335,9 +335,7 @@ void UTIL_FakeClientCommand(edict_t *pEdict, const char *cmd, const char *arg1, g_fakecmd.argv[1] = arg1; g_fakecmd.argv[2] = arg2; // build argument line - ke::SafeSprintf(g_fakecmd.args, 255, "%s %s", arg1, arg2); - // if ke::SafeSprintf reached 255 chars limit, this will make sure there will be no access violation - g_fakecmd.args[255] = 0; + ke::SafeSprintf(g_fakecmd.args, sizeof(g_fakecmd.args), "%s %s", arg1, arg2); } else if (arg1) { // only one argument passed @@ -345,9 +343,7 @@ void UTIL_FakeClientCommand(edict_t *pEdict, const char *cmd, const char *arg1, // store argument g_fakecmd.argv[1] = arg1; // build argument line - ke::SafeSprintf(g_fakecmd.args, 255, "%s", arg1); - // if ke::SafeSprintf reached 255 chars limit, this will make sure there will be no access violation - g_fakecmd.args[255] = 0; + ke::SafeSprintf(g_fakecmd.args, sizeof(g_fakecmd.args), "%s", arg1); } else g_fakecmd.argc = 1; // no argmuents -> only one command diff --git a/modules/cstrike/csx/WinCSX/WinCSX.cpp b/modules/cstrike/csx/WinCSX/WinCSX.cpp index 0711bd5b..6ff54ff2 100644 --- a/modules/cstrike/csx/WinCSX/WinCSX.cpp +++ b/modules/cstrike/csx/WinCSX/WinCSX.cpp @@ -179,7 +179,7 @@ void UpdateListBox(HWND hDlg) { //if ((*b).getPosition() < 1) // umm... naaah! //continue; - ke::SafeSprintf(tempbuffer, sizeof(tempbuffer)-1, "%s", (*b).getName()); + ke::SafeSprintf(tempbuffer, sizeof(tempbuffer), "%s", (*b).getName()); SendMessage( // returns LRESULT in lResult listbox, // handle to destination control @@ -326,7 +326,7 @@ void SaveChanges(HWND hDlg) { UpdateListBox(hDlg); char buffer[256]; - ke::SafeSprintf(buffer, sizeof(buffer)-1, "New rank of %s: %d", name, newPosition); + ke::SafeSprintf(buffer, sizeof(buffer), "New rank of %s: %d", name, newPosition); MessageBox(hDlg, buffer, "Update succeeded", MB_OK); // In the listbox, we need to reselect the item we just updated. Use the new name. diff --git a/modules/engine/engine.cpp b/modules/engine/engine.cpp index bbe28a01..f0d1c7eb 100644 --- a/modules/engine/engine.cpp +++ b/modules/engine/engine.cpp @@ -945,7 +945,7 @@ static cell AMX_NATIVE_CALL traceresult(AMX *amx, cell *params) // (jghg) static cell AMX_NATIVE_CALL get_string(AMX *amx, cell *params) // (string, returnstring[], length) { - ke::SafeSprintf(g_buffer, sizeof(g_buffer)-1, "%s", STRING(params[1])); + ke::SafeSprintf(g_buffer, sizeof(g_buffer), "%s", STRING(params[1])); return MF_SetAmxString(amx, params[2], g_buffer, params[3]); } diff --git a/modules/fakemeta/pev.cpp b/modules/fakemeta/pev.cpp index 5ba8400d..97579aa4 100644 --- a/modules/fakemeta/pev.cpp +++ b/modules/fakemeta/pev.cpp @@ -299,23 +299,23 @@ static cell AMX_NATIVE_CALL amx_pev(AMX *amx,cell *params) return num; } else if (ValType & Ret_Int) { char temp[32]; - ke::SafeSprintf(temp, sizeof(temp)-1, "%d", rets.i); + ke::SafeSprintf(temp, sizeof(temp), "%d", rets.i); return MF_SetAmxString(amx, params[3], temp, size); } else if (ValType == Ret_Float) { char temp[32]; - ke::SafeSprintf(temp, sizeof(temp)-1, "%f", rets.f); + ke::SafeSprintf(temp, sizeof(temp), "%f", rets.f); return MF_SetAmxString(amx, params[3], temp, size); } else if (ValType == Ret_Vec) { char temp[32]; - ke::SafeSprintf(temp, sizeof(temp)-1, "%f %f %f", vr.x, vr.y, vr.z); + ke::SafeSprintf(temp, sizeof(temp), "%f %f %f", vr.x, vr.y, vr.z); return MF_SetAmxString(amx, params[3], temp, size); } else if (ValType == Ret_Bytes2) { char temp[32]; - ke::SafeSprintf(temp, sizeof(temp)-1, "%d %d", rets.ba[0], rets.ba[1]); + ke::SafeSprintf(temp, sizeof(temp), "%d %d", rets.ba[0], rets.ba[1]); return MF_SetAmxString(amx, params[3], temp, size); } else if (ValType == Ret_Bytes4) { char temp[32]; - ke::SafeSprintf(temp, sizeof(temp)-1, "%d %d %d %d", rets.ba[0], rets.ba[1], rets.ba[2], rets.ba[3]); + ke::SafeSprintf(temp, sizeof(temp), "%d %d %d %d", rets.ba[0], rets.ba[1], rets.ba[2], rets.ba[3]); return MF_SetAmxString(amx, params[3], temp, size); } diff --git a/modules/geoip/geoip_main.cpp b/modules/geoip/geoip_main.cpp index 6d88eb98..3e9370de 100644 --- a/modules/geoip/geoip_main.cpp +++ b/modules/geoip/geoip_main.cpp @@ -192,7 +192,7 @@ bool loadDatabase() // MF_BuildPathname not used because backslash // makes CreateFileMapping failing under windows. - ke::SafeSprintf(file, sizeof(file) - 1, "%s/%s/GeoLite2-%s.mmdb", modName, dataDir, databases[i]); + ke::SafeSprintf(file, sizeof(file), "%s/%s/GeoLite2-%s.mmdb", modName, dataDir, databases[i]); status = MMDB_open(file, MMDB_MODE_MMAP, &HandleDB); diff --git a/modules/hamsandwich/config_parser.cpp b/modules/hamsandwich/config_parser.cpp index 7589df92..42ef7e1a 100644 --- a/modules/hamsandwich/config_parser.cpp +++ b/modules/hamsandwich/config_parser.cpp @@ -109,7 +109,7 @@ static void read_mirror(char *input) *data='\0'; // mark down the source - ke::SafeSprintf(source, sizeof(source)-1, "%s", input); + ke::SafeSprintf(source, sizeof(source), "%s", input); *data=old; @@ -129,13 +129,13 @@ static void read_mirror(char *input) old=*data; *data='\0'; - ke::SafeSprintf(dest, sizeof(dest)-1, "%s", data2); + ke::SafeSprintf(dest, sizeof(dest), "%s", data2); *data=old; if (strcmp(dest, CurrentModName)==0) { - ke::SafeSprintf(CurrentModName, sizeof(CurrentModName)-1, "%s", source); + ke::SafeSprintf(CurrentModName, sizeof(CurrentModName), "%s", source); } } @@ -314,7 +314,7 @@ int ReadConfig(void) FILE *fp=fopen(FileName,"r"); - ke::SafeSprintf(CurrentModName, sizeof(CurrentModName)-1, "%s", MF_GetModname()); + ke::SafeSprintf(CurrentModName, sizeof(CurrentModName), "%s", MF_GetModname()); if (!fp) { diff --git a/modules/hamsandwich/ham_utils.h b/modules/hamsandwich/ham_utils.h index 1fafc500..1222ba9e 100644 --- a/modules/hamsandwich/ham_utils.h +++ b/modules/hamsandwich/ham_utils.h @@ -22,12 +22,12 @@ #define CHECK_FUNCTION(x) \ if (x < 0 || x >= HAM_LAST_ENTRY_DONT_USE_ME_LOL) { \ char msg[1024]; \ - ke::SafeSprintf(msg, sizeof(msg)-1, "Function out of bounds. Got: %d Max: %d", x, HAM_LAST_ENTRY_DONT_USE_ME_LOL - 1); \ + ke::SafeSprintf(msg, sizeof(msg), "Function out of bounds. Got: %d Max: %d", x, HAM_LAST_ENTRY_DONT_USE_ME_LOL - 1); \ FailPlugin(amx, x, HAM_INVALID_FUNC, msg); \ return 0; \ } else if (hooklist[x].isset == 0) { \ char msg[1024]; \ - ke::SafeSprintf(msg, sizeof(msg)-1, "Function %s is not configured in hamdata.ini.", hooklist[x].name); \ + ke::SafeSprintf(msg, sizeof(msg), "Function %s is not configured in hamdata.ini.", hooklist[x].name); \ FailPlugin(amx, x, HAM_FUNC_NOT_CONFIGURED, msg); \ return 0; \ } diff --git a/modules/hamsandwich/hook_native.cpp b/modules/hamsandwich/hook_native.cpp index 80ae274b..797fa997 100644 --- a/modules/hamsandwich/hook_native.cpp +++ b/modules/hamsandwich/hook_native.cpp @@ -707,7 +707,7 @@ static cell AMX_NATIVE_CALL RegisterHamFromEntity(AMX *amx, cell *params) // It may very well be wrong (such as lots of TS weapons have the same classname) // but it's the best we can do, and better than nothing. // (only used for display) - ke::SafeSprintf(classname, sizeof(classname) - 1, "%s", STRING(Entity->v.classname)); + ke::SafeSprintf(classname, sizeof(classname), "%s", STRING(Entity->v.classname)); // If we got here, the function is not hooked Hook *hook = new Hook(vtable, hooklist[func].vtid, hooklist[func].targetfunc, hooklist[func].isvoid, hooklist[func].needsretbuf, hooklist[func].paramcount, classname); diff --git a/modules/ns/ParticleManager.cpp b/modules/ns/ParticleManager.cpp index f9840d0f..fa8885f3 100644 --- a/modules/ns/ParticleManager.cpp +++ b/modules/ns/ParticleManager.cpp @@ -26,7 +26,7 @@ void ParticleManager::ReadFile(void) char FileName[256]; - ke::SafeSprintf(FileName, sizeof(FileName)-1, "%s/ns.ps", MF_GetModname()); + ke::SafeSprintf(FileName, sizeof(FileName), "%s/ns.ps", MF_GetModname()); FILE *fp=fopen(FileName,"r"); if (!fp) diff --git a/modules/ns/TitleManager.cpp b/modules/ns/TitleManager.cpp index 301afc9b..33348dbb 100644 --- a/modules/ns/TitleManager.cpp +++ b/modules/ns/TitleManager.cpp @@ -27,7 +27,7 @@ void TitleManager::LoadTitles(void) char FileName[128]; - ke::SafeSprintf(FileName, sizeof(FileName)-1, "%s/titles.txt", MF_GetModname()); + ke::SafeSprintf(FileName, sizeof(FileName), "%s/titles.txt", MF_GetModname()); FILE *fp=fopen(FileName,"r"); diff --git a/modules/ns/natives/particles.cpp b/modules/ns/natives/particles.cpp index 2f97e8c4..c0ebb787 100644 --- a/modules/ns/natives/particles.cpp +++ b/modules/ns/natives/particles.cpp @@ -48,7 +48,7 @@ cell PSKeyValueI(const char *name, AMX *amx, cell *params) char StrData[1024]; - ke::SafeSprintf(StrData, sizeof(StrData)-1, "%d", params[2]); + ke::SafeSprintf(StrData, sizeof(StrData), "%d", params[2]); kvd.szClassName=const_cast(STRING(reinterpret_cast(params[1])->v.classname)); kvd.szKeyName=name; @@ -71,7 +71,7 @@ cell PSKeyValueF(const char *name, AMX *amx, cell *params) char StrData[1024]; - ke::SafeSprintf(StrData, sizeof(StrData)-1, "%f", amx_ctof2(params[2])); + ke::SafeSprintf(StrData, sizeof(StrData), "%f", amx_ctof2(params[2])); kvd.szClassName=const_cast(STRING(reinterpret_cast(params[1])->v.classname)); kvd.szKeyName=name;