diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2010-10-10 17:49:47 +0200 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2010-10-10 17:49:47 +0200 |
commit | 773bdc8d18125e557e6468caaecab4613c585a97 (patch) | |
tree | 6b2ca6efd24feb40bc4e85b585e744bfa5056ba1 /src | |
parent | 8d6c5e9e4c9602142c24745e2affcc6b1f7fa8d6 (diff) | |
download | weechat-773bdc8d18125e557e6468caaecab4613c585a97.zip |
Allow null value for hashtable entries
Diffstat (limited to 'src')
-rw-r--r-- | src/core/wee-command.c | 19 | ||||
-rw-r--r-- | src/core/wee-hashtable.c | 37 |
2 files changed, 40 insertions, 16 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c index 6e96df80d..b46217f14 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -509,12 +509,21 @@ command_buffer_display_localvar (void *data, (void) data; (void) hashtable; - if (key && value) + if (key) { - gui_chat_printf (NULL, - " %s: \"%s\"", - (const char *)key, - (const char *)value); + if (value) + { + gui_chat_printf (NULL, + " %s: \"%s\"", + (const char *)key, + (const char *)value); + } + else + { + gui_chat_printf (NULL, + " %s: (null)", + (const char *)key); + } } } diff --git a/src/core/wee-hashtable.c b/src/core/wee-hashtable.c index 24476e402..ea1d1b38a 100644 --- a/src/core/wee-hashtable.c +++ b/src/core/wee-hashtable.c @@ -163,13 +163,18 @@ hashtable_alloc_type (enum t_hashtable_type type, void *value, int size_value, switch (type) { case HASHTABLE_INTEGER: - *pointer = malloc (sizeof (int)); - if (*pointer) - *((int *)(*pointer)) = *((int *)value); + if (value) + { + *pointer = malloc (sizeof (int)); + if (*pointer) + *((int *)(*pointer)) = *((int *)value); + } + else + *pointer = NULL; *size = (*pointer) ? sizeof (int) : 0; break; case HASHTABLE_STRING: - *pointer = strdup ((const char *)value); + *pointer = (value) ? strdup ((const char *)value) : NULL; *size = (*pointer) ? strlen (*pointer) + 1 : 0; break; case HASHTABLE_POINTER: @@ -177,15 +182,25 @@ hashtable_alloc_type (enum t_hashtable_type type, void *value, int size_value, *size = sizeof (void *); break; case HASHTABLE_BUFFER: - *pointer = malloc (size_value); - if (*pointer) - memcpy (*pointer, value, size_value); + if (value) + { + *pointer = malloc (size_value); + if (*pointer) + memcpy (*pointer, value, size_value); + } + else + *pointer = NULL; *size = (*pointer) ? size_value : 0; break; case HASHTABLE_TIME: - *pointer = malloc (sizeof (time_t)); - if (*pointer) - *((time_t *)(*pointer)) = *((time_t *)value); + if (value) + { + *pointer = malloc (sizeof (time_t)); + if (*pointer) + *((time_t *)(*pointer)) = *((time_t *)value); + } + else + *pointer = NULL; *size = (*pointer) ? sizeof (time_t) : 0; break; case HASHTABLE_NUM_TYPES: @@ -229,7 +244,7 @@ hashtable_set_with_size (struct t_hashtable *hashtable, unsigned int hash; struct t_hashtable_item *ptr_item, *pos_item, *new_item; - if (!hashtable + if (!hashtable || !key || ((hashtable->type_keys == HASHTABLE_BUFFER) && (key_size <= 0)) || ((hashtable->type_values == HASHTABLE_BUFFER) && (value_size <= 0))) { |