From 5b3a3cef27e7de7c15eacc31c86b7209f5d65de3 Mon Sep 17 00:00:00 2001 From: Scott Ehlert Date: Thu, 22 Mar 2007 21:12:17 +0000 Subject: [PATCH] Made this more consistent or something... --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40658 --- core/Translator.cpp | 2 +- core/smn_filesystem.cpp | 18 +++++++++--------- core/sourcemod.cpp | 2 +- core/sourcemod.h | 4 ++-- core/systems/ExtensionSys.cpp | 10 +++++----- core/systems/LibrarySys.cpp | 8 ++++++-- core/systems/PluginSys.cpp | 14 +++++++------- core/systems/PluginSys.h | 2 +- 8 files changed, 32 insertions(+), 28 deletions(-) diff --git a/core/Translator.cpp b/core/Translator.cpp index c9827e5e..0d307ce4 100644 --- a/core/Translator.cpp +++ b/core/Translator.cpp @@ -101,7 +101,7 @@ void CPhraseFile::ReparseFile() } SMCParseError err; - char path[PLATFORM_MAX_PATH+1]; + char path[PLATFORM_MAX_PATH]; g_SourceMod.BuildPath(Path_SM, path, PLATFORM_MAX_PATH, "translations/%s", m_File.c_str()); unsigned int line=0, col=0; diff --git a/core/smn_filesystem.cpp b/core/smn_filesystem.cpp index 9cad4d6c..601a74c9 100644 --- a/core/smn_filesystem.cpp +++ b/core/smn_filesystem.cpp @@ -64,7 +64,7 @@ static cell_t sm_OpenDirectory(IPluginContext *pContext, const cell_t *params) return 0; } - char realpath[PLATFORM_MAX_PATH+1]; + char realpath[PLATFORM_MAX_PATH]; g_SourceMod.BuildPath(Path_Game, realpath, sizeof(realpath), "%s", path); IDirectory *pDir = g_LibSys.OpenDirectory(realpath); @@ -142,7 +142,7 @@ static cell_t sm_OpenFile(IPluginContext *pContext, const cell_t *params) return 0; } - char realpath[PLATFORM_MAX_PATH+1]; + char realpath[PLATFORM_MAX_PATH]; g_SourceMod.BuildPath(Path_Game, realpath, sizeof(realpath), "%s", name); FILE *pFile = fopen(realpath, mode); @@ -164,7 +164,7 @@ static cell_t sm_DeleteFile(IPluginContext *pContext, const cell_t *params) return 0; } - char realpath[PLATFORM_MAX_PATH+1]; + char realpath[PLATFORM_MAX_PATH]; g_SourceMod.BuildPath(Path_Game, realpath, sizeof(realpath), "%s", name); return (unlink(realpath)) ? 0 : 1; @@ -271,7 +271,7 @@ static cell_t sm_FileExists(IPluginContext *pContext, const cell_t *params) return 0; } - char realpath[PLATFORM_MAX_PATH+1]; + char realpath[PLATFORM_MAX_PATH]; g_SourceMod.BuildPath(Path_Game, realpath, sizeof(realpath), "%s", name); #ifdef PLATFORM_WINDOWS struct _stat s; @@ -313,9 +313,9 @@ static cell_t sm_RenameFile(IPluginContext *pContext, const cell_t *params) return 0; } - char new_realpath[PLATFORM_MAX_PATH+1]; + char new_realpath[PLATFORM_MAX_PATH]; g_SourceMod.BuildPath(Path_Game, new_realpath, sizeof(new_realpath), "%s", newpath); - char old_realpath[PLATFORM_MAX_PATH+1]; + char old_realpath[PLATFORM_MAX_PATH]; g_SourceMod.BuildPath(Path_Game, old_realpath, sizeof(old_realpath), "%s", oldpath); #ifdef PLATFORM_WINDOWS @@ -335,7 +335,7 @@ static cell_t sm_DirExists(IPluginContext *pContext, const cell_t *params) return 0; } - char realpath[PLATFORM_MAX_PATH+1]; + char realpath[PLATFORM_MAX_PATH]; g_SourceMod.BuildPath(Path_Game, realpath, sizeof(realpath), "%s", name); #ifdef PLATFORM_WINDOWS struct _stat s; @@ -372,7 +372,7 @@ static cell_t sm_FileSize(IPluginContext *pContext, const cell_t *params) return -1; } - char realpath[PLATFORM_MAX_PATH+1]; + char realpath[PLATFORM_MAX_PATH]; g_SourceMod.BuildPath(Path_Game, realpath, sizeof(realpath), "%s", name); #ifdef PLATFORM_WINDOWS struct _stat s; @@ -409,7 +409,7 @@ static cell_t sm_RemoveDir(IPluginContext *pContext, const cell_t *params) return 0; } - char realpath[PLATFORM_MAX_PATH+1]; + char realpath[PLATFORM_MAX_PATH]; g_SourceMod.BuildPath(Path_Game, realpath, sizeof(realpath), "%s", name); return (rmdir(realpath)) ? 0 : 1; diff --git a/core/sourcemod.cpp b/core/sourcemod.cpp index e537ad8b..eee4d010 100644 --- a/core/sourcemod.cpp +++ b/core/sourcemod.cpp @@ -286,7 +286,7 @@ void SourceModBase::DoGlobalPluginLoads() size_t SourceModBase::BuildPath(PathType type, char *buffer, size_t maxlength, char *format, ...) { - char _buffer[PLATFORM_MAX_PATH+1]; + char _buffer[PLATFORM_MAX_PATH]; va_list ap; va_start(ap, format); diff --git a/core/sourcemod.h b/core/sourcemod.h index 0a4009a4..dcd48c29 100644 --- a/core/sourcemod.h +++ b/core/sourcemod.h @@ -92,8 +92,8 @@ private: void GameFrame(bool simulating); private: CStack m_freepacks; - char m_SMBaseDir[PLATFORM_MAX_PATH+1]; - char m_SMRelDir[PLATFORM_MAX_PATH+1]; + char m_SMBaseDir[PLATFORM_MAX_PATH]; + char m_SMRelDir[PLATFORM_MAX_PATH]; bool m_IsMapLoading; bool m_ExecPluginReload; unsigned int m_target; diff --git a/core/systems/ExtensionSys.cpp b/core/systems/ExtensionSys.cpp index 5d77c5b7..f6200124 100644 --- a/core/systems/ExtensionSys.cpp +++ b/core/systems/ExtensionSys.cpp @@ -33,7 +33,7 @@ CExtension::CExtension(const char *filename, char *error, size_t err_max) unload_code = 0; m_FullyLoaded = false; - char path[PLATFORM_MAX_PATH+1]; + char path[PLATFORM_MAX_PATH]; g_SourceMod.BuildPath(Path_SM, path, PLATFORM_MAX_PATH, "extensions/%s", filename); m_pLib = g_LibSys.OpenLibrary(path, error, err_max); @@ -317,7 +317,7 @@ IExtension *CExtensionManager::LoadAutoExtension(const char *path) { if (!strstr(path, "." PLATFORM_LIB_EXT)) { - char newpath[PLATFORM_MAX_PATH+1]; + char newpath[PLATFORM_MAX_PATH]; snprintf(newpath, PLATFORM_MAX_PATH, "%s.%s", path, PLATFORM_LIB_EXT); return LoadAutoExtension(newpath); } @@ -355,7 +355,7 @@ IExtension *CExtensionManager::FindExtensionByFile(const char *file) } /* Make sure the file direction is right */ - char path[PLATFORM_MAX_PATH+1]; + char path[PLATFORM_MAX_PATH]; g_LibSys.PathFormat(path, PLATFORM_MAX_PATH, "%s", file); for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++) @@ -768,7 +768,7 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmd, unsigned int argco const char *unload = g_RootMenu.GetArgument(4); if (pExt->unload_code == (unsigned)atoi(unload)) { - char filename[PLATFORM_MAX_PATH+1]; + char filename[PLATFORM_MAX_PATH]; snprintf(filename, PLATFORM_MAX_PATH, "%s", pExt->GetFilename()); UnloadExtension(pExt); g_RootMenu.ConsolePrint("[SM] Extension %s is now unloaded.", filename); @@ -781,7 +781,7 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmd, unsigned int argco if (!pExt->IsLoaded() || (!pExt->m_Deps.size() && !pExt->m_Plugins.size())) { - char filename[PLATFORM_MAX_PATH+1]; + char filename[PLATFORM_MAX_PATH]; snprintf(filename, PLATFORM_MAX_PATH, "%s", pExt->GetFilename()); UnloadExtension(pExt); g_RootMenu.ConsolePrint("[SM] Extension %s is now unloaded.", filename); diff --git a/core/systems/LibrarySys.cpp b/core/systems/LibrarySys.cpp index cc52530d..7304c4d6 100644 --- a/core/systems/LibrarySys.cpp +++ b/core/systems/LibrarySys.cpp @@ -301,11 +301,15 @@ ILibrary *LibrarySystem::OpenLibrary(const char *path, char *error, size_t err_m size_t LibrarySystem::PathFormat(char *buffer, size_t len, const char *fmt, ...) { va_list ap; - va_start(ap,fmt); + va_start(ap, fmt); size_t mylen = vsnprintf(buffer, len, fmt, ap); va_end(ap); - mylen = (mylen >= len) ? len : mylen; + if (mylen >= len) + { + mylen = len - 1; + buffer[mylen] = '\0'; + } for (size_t i=0; iGetEntryName(), "disabled") != 0) && (strcmp(dir->GetEntryName(), "optional") != 0)) { - char new_local[PLATFORM_MAX_PATH+1]; + char new_local[PLATFORM_MAX_PATH]; if (localpath == NULL) { /* If no path yet, don't add a former slash */ @@ -724,7 +724,7 @@ void CPluginManager::LoadPluginsFromDir(const char *basedir, const char *localpa && strcmp(&name[len-4], ".smx") == 0) { /* If the filename matches, load the plugin */ - char plugin[PLATFORM_MAX_PATH+1]; + char plugin[PLATFORM_MAX_PATH]; if (localpath == NULL) { snprintf(plugin, sizeof(plugin), "%s", name); @@ -944,7 +944,7 @@ bool CPluginManager::LoadOrRequireExtensions(CPlugin *pPlugin, unsigned int pass uint32_t num = pBase->GetPubVarsNum(); sp_pubvar_t *pubvar; IExtension *pExt; - char path[PLATFORM_MAX_PATH+1]; + char path[PLATFORM_MAX_PATH]; char *file, *name; for (uint32_t i=0; iGetPlugin(); - char name[PLATFORM_MAX_PATH+1]; + char name[PLATFORM_MAX_PATH]; const sm_plugininfo_t *info = pl->GetPublicInfo(); strcpy(name, (IS_STR_FILLED(info->name)) ? info->name : pl->GetFilename()); diff --git a/core/systems/PluginSys.h b/core/systems/PluginSys.h index 3f010148..f421c5ab 100644 --- a/core/systems/PluginSys.h +++ b/core/systems/PluginSys.h @@ -229,7 +229,7 @@ protected: private: ContextPair m_ctx; PluginType m_type; - char m_filename[PLATFORM_MAX_PATH+1]; + char m_filename[PLATFORM_MAX_PATH]; PluginStatus m_status; unsigned int m_serial; sm_plugininfo_t m_info;