Fixed crash when reloading blocked plugins fails (bug 4038, r+a=fyren).

This commit is contained in:
David Anderson 2009-10-02 03:33:59 -07:00
parent 3f264097a7
commit dc0d6a9b4a

View File

@ -60,7 +60,7 @@ CPlugin::CPlugin(const char *file)
m_serial = ++MySerial; m_serial = ++MySerial;
m_pRuntime = NULL; m_pRuntime = NULL;
m_errormsg[sizeof(m_errormsg) - 1] = '\0'; m_errormsg[sizeof(m_errormsg) - 1] = '\0';
snprintf(m_filename, sizeof(m_filename), "%s", file); UTIL_Format(m_filename, sizeof(m_filename), "%s", file);
m_handle = 0; m_handle = 0;
m_ident = NULL; m_ident = NULL;
m_pProps = sm_trie_create(); m_pProps = sm_trie_create();
@ -164,7 +164,7 @@ CPlugin *CPlugin::CreatePlugin(const char *file, char *error, size_t maxlength)
{ {
if (error) if (error)
{ {
snprintf(error, maxlength, "Unable to open file"); UTIL_Format(error, maxlength, "Unable to open file");
} }
pPlugin->m_status = Plugin_BadLoad; pPlugin->m_status = Plugin_BadLoad;
return pPlugin; return pPlugin;
@ -210,7 +210,7 @@ void CPlugin::SetErrorState(PluginStatus status, const char *error_fmt, ...)
va_list ap; va_list ap;
va_start(ap, error_fmt); va_start(ap, error_fmt);
vsnprintf(m_errormsg, sizeof(m_errormsg), error_fmt, ap); UTIL_FormatArgs(m_errormsg, sizeof(m_errormsg), error_fmt, ap);
va_end(ap); va_end(ap);
if (m_pRuntime != NULL) if (m_pRuntime != NULL)
@ -872,7 +872,7 @@ void CPluginManager::LoadPluginsFromDir(const char *basedir, const char *localpa
if (localpath == NULL) if (localpath == NULL)
{ {
/* If no path yet, don't add a former slash */ /* If no path yet, don't add a former slash */
snprintf(new_local, sizeof(new_local), "%s", dir->GetEntryName()); UTIL_Format(new_local, sizeof(new_local), "%s", dir->GetEntryName());
} else { } else {
g_LibSys.PathFormat(new_local, sizeof(new_local), "%s/%s", localpath, dir->GetEntryName()); g_LibSys.PathFormat(new_local, sizeof(new_local), "%s/%s", localpath, dir->GetEntryName());
} }
@ -887,7 +887,7 @@ void CPluginManager::LoadPluginsFromDir(const char *basedir, const char *localpa
char plugin[PLATFORM_MAX_PATH]; char plugin[PLATFORM_MAX_PATH];
if (localpath == NULL) if (localpath == NULL)
{ {
snprintf(plugin, sizeof(plugin), "%s", name); UTIL_Format(plugin, sizeof(plugin), "%s", name);
} else { } else {
g_LibSys.PathFormat(plugin, sizeof(plugin), "%s/%s", localpath, name); g_LibSys.PathFormat(plugin, sizeof(plugin), "%s/%s", localpath, name);
} }
@ -986,7 +986,7 @@ LoadRes CPluginManager::_LoadPlugin(CPlugin **_plugin, const char *path, bool de
{ {
if (error) if (error)
{ {
snprintf(error, maxlength, "Unable to set JIT option (key \"%s\") (value \"%s\")", key, val); UTIL_Format(error, maxlength, "Unable to set JIT option (key \"%s\") (value \"%s\")", key, val);
} }
co->Abort(); co->Abort();
co = NULL; co = NULL;
@ -1005,7 +1005,7 @@ LoadRes CPluginManager::_LoadPlugin(CPlugin **_plugin, const char *path, bool de
pPlugin->m_pRuntime = g_pSourcePawn2->LoadPlugin(co, fullpath, &err); pPlugin->m_pRuntime = g_pSourcePawn2->LoadPlugin(co, fullpath, &err);
if (pPlugin->m_pRuntime == NULL) if (pPlugin->m_pRuntime == NULL)
{ {
snprintf(error, UTIL_Format(error,
maxlength, maxlength,
"Unable to load plugin (error %d: %s)", "Unable to load plugin (error %d: %s)",
err, err,
@ -1084,6 +1084,8 @@ IPlugin *CPluginManager::LoadPlugin(const char *path, bool debug, PluginType typ
} }
if (res == LoadRes_NeverLoad) if (res == LoadRes_NeverLoad)
{
if (error)
{ {
if (m_LoadingLocked) if (m_LoadingLocked)
{ {
@ -1093,6 +1095,7 @@ IPlugin *CPluginManager::LoadPlugin(const char *path, bool debug, PluginType typ
{ {
UTIL_Format(error, maxlength, "This plugin is blocked from loading (see plugin_settings.cfg)"); UTIL_Format(error, maxlength, "This plugin is blocked from loading (see plugin_settings.cfg)");
} }
}
return NULL; return NULL;
} }
@ -1221,7 +1224,7 @@ bool CPluginManager::FindOrRequirePluginDeps(CPlugin *pPlugin, char *error, size
{ {
if (error) if (error)
{ {
snprintf(error, maxlength, "Fatal error during initializing plugin load"); UTIL_Format(error, maxlength, "Fatal error during initializing plugin load");
} }
return false; return false;
} }
@ -1254,7 +1257,7 @@ bool CPluginManager::FindOrRequirePluginDeps(CPlugin *pPlugin, char *error, size
{ {
if (error) if (error)
{ {
snprintf(error, maxlength, "Could not find required plugin \"%s\"", name); UTIL_Format(error, maxlength, "Could not find required plugin \"%s\"", name);
} }
return false; return false;
} }
@ -1325,7 +1328,7 @@ bool CPluginManager::LoadOrRequireExtensions(CPlugin *pPlugin, unsigned int pass
{ {
if (error) if (error)
{ {
snprintf(error, maxlength, "Required extension \"%s\" file(\"%s\") not running", name, file); UTIL_Format(error, maxlength, "Required extension \"%s\" file(\"%s\") not running", name, file);
} }
return false; return false;
} }
@ -1393,7 +1396,7 @@ bool CPluginManager::RunSecondPass(CPlugin *pPlugin, char *error, size_t maxleng
{ {
if (error) if (error)
{ {
snprintf(error, maxlength, "Native \"%s\" was not found", native->name); UTIL_Format(error, maxlength, "Native \"%s\" was not found", native->name);
} }
return false; return false;
} }