summaryrefslogtreecommitdiff
path: root/src/common/HPM.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/HPM.c')
-rw-r--r--src/common/HPM.c51
1 files changed, 38 insertions, 13 deletions
diff --git a/src/common/HPM.c b/src/common/HPM.c
index dbe121940..1fad7102f 100644
--- a/src/common/HPM.c
+++ b/src/common/HPM.c
@@ -103,6 +103,7 @@ void hplugin_export_symbol(void *value, const char *name)
void *hplugin_import_symbol(char *name, unsigned int pID)
{
int i;
+ nullpo_retr(NULL, name);
ARR_FIND(0, VECTOR_LENGTH(HPM->symbols), i, strcmp(VECTOR_INDEX(HPM->symbols, i)->name, name) == 0);
if (i != VECTOR_LENGTH(HPM->symbols))
@@ -133,6 +134,7 @@ bool hplugin_iscompatible(char* version) {
bool hplugin_exists(const char *filename)
{
int i;
+ nullpo_retr(false, filename);
for (i = 0; i < VECTOR_LENGTH(HPM->plugins); i++) {
if (strcmpi(VECTOR_INDEX(HPM->plugins, i)->filename,filename) == 0)
return true;
@@ -259,6 +261,7 @@ void hplugins_addToHPData(enum HPluginDataTypes type, uint32 pluginID, struct hp
return;
}
store = *storeptr;
+ nullpo_retv(store);
/* duplicate check */
ARR_FIND(0, VECTOR_LENGTH(store->entries), i, VECTOR_INDEX(store->entries, i)->pluginID == pluginID && VECTOR_INDEX(store->entries, i)->classid == classid);
@@ -447,7 +450,8 @@ bool hplugins_addconf(unsigned int pluginID, enum HPluginConfType type, char *na
return true;
}
-struct hplugin *hplugin_load(const char* filename) {
+struct hplugin *hplugin_load(const char* filename)
+{
struct hplugin *plugin;
struct hplugin_info *info;
struct HPMi_interface **HPMi;
@@ -563,6 +567,7 @@ struct hplugin *hplugin_load(const char* filename) {
/* id */
plugin->hpi->pid = plugin->idx;
/* core */
+ plugin->hpi->memmgr = HPMiMalloc;
#ifdef CONSOLE_INPUT
plugin->hpi->addCPCommand = console->input->addCommand;
#endif // CONSOLE_INPUT
@@ -596,6 +601,7 @@ struct hplugin *hplugin_load(const char* filename) {
void hplugin_unload(struct hplugin* plugin)
{
int i;
+ nullpo_retv(plugin);
if (plugin->filename)
aFree(plugin->filename);
if (plugin->dll)
@@ -622,7 +628,8 @@ CMDLINEARG(loadplugin)
/**
* Reads the plugin configuration and loads the plugins as necessary.
*/
-void hplugins_config_read(void) {
+void hplugins_config_read(void)
+{
struct config_t plugins_conf;
struct config_setting_t *plist = NULL;
const char *config_filename = "conf/plugins.conf"; // FIXME hardcoded name
@@ -788,6 +795,7 @@ const char *HPM_file2ptr(const char *file)
{
int i;
+ nullpo_retr(NULL, file);
ARR_FIND(0, HPM->filenames.count, i, HPM->filenames.data[i].addr == file);
if (i != HPM->filenames.count) {
return HPM->filenames.data[i].name;
@@ -801,19 +809,29 @@ const char *HPM_file2ptr(const char *file)
return HPM->filenames.data[i].name;
}
-void* HPM_mmalloc(size_t size, const char *file, int line, const char *func) {
+
+void* HPM_mmalloc(size_t size, const char *file, int line, const char *func)
+{
return iMalloc->malloc(size,HPM_file2ptr(file),line,func);
}
-void* HPM_calloc(size_t num, size_t size, const char *file, int line, const char *func) {
+
+void* HPM_calloc(size_t num, size_t size, const char *file, int line, const char *func)
+{
return iMalloc->calloc(num,size,HPM_file2ptr(file),line,func);
}
-void* HPM_realloc(void *p, size_t size, const char *file, int line, const char *func) {
+
+void* HPM_realloc(void *p, size_t size, const char *file, int line, const char *func)
+{
return iMalloc->realloc(p,size,HPM_file2ptr(file),line,func);
}
-void* HPM_reallocz(void *p, size_t size, const char *file, int line, const char *func) {
+
+void* HPM_reallocz(void *p, size_t size, const char *file, int line, const char *func)
+{
return iMalloc->reallocz(p,size,HPM_file2ptr(file),line,func);
}
-char* HPM_astrdup(const char *p, const char *file, int line, const char *func) {
+
+char* HPM_astrdup(const char *p, const char *file, int line, const char *func)
+{
return iMalloc->astrdup(p,HPM_file2ptr(file),line,func);
}
@@ -849,6 +867,7 @@ bool hplugins_get_battle_conf(const char *w1, int *value)
{
int i;
+ nullpo_retr(w1, value);
nullpo_retr(false, value);
ARR_FIND(0, VECTOR_LENGTH(HPM->config_listeners[HPCT_BATTLE]), i, strcmpi(w1, VECTOR_INDEX(HPM->config_listeners[HPCT_BATTLE], i).key) == 0);
@@ -880,7 +899,7 @@ bool hplugins_parse_conf(const struct config_t *config, const char *filename, en
for (i = 0; i < VECTOR_LENGTH(HPM->config_listeners[point]); i++) {
const struct HPConfListenStorage *entry = &VECTOR_INDEX(HPM->config_listeners[point], i);
const char *config_name = entry->key;
- const char *str = buf;
+ const char *str = NULL;
if ((setting = libconfig->lookup(config, config_name)) == NULL) {
if (!imported && entry->required) {
ShowWarning("Missing configuration '%s' in file %s!\n", config_name, filename);
@@ -1012,9 +1031,11 @@ void hplugin_data_store_create(struct hplugin_data_store **storeptr, enum HPlugi
/**
* Called by HPM->DataCheck on a plugins incoming data, ensures data structs in use are matching!
**/
-bool HPM_DataCheck(struct s_HPMDataCheck *src, unsigned int size, int version, char *name) {
+bool HPM_DataCheck(struct s_HPMDataCheck *src, unsigned int size, int version, char *name)
+{
unsigned int i, j;
+ nullpo_retr(false, src);
if (version != datacheck_version) {
ShowError("HPMDataCheck:%s: DataCheck API version mismatch %d != %d\n", name, datacheck_version, version);
return false;
@@ -1039,7 +1060,8 @@ bool HPM_DataCheck(struct s_HPMDataCheck *src, unsigned int size, int version, c
return true;
}
-void HPM_datacheck_init(const struct s_HPMDataCheck *src, unsigned int length, int version) {
+void HPM_datacheck_init(const struct s_HPMDataCheck *src, unsigned int length, int version)
+{
unsigned int i;
datacheck_version = version;
@@ -1055,11 +1077,13 @@ void HPM_datacheck_init(const struct s_HPMDataCheck *src, unsigned int length, i
}
}
-void HPM_datacheck_final(void) {
+void HPM_datacheck_final(void)
+{
db_destroy(datacheck_db);
}
-void hpm_init(void) {
+void hpm_init(void)
+{
int i;
datacheck_db = NULL;
datacheck_data = NULL;
@@ -1070,8 +1094,8 @@ void hpm_init(void) {
HPM->off = false;
- memcpy(&iMalloc_HPM, iMalloc, sizeof(struct malloc_interface));
HPMiMalloc = &iMalloc_HPM;
+ *HPMiMalloc = *iMalloc;
HPMiMalloc->malloc = HPM_mmalloc;
HPMiMalloc->calloc = HPM_calloc;
HPMiMalloc->realloc = HPM_realloc;
@@ -1151,6 +1175,7 @@ void hpm_final(void)
return;
}
+
void hpm_defaults(void)
{
HPM = &HPM_s;