From 460515bf41511987795645cef16c96fd69078d33 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sat, 8 Feb 2020 20:00:56 +0100 Subject: [PATCH] lib/util.c: add assertions everywhere. --- lib/util.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lib/util.c b/lib/util.c index 0f5d6607..71afd43b 100644 --- a/lib/util.c +++ b/lib/util.c @@ -130,6 +130,8 @@ xbps_pkg_version(const char *pkg) const char *p, *r; size_t p_len; + assert(pkg); + if ((p = strrchr(pkg, '-')) == NULL) return NULL; @@ -155,6 +157,8 @@ xbps_binpkg_pkgver(const char *pkg) char *p, *p1, *res; unsigned int len; + assert(pkg); + /* skip path if found, only interested in filename */ if ((fname = strrchr(pkg, '/'))) fname++; @@ -195,6 +199,8 @@ xbps_binpkg_arch(const char *pkg) char *p, *p1, *res; unsigned int len; + assert(pkg); + /* skip path if found, only interested in filename */ if ((fname = strrchr(pkg, '/'))) fname++; @@ -227,6 +233,8 @@ xbps_pkg_revision(const char *pkg) const char *p, *r; size_t p_len; + assert(pkg); + if ((p = strrchr(pkg, '-')) == NULL) return NULL; @@ -428,6 +436,9 @@ xbps_pkg_arch_match(struct xbps_handle *xhp, const char *orig, { const char *arch; + assert(xhp); + assert(orig); + if (xhp->target_arch) arch = xhp->target_arch; else @@ -504,12 +515,18 @@ xbps_humanize_number(char *buf, int64_t bytes) size_t xbps_strlcat(char *dest, const char *src, size_t siz) { + assert(dest); + assert(src); + return strlcat(dest, src, siz); } size_t xbps_strlcpy(char *dest, const char *src, size_t siz) { + assert(dest); + assert(src); + return strlcpy(dest, src, siz); } @@ -524,6 +541,9 @@ xbps_pkg_reverts(xbps_dictionary_t pkg, const char *pkgver) const char *version = xbps_pkg_version(pkgver); const char *revertver = NULL; + assert(pkg); + assert(pkgver); + if ((reverts = xbps_dictionary_get(pkg, "reverts")) == NULL) return false; @@ -572,6 +592,10 @@ xbps_symlink_target(struct xbps_handle *xhp, const char *path, const char *tgt) char *rootdir = NULL; ssize_t r; + assert(xhp); + assert(path); + assert(tgt); + if (lstat(path, &sb) == -1) return NULL; @@ -655,6 +679,8 @@ xbps_patterns_match(xbps_array_t patterns, const char *path) { bool match = false; + assert(path); + if (patterns == NULL) return false;