mirror of
https://github.com/mdbtools/mdbtools.git
synced 2025-07-17 02:36:44 +08:00
Fix bug in fake g_strsplit
Lack of NULL termination caused an occasional crash
This commit is contained in:
parent
cc292b3f0d
commit
4ca16b8edf
@ -25,14 +25,14 @@ int g_str_equal(const void *str1, const void *str2) {
|
|||||||
char **g_strsplit(const char *haystack, const char *needle, int something) {
|
char **g_strsplit(const char *haystack, const char *needle, int something) {
|
||||||
char **ret = NULL;
|
char **ret = NULL;
|
||||||
char *found = NULL;
|
char *found = NULL;
|
||||||
size_t components = 1;
|
size_t components = 2; // last component + terminating NULL
|
||||||
|
|
||||||
while ((found = strstr(haystack, needle))) {
|
while ((found = strstr(haystack, needle))) {
|
||||||
components++;
|
components++;
|
||||||
haystack = found + strlen(needle);
|
haystack = found + strlen(needle);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = malloc(components * sizeof(char *));
|
ret = calloc(components, sizeof(char *));
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while ((found = strstr(haystack, needle))) {
|
while ((found = strstr(haystack, needle))) {
|
||||||
|
Loading…
Reference in New Issue
Block a user