1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-30 06:46:38 +02:00

Fixed bug with explode_string / free_exploded_string when max_items > 0

This commit is contained in:
Sebastien Helleu
2007-03-19 23:31:49 +00:00
parent a584ef4261
commit 25bfda26e9
4 changed files with 48 additions and 66 deletions
+2 -1
View File
@@ -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)
+22 -32
View File
@@ -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;
}
+2 -1
View File
@@ -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)
+22 -32
View File
@@ -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;
}