[vlc-commits] modules: simplify vlc_module_match() error handling
Rémi Denis-Courmont
git at videolan.org
Sat Sep 26 21:23:30 CEST 2020
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Fri Sep 25 22:09:53 2020 +0300| [9652333d214acdd943c120c95990265f24c6e1cd] | committer: Rémi Denis-Courmont
modules: simplify vlc_module_match() error handling
Set the modules table to NULL on error, to simplify call sites.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=9652333d214acdd943c120c95990265f24c6e1cd
---
include/vlc_modules.h | 2 +-
src/modules/modules.c | 5 +++--
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/include/vlc_modules.h b/include/vlc_modules.h
index ade8135265..ec3c602934 100644
--- a/include/vlc_modules.h
+++ b/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
diff --git a/src/modules/modules.c b/src/modules/modules.c
index 9c21fa2b74..531f96ad96 100644
--- a/src/modules/modules.c
+++ b/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;
More information about the vlc-commits
mailing list