diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2009-02-05 18:09:58 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2009-02-05 18:09:58 +0100 |
commit | 52f68cc615308c9e19f3186dd371b96a0519a9ef (patch) | |
tree | 2b14f19a05cb43eb6402db35d72e37206171f913 | |
parent | d7bec49b713608d0b1caeb8e5f2fee790de2f14c (diff) | |
download | weechat-52f68cc615308c9e19f3186dd371b96a0519a9ef.zip |
Add some extra tests on arguments for config functions
-rw-r--r-- | src/core/wee-config-file.c | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/src/core/wee-config-file.c b/src/core/wee-config-file.c index 8d4b79439..738441505 100644 --- a/src/core/wee-config-file.c +++ b/src/core/wee-config-file.c @@ -232,12 +232,15 @@ struct t_config_option * config_file_option_find_pos (struct t_config_section *section, const char *name) { struct t_config_option *ptr_option; - - for (ptr_option = section->options; ptr_option; - ptr_option = ptr_option->next_option) + + if (section && name) { - if (string_strcasecmp (name, ptr_option->name) < 0) - return ptr_option; + for (ptr_option = section->options; ptr_option; + ptr_option = ptr_option->next_option) + { + if (string_strcasecmp (name, ptr_option->name) < 0) + return ptr_option; + } } /* position not found (we will add to the end of list) */ @@ -254,7 +257,7 @@ config_file_option_insert_in_section (struct t_config_option *option) { struct t_config_option *pos_option; - if (!option->section) + if (!option || !option->section) return; if (option->section->options) @@ -522,6 +525,9 @@ config_file_option_full_name (struct t_config_option *option) int length_option; char *option_full_name; + if (!option) + return NULL; + length_option = strlen (option->config_file->name) + 1 + strlen (option->section->name) + 1 + strlen (option->name) + 1; option_full_name = malloc (length_option); @@ -1187,6 +1193,9 @@ config_file_option_set_null (struct t_config_option *option, int run_callback) int rc; char *option_full_name; + if (!option) + return WEECHAT_CONFIG_OPTION_SET_ERROR; + rc = WEECHAT_CONFIG_OPTION_SET_ERROR; /* null value is authorized only if it's allowed in option */ @@ -1243,6 +1252,9 @@ config_file_option_unset (struct t_config_option *option) int rc; char *option_full_name; + if (!option) + return WEECHAT_CONFIG_OPTION_UNSET_ERROR; + rc = WEECHAT_CONFIG_OPTION_UNSET_OK_NO_RESET; if (option->section && option->section->user_can_delete_options) @@ -1305,7 +1317,7 @@ void config_file_option_rename (struct t_config_option *option, const char *new_name) { - if (!new_name || !new_name[0] + if (!option || !new_name || !new_name[0] || config_file_search_option (option->config_file, option->section, new_name)) return; @@ -1340,6 +1352,9 @@ void * config_file_option_get_pointer (struct t_config_option *option, const char *property) { + if (!option || !property) + return NULL; + if (string_strcasecmp (property, "config_file") == 0) return option->config_file; else if (string_strcasecmp (property, "section") == 0) |