diff --git a/ChangeLog b/ChangeLog index d07b225d7..c51df9dca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,10 +1,11 @@ WeeChat - Wee Enhanced Environment for Chat =========================================== -ChangeLog - 2007-03-16 +ChangeLog - 2007-03-20 Version 0.2.4 (under dev!): + * fixed bug with explode_string / free_exploded_string when max_items > 0 * added new key (ctrl-R) for interactive and incremental search in buffer history (task #6628) * fixed /topic completion when no topic set on current channel (bug #19322) diff --git a/src/common/util.c b/src/common/util.c index 657f40380..badc22b61 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -455,33 +455,30 @@ explode_string (char *string, char *separators, int num_items_max, if (num_items != NULL) *num_items = 0; - - n_items = num_items_max; - + if (!string || !string[0]) return NULL; - - if (num_items_max == 0) + + /* calculate number of items */ + ptr = string; + i = 1; + while ((ptr = strpbrk (ptr, separators))) { - /* calculate number of items */ - ptr = string; - i = 1; - while ((ptr = strpbrk (ptr, separators))) - { - while (strchr (separators, ptr[0]) != NULL) - ptr++; - i++; - } - n_items = i; + while (strchr (separators, ptr[0]) != NULL) + ptr++; + i++; } + n_items = i; + if ((num_items_max != 0) && (n_items > num_items_max)) + n_items = num_items_max; + array = - (char **) malloc ((num_items_max ? n_items : n_items + 1) * - sizeof (char *)); - + (char **) malloc ((n_items + 1) * sizeof (char *)); + ptr1 = string; ptr2 = string; - + for (i = 0; i < n_items; i++) { while (strchr (separators, ptr1[0]) != NULL) @@ -490,7 +487,7 @@ explode_string (char *string, char *separators, int num_items_max, if ((ptr2 = strchr (ptr1, '\r')) == NULL) if ((ptr2 = strchr (ptr1, '\n')) == NULL) ptr2 = strchr (ptr1, '\0'); - + if ((ptr1 == NULL) || (ptr2 == NULL)) { array[i] = NULL; @@ -511,18 +508,11 @@ explode_string (char *string, char *separators, int num_items_max, } } } - if (num_items_max == 0) - { - array[i] = NULL; - if (num_items != NULL) - *num_items = i; - } - else - { - if (num_items != NULL) - *num_items = num_items_max; - } - + + array[i] = NULL; + if (num_items != NULL) + *num_items = i; + return array; } diff --git a/weechat/ChangeLog b/weechat/ChangeLog index d07b225d7..c51df9dca 100644 --- a/weechat/ChangeLog +++ b/weechat/ChangeLog @@ -1,10 +1,11 @@ WeeChat - Wee Enhanced Environment for Chat =========================================== -ChangeLog - 2007-03-16 +ChangeLog - 2007-03-20 Version 0.2.4 (under dev!): + * fixed bug with explode_string / free_exploded_string when max_items > 0 * added new key (ctrl-R) for interactive and incremental search in buffer history (task #6628) * fixed /topic completion when no topic set on current channel (bug #19322) diff --git a/weechat/src/common/util.c b/weechat/src/common/util.c index 657f40380..badc22b61 100644 --- a/weechat/src/common/util.c +++ b/weechat/src/common/util.c @@ -455,33 +455,30 @@ explode_string (char *string, char *separators, int num_items_max, if (num_items != NULL) *num_items = 0; - - n_items = num_items_max; - + if (!string || !string[0]) return NULL; - - if (num_items_max == 0) + + /* calculate number of items */ + ptr = string; + i = 1; + while ((ptr = strpbrk (ptr, separators))) { - /* calculate number of items */ - ptr = string; - i = 1; - while ((ptr = strpbrk (ptr, separators))) - { - while (strchr (separators, ptr[0]) != NULL) - ptr++; - i++; - } - n_items = i; + while (strchr (separators, ptr[0]) != NULL) + ptr++; + i++; } + n_items = i; + if ((num_items_max != 0) && (n_items > num_items_max)) + n_items = num_items_max; + array = - (char **) malloc ((num_items_max ? n_items : n_items + 1) * - sizeof (char *)); - + (char **) malloc ((n_items + 1) * sizeof (char *)); + ptr1 = string; ptr2 = string; - + for (i = 0; i < n_items; i++) { while (strchr (separators, ptr1[0]) != NULL) @@ -490,7 +487,7 @@ explode_string (char *string, char *separators, int num_items_max, if ((ptr2 = strchr (ptr1, '\r')) == NULL) if ((ptr2 = strchr (ptr1, '\n')) == NULL) ptr2 = strchr (ptr1, '\0'); - + if ((ptr1 == NULL) || (ptr2 == NULL)) { array[i] = NULL; @@ -511,18 +508,11 @@ explode_string (char *string, char *separators, int num_items_max, } } } - if (num_items_max == 0) - { - array[i] = NULL; - if (num_items != NULL) - *num_items = i; - } - else - { - if (num_items != NULL) - *num_items = num_items_max; - } - + + array[i] = NULL; + if (num_items != NULL) + *num_items = i; + return array; }