Browse Source

modules: simplify vlc_module_match() error handling

Set the modules table to NULL on error, to simplify call sites.
pull/113/head
Rémi Denis-Courmont 6 years ago
parent
commit
9652333d21
  1. 2
      include/vlc_modules.h
  2. 5
      src/modules/modules.c

2
include/vlc_modules.h

@ -46,7 +46,7 @@ struct vlc_logger;
* \param names string of comma-separated requested module shortcut names
* \param strict whether to exclude modules with no unmatching shortcut names
* \param modules storage location for the base address of a sorted table
* of candidate modules [OUT]
* of candidate modules (NULL on error) [OUT]
* \param strict_matches storage location for the count of strictly matched
* modules [OUT]
* \return number of modules found or a strictly negative value on error

5
src/modules/modules.c

@ -112,17 +112,18 @@ ssize_t vlc_module_match(const char *capability, const char *names,
module_t **sorted = malloc(total * sizeof (*sorted));
size_t matches = 0;
*modules = sorted;
if (total > 0) {
if (unlikely(unsorted == NULL || sorted == NULL)) {
free(unsorted);
free(sorted);
*modules = NULL;
return -1;
}
memcpy(unsorted, tab, total * sizeof (*unsorted));
}
*modules = sorted;
/* Go through the list of module shortcut names. */
while (names[0] != '\0') {
const char *shortcut = names;

Loading…
Cancel
Save