Skip to content

Commit 7a66e25

Browse files
committed
Resync
1 parent 9d63869 commit 7a66e25

6 files changed

Lines changed: 82 additions & 36 deletions

File tree

cdrom/cdrom.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,25 +1395,26 @@ struct string_list* cdrom_get_available_drives(void)
13951395
if (filestream_read_file("/proc/modules", (void**)&buf, &len))
13961396
{
13971397
#ifdef CDROM_DEBUG
1398-
bool found = false;
1398+
bool found = false;
13991399
#endif
1400-
struct string_list *mods = string_split(buf, "\n");
1400+
struct string_list mods = {0};
14011401

1402-
if (mods)
1402+
string_list_initialize(&mods);
1403+
1404+
if (string_split_noalloc(&mods, buf, "\n"))
14031405
{
1404-
for (i = 0; i < mods->size; i++)
1406+
for (i = 0; i < mods.size; i++)
14051407
{
1406-
if (strcasestr(mods->elems[i].data, "sg "))
1408+
if (strcasestr(mods.elems[i].data, "sg "))
14071409
{
14081410
#ifdef CDROM_DEBUG
14091411
found = true;
14101412
#endif
14111413
break;
14121414
}
14131415
}
1414-
1415-
string_list_free(mods);
14161416
}
1417+
string_list_deinitialize(&mods);
14171418

14181419
#ifdef CDROM_DEBUG
14191420
if (found)

file/archive_file.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,37 +58,34 @@ static int file_archive_get_file_list_cb(
5858
size_t path_len = strlen(path);
5959
/* Checks if this entry is a directory or a file. */
6060
char last_char = path[path_len - 1];
61-
struct string_list *ext_list = NULL;
61+
struct string_list ext_list = {0};
6262

6363
/* Skip if directory. */
6464
if (last_char == '/' || last_char == '\\' )
65-
{
66-
string_list_free(ext_list);
6765
return 0;
68-
}
6966

70-
ext_list = string_split(valid_exts, "|");
71-
72-
if (ext_list)
67+
string_list_initialize(&ext_list);
68+
if (string_split_noalloc(&ext_list, valid_exts, "|"))
7369
{
7470
const char *file_ext = path_get_extension(path);
7571

7672
if (!file_ext)
7773
{
78-
string_list_free(ext_list);
74+
string_list_deinitialize(&ext_list);
7975
return 0;
8076
}
8177

82-
if (!string_list_find_elem_prefix(ext_list, ".", file_ext))
78+
if (!string_list_find_elem_prefix(&ext_list, ".", file_ext))
8379
{
8480
/* keep iterating */
85-
string_list_free(ext_list);
81+
string_list_deinitialize(&ext_list);
8682
return -1;
8783
}
8884

8985
attr.i = RARCH_COMPRESSED_FILE_IN_ARCHIVE;
90-
string_list_free(ext_list);
9186
}
87+
88+
string_list_deinitialize(&ext_list);
9289
}
9390

9491
return string_list_append(userdata->list, path, attr);

file/config_file_userdata.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,14 @@ int config_userdata_get_float_array(void *userdata, const char *key_str,
7676
config_get_string(usr->conf, key[1], &str))
7777
{
7878
unsigned i;
79-
struct string_list *list = string_split(str, " ");
80-
*values = (float*)calloc(list->size, sizeof(float));
81-
for (i = 0; i < list->size; i++)
82-
(*values)[i] = (float)strtod(list->elems[i].data, NULL);
83-
*out_num_values = (unsigned)list->size;
84-
string_list_free(list);
79+
struct string_list list = {0};
80+
string_list_initialize(&list);
81+
string_split_noalloc(&list, str, " ");
82+
*values = (float*)calloc(list.size, sizeof(float));
83+
for (i = 0; i < list.size; i++)
84+
(*values)[i] = (float)strtod(list.elems[i].data, NULL);
85+
*out_num_values = (unsigned)list.size;
86+
string_list_deinitialize(&list);
8587
free(str);
8688
return true;
8789
}
@@ -106,12 +108,14 @@ int config_userdata_get_int_array(void *userdata, const char *key_str,
106108
config_get_string(usr->conf, key[1], &str))
107109
{
108110
unsigned i;
109-
struct string_list *list = string_split(str, " ");
110-
*values = (int*)calloc(list->size, sizeof(int));
111-
for (i = 0; i < list->size; i++)
112-
(*values)[i] = (int)strtod(list->elems[i].data, NULL);
113-
*out_num_values = (unsigned)list->size;
114-
string_list_free(list);
111+
struct string_list list = {0};
112+
string_list_initialize(&list);
113+
string_split_noalloc(&list, str, " ");
114+
*values = (int*)calloc(list.size, sizeof(int));
115+
for (i = 0; i < list.size; i++)
116+
(*values)[i] = (int)strtod(list.elems[i].data, NULL);
117+
*out_num_values = (unsigned)list.size;
118+
string_list_deinitialize(&list);
115119
free(str);
116120
return true;
117121
}

include/lists/string_list.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ bool string_list_find_elem_prefix(const struct string_list *list,
8888
*/
8989
struct string_list *string_split(const char *str, const char *delim);
9090

91+
bool string_split_noalloc(struct string_list *list,
92+
const char *str, const char *delim);
93+
9194
/**
9295
* string_separate:
9396
* @str : string to turn into a string list

lists/dir_list.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,19 @@ bool dir_list_append(struct string_list *list,
214214
bool include_hidden, bool include_compressed,
215215
bool recursive)
216216
{
217-
struct string_list *ext_list = ext ? string_split(ext, "|") : NULL;
218-
bool ret = dir_list_read(dir, list, ext_list,
219-
include_dirs, include_hidden, include_compressed, recursive) != -1;
220-
221-
string_list_free(ext_list);
217+
bool ret = false;
218+
struct string_list ext_list = {0};
219+
struct string_list *ext_list_ptr = NULL;
222220

221+
if (ext)
222+
{
223+
string_list_initialize(&ext_list);
224+
string_split_noalloc(&ext_list, ext, "|");
225+
ext_list_ptr = &ext_list;
226+
}
227+
ret = dir_list_read(dir, list, ext_list_ptr,
228+
include_dirs, include_hidden, include_compressed, recursive) != -1;
229+
string_list_deinitialize(&ext_list);
223230
return ret;
224231
}
225232

lists/string_list.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ struct string_list *string_split(const char *str, const char *delim)
286286
struct string_list *list = string_list_new();
287287

288288
if (!list)
289-
goto error;
289+
return NULL;
290290

291291
copy = strdup(str);
292292
if (!copy)
@@ -314,6 +314,40 @@ struct string_list *string_split(const char *str, const char *delim)
314314
return NULL;
315315
}
316316

317+
bool string_split_noalloc(struct string_list *list,
318+
const char *str, const char *delim)
319+
{
320+
char *save = NULL;
321+
char *copy = NULL;
322+
const char *tmp = NULL;
323+
324+
if (!list)
325+
return false;
326+
327+
copy = strdup(str);
328+
if (!copy)
329+
return false;
330+
331+
tmp = strtok_r(copy, delim, &save);
332+
while (tmp)
333+
{
334+
union string_list_elem_attr attr;
335+
336+
attr.i = 0;
337+
338+
if (!string_list_append(list, tmp, attr))
339+
{
340+
free(copy);
341+
return false;
342+
}
343+
344+
tmp = strtok_r(NULL, delim, &save);
345+
}
346+
347+
free(copy);
348+
return true;
349+
}
350+
317351
/**
318352
* string_separate:
319353
* @str : string to turn into a string list

0 commit comments

Comments
 (0)