diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2010-10-16 11:30:42 +0200 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2010-10-16 11:30:42 +0200 |
commit | eff0f9abdb53b0c0e1c2060a6f9598c51347e1bb (patch) | |
tree | b76343d396442477bd48227258736cda1c8f15af /src/core | |
parent | 880163d78401d37956295067e5671e1d112cff6e (diff) | |
download | weechat-eff0f9abdb53b0c0e1c2060a6f9598c51347e1bb.zip |
Fix crash in hashtable_get_string with "values" or "keys_values" when some values in hashtable are NULL
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/wee-hashtable.c | 105 |
1 files changed, 63 insertions, 42 deletions
diff --git a/src/core/wee-hashtable.c b/src/core/wee-hashtable.c index 013256026..4575f3d95 100644 --- a/src/core/wee-hashtable.c +++ b/src/core/wee-hashtable.c @@ -480,21 +480,28 @@ hashtable_compute_length_values_cb (void *data, (void) key; length = (int *)data; - - switch (hashtable->type_values) + + if (value) { - case HASHTABLE_INTEGER: - snprintf (str_int, sizeof (str_int), "%d", *((int *)value)); - *length += strlen (str_int) + 1; - break; - case HASHTABLE_STRING: - *length += strlen ((char *)value) + 1; - break; - case HASHTABLE_POINTER: - case HASHTABLE_BUFFER: - case HASHTABLE_TIME: - case HASHTABLE_NUM_TYPES: - break; + switch (hashtable->type_values) + { + case HASHTABLE_INTEGER: + snprintf (str_int, sizeof (str_int), "%d", *((int *)value)); + *length += strlen (str_int) + 1; + break; + case HASHTABLE_STRING: + *length += strlen ((char *)value) + 1; + break; + case HASHTABLE_POINTER: + case HASHTABLE_BUFFER: + case HASHTABLE_TIME: + case HASHTABLE_NUM_TYPES: + break; + } + } + else + { + *length += strlen ("(null)"); } } @@ -567,21 +574,28 @@ hashtable_build_string_values_cb (void *data, if (str[0]) strcat (str, ","); - - switch (hashtable->type_values) + + if (value) { - case HASHTABLE_INTEGER: - snprintf (str_int, sizeof (str_int), "%d", *((int *)value)); - strcat (str, str_int); - break; - case HASHTABLE_STRING: - strcat (str, (char *)value); - break; - case HASHTABLE_POINTER: - case HASHTABLE_BUFFER: - case HASHTABLE_TIME: - case HASHTABLE_NUM_TYPES: - break; + switch (hashtable->type_values) + { + case HASHTABLE_INTEGER: + snprintf (str_int, sizeof (str_int), "%d", *((int *)value)); + strcat (str, str_int); + break; + case HASHTABLE_STRING: + strcat (str, (char *)value); + break; + case HASHTABLE_POINTER: + case HASHTABLE_BUFFER: + case HASHTABLE_TIME: + case HASHTABLE_NUM_TYPES: + break; + } + } + else + { + strcat (str, "(null)"); } } @@ -622,21 +636,28 @@ hashtable_build_string_keys_values_cb (void *data, } strcat (str, ":"); - - switch (hashtable->type_values) + + if (value) { - case HASHTABLE_INTEGER: - snprintf (str_int, sizeof (str_int), "%d", *((int *)value)); - strcat (str, str_int); - break; - case HASHTABLE_STRING: - strcat (str, (char *)value); - break; - case HASHTABLE_POINTER: - case HASHTABLE_BUFFER: - case HASHTABLE_TIME: - case HASHTABLE_NUM_TYPES: - break; + switch (hashtable->type_values) + { + case HASHTABLE_INTEGER: + snprintf (str_int, sizeof (str_int), "%d", *((int *)value)); + strcat (str, str_int); + break; + case HASHTABLE_STRING: + strcat (str, (char *)value); + break; + case HASHTABLE_POINTER: + case HASHTABLE_BUFFER: + case HASHTABLE_TIME: + case HASHTABLE_NUM_TYPES: + break; + } + } + else + { + strcat (str, "(null)"); } } |