Sprinkle a couple of assert(3)ions.
This commit is contained in:
parent
fd30feadcb
commit
008573e1eb
@ -104,6 +104,9 @@ xbps_fetch_file(const char *uri,
|
|||||||
int fd = -1, rv = 0;
|
int fd = -1, rv = 0;
|
||||||
bool restart = false;
|
bool restart = false;
|
||||||
|
|
||||||
|
assert(uri != NULL);
|
||||||
|
assert(outputdir != NULL);
|
||||||
|
|
||||||
fetchLastErrCode = 0;
|
fetchLastErrCode = 0;
|
||||||
fetchTimeout = 30; /* 30 seconds of timeout */
|
fetchTimeout = 30; /* 30 seconds of timeout */
|
||||||
|
|
||||||
|
@ -156,6 +156,8 @@ humanize_number(char *buf, size_t len, int64_t bytes,
|
|||||||
int
|
int
|
||||||
xbps_humanize_number(char *buf, int64_t bytes)
|
xbps_humanize_number(char *buf, int64_t bytes)
|
||||||
{
|
{
|
||||||
|
assert(buf != NULL);
|
||||||
|
|
||||||
return humanize_number(buf, 6, bytes, "B",
|
return humanize_number(buf, 6, bytes, "B",
|
||||||
HN_AUTOSCALE, HN_DECIMAL|HN_NOSPACE);
|
HN_AUTOSCALE, HN_DECIMAL|HN_NOSPACE);
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,9 @@ xbps_entry_install_conf_file(prop_dictionary_t filesd,
|
|||||||
|
|
||||||
assert(filesd != NULL);
|
assert(filesd != NULL);
|
||||||
assert(entry != NULL);
|
assert(entry != NULL);
|
||||||
|
assert(entry_pname != NULL);
|
||||||
assert(pkgname != NULL);
|
assert(pkgname != NULL);
|
||||||
|
assert(version != NULL);
|
||||||
|
|
||||||
iter = xbps_get_array_iter_from_dict(filesd, "conf_files");
|
iter = xbps_get_array_iter_from_dict(filesd, "conf_files");
|
||||||
if (iter == NULL)
|
if (iter == NULL)
|
||||||
|
@ -49,6 +49,9 @@ xbps_remove_obsoletes(prop_dictionary_t oldd, prop_dictionary_t newd)
|
|||||||
int rv = 0;
|
int rv = 0;
|
||||||
bool found, dodirs = false, dolinks = false;
|
bool found, dodirs = false, dolinks = false;
|
||||||
|
|
||||||
|
assert(oldd != NULL);
|
||||||
|
assert(newd != NULL);
|
||||||
|
|
||||||
again:
|
again:
|
||||||
iter = xbps_get_array_iter_from_dict(oldd, array_str);
|
iter = xbps_get_array_iter_from_dict(oldd, array_str);
|
||||||
if (iter == NULL)
|
if (iter == NULL)
|
||||||
|
@ -129,6 +129,8 @@ xbps_requiredby_pkg_remove(const char *pkgname)
|
|||||||
char *plist;
|
char *plist;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
|
assert(pkgname != NULL);
|
||||||
|
|
||||||
plist = xbps_xasprintf("%s/%s/%s", xbps_get_rootdir(),
|
plist = xbps_xasprintf("%s/%s/%s", xbps_get_rootdir(),
|
||||||
XBPS_META_PATH, XBPS_REGPKGDB);
|
XBPS_META_PATH, XBPS_REGPKGDB);
|
||||||
if (plist == NULL)
|
if (plist == NULL)
|
||||||
@ -169,6 +171,9 @@ xbps_requiredby_pkg_add(prop_array_t regar, prop_dictionary_t pkg)
|
|||||||
char *rdepname;
|
char *rdepname;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
|
assert(regar != NULL);
|
||||||
|
assert(pkg != NULL);
|
||||||
|
|
||||||
prop_dictionary_get_cstring_nocopy(pkg, "pkgver", &pkgver);
|
prop_dictionary_get_cstring_nocopy(pkg, "pkgver", &pkgver);
|
||||||
rdeps = prop_dictionary_get(pkg, "run_depends");
|
rdeps = prop_dictionary_get(pkg, "run_depends");
|
||||||
if (rdeps == NULL || prop_array_count(rdeps) == 0)
|
if (rdeps == NULL || prop_array_count(rdeps) == 0)
|
||||||
|
@ -59,6 +59,7 @@ set_new_state(prop_dictionary_t dict, pkg_state_t state)
|
|||||||
const struct state *stp;
|
const struct state *stp;
|
||||||
const char *pkgname;
|
const char *pkgname;
|
||||||
|
|
||||||
|
assert(dict != NULL);
|
||||||
|
|
||||||
for (stp = states; stp->string != NULL; stp++)
|
for (stp = states; stp->string != NULL; stp++)
|
||||||
if (state == stp->number)
|
if (state == stp->number)
|
||||||
@ -102,6 +103,7 @@ xbps_get_pkg_state_installed(const char *pkgname, pkg_state_t *state)
|
|||||||
prop_dictionary_t pkgd;
|
prop_dictionary_t pkgd;
|
||||||
|
|
||||||
assert(pkgname != NULL);
|
assert(pkgname != NULL);
|
||||||
|
assert(state != NULL);
|
||||||
|
|
||||||
pkgd = xbps_find_pkg_dict_installed(pkgname, false);
|
pkgd = xbps_find_pkg_dict_installed(pkgname, false);
|
||||||
if (pkgd == NULL)
|
if (pkgd == NULL)
|
||||||
@ -119,6 +121,7 @@ int
|
|||||||
xbps_get_pkg_state_dictionary(prop_dictionary_t dict, pkg_state_t *state)
|
xbps_get_pkg_state_dictionary(prop_dictionary_t dict, pkg_state_t *state)
|
||||||
{
|
{
|
||||||
assert(dict != NULL);
|
assert(dict != NULL);
|
||||||
|
assert(state != NULL);
|
||||||
|
|
||||||
if ((*state = get_state(dict)) == 0)
|
if ((*state = get_state(dict)) == 0)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
@ -143,6 +146,8 @@ xbps_set_pkg_state_installed(const char *pkgname, pkg_state_t state)
|
|||||||
int rv = 0;
|
int rv = 0;
|
||||||
bool newpkg = false;
|
bool newpkg = false;
|
||||||
|
|
||||||
|
assert(pkgname != NULL);
|
||||||
|
|
||||||
plist = xbps_xasprintf("%s/%s/%s", xbps_get_rootdir(),
|
plist = xbps_xasprintf("%s/%s/%s", xbps_get_rootdir(),
|
||||||
XBPS_META_PATH, XBPS_REGPKGDB);
|
XBPS_META_PATH, XBPS_REGPKGDB);
|
||||||
if (plist == NULL)
|
if (plist == NULL)
|
||||||
|
@ -200,6 +200,8 @@ xbps_find_pkg_dict_installed(const char *str, bool bypattern)
|
|||||||
prop_dictionary_t d, pkgd, rpkgd = NULL;
|
prop_dictionary_t d, pkgd, rpkgd = NULL;
|
||||||
pkg_state_t state = 0;
|
pkg_state_t state = 0;
|
||||||
|
|
||||||
|
assert(str != NULL);
|
||||||
|
|
||||||
if ((d = xbps_regpkgdb_dictionary_get()) == NULL)
|
if ((d = xbps_regpkgdb_dictionary_get()) == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -489,6 +491,8 @@ _xbps_uncompress_plist_data(char *xml, size_t len)
|
|||||||
ssize_t totalsize = 0;
|
ssize_t totalsize = 0;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
|
assert(xml != NULL);
|
||||||
|
|
||||||
/* Decompress the mmap'ed buffer with zlib */
|
/* Decompress the mmap'ed buffer with zlib */
|
||||||
strm.zalloc = Z_NULL;
|
strm.zalloc = Z_NULL;
|
||||||
strm.zfree = Z_NULL;
|
strm.zfree = Z_NULL;
|
||||||
|
@ -59,6 +59,8 @@ set_pkg_state(prop_dictionary_t pkgd, const char *pkgname)
|
|||||||
pkg_state_t state = 0;
|
pkg_state_t state = 0;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
|
assert(pkgd != NULL);
|
||||||
|
|
||||||
rv = xbps_set_pkg_state_dictionary(pkgd, XBPS_PKG_STATE_NOT_INSTALLED);
|
rv = xbps_set_pkg_state_dictionary(pkgd, XBPS_PKG_STATE_NOT_INSTALLED);
|
||||||
if (rv != 0)
|
if (rv != 0)
|
||||||
return rv;
|
return rv;
|
||||||
|
@ -152,6 +152,9 @@ xbps_repository_get_pkg_plist_dict_from_url(const char *url, const char *plistf)
|
|||||||
const char *curpath, *comptype;
|
const char *curpath, *comptype;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
|
assert(url != NULL);
|
||||||
|
assert(plistf != NULL);
|
||||||
|
|
||||||
if ((a = open_archive(url)) == NULL)
|
if ((a = open_archive(url)) == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -198,6 +201,9 @@ xbps_repository_get_pkg_plist_dict(const char *pkgname, const char *plistf)
|
|||||||
char *url;
|
char *url;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
|
assert(pkgname != NULL);
|
||||||
|
assert(plistf != NULL);
|
||||||
|
|
||||||
if ((rv = xbps_repository_pool_init()) != 0) {
|
if ((rv = xbps_repository_pool_init()) != 0) {
|
||||||
errno = rv;
|
errno = rv;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -217,6 +217,8 @@ xbps_repository_pool_foreach(
|
|||||||
int rv = 0;
|
int rv = 0;
|
||||||
bool done = false;
|
bool done = false;
|
||||||
|
|
||||||
|
assert(fn != NULL);
|
||||||
|
|
||||||
if (!repolist_initialized)
|
if (!repolist_initialized)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
|
@ -95,6 +95,7 @@ xbps_repository_sync_pkg_index(const char *uri,
|
|||||||
int rv = 0;
|
int rv = 0;
|
||||||
bool only_sync = false;
|
bool only_sync = false;
|
||||||
|
|
||||||
|
assert(uri != NULL);
|
||||||
tmp_metafile = rpidx = lrepodir = lrepofile = NULL;
|
tmp_metafile = rpidx = lrepodir = lrepofile = NULL;
|
||||||
|
|
||||||
if (uname(&un) == -1)
|
if (uname(&un) == -1)
|
||||||
|
11
lib/util.c
11
lib/util.c
@ -78,6 +78,8 @@ xbps_get_file_hash(const char *file)
|
|||||||
int fd;
|
int fd;
|
||||||
bool need_guard = false;
|
bool need_guard = false;
|
||||||
|
|
||||||
|
assert(file != NULL);
|
||||||
|
|
||||||
if ((fd = open(file, O_RDONLY)) == -1) {
|
if ((fd = open(file, O_RDONLY)) == -1) {
|
||||||
free(buf);
|
free(buf);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -126,6 +128,9 @@ xbps_check_file_hash(const char *file, const char *sha256)
|
|||||||
{
|
{
|
||||||
char *res;
|
char *res;
|
||||||
|
|
||||||
|
assert(file != NULL);
|
||||||
|
assert(sha256 != NULL);
|
||||||
|
|
||||||
res = xbps_get_file_hash(file);
|
res = xbps_get_file_hash(file);
|
||||||
if (res == NULL)
|
if (res == NULL)
|
||||||
return errno;
|
return errno;
|
||||||
@ -342,6 +347,8 @@ get_pkg_index_remote_plist(const char *uri)
|
|||||||
{
|
{
|
||||||
char *uri_fixed, *repodir;
|
char *uri_fixed, *repodir;
|
||||||
|
|
||||||
|
assert(uri != NULL);
|
||||||
|
|
||||||
uri_fixed = xbps_get_remote_repo_string(uri);
|
uri_fixed = xbps_get_remote_repo_string(uri);
|
||||||
if (uri_fixed == NULL)
|
if (uri_fixed == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -379,6 +386,9 @@ xbps_get_binpkg_repo_uri(prop_dictionary_t pkg_repod, const char *repoloc)
|
|||||||
const char *filen, *arch, *cdir;
|
const char *filen, *arch, *cdir;
|
||||||
char *lbinpkg = NULL;
|
char *lbinpkg = NULL;
|
||||||
|
|
||||||
|
assert(pkg_repod != NULL);
|
||||||
|
assert(repoloc != NULL);
|
||||||
|
|
||||||
if (!prop_dictionary_get_cstring_nocopy(pkg_repod,
|
if (!prop_dictionary_get_cstring_nocopy(pkg_repod,
|
||||||
"filename", &filen))
|
"filename", &filen))
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -413,6 +423,7 @@ xbps_pkg_has_rundeps(prop_dictionary_t pkg)
|
|||||||
prop_array_t array;
|
prop_array_t array;
|
||||||
|
|
||||||
assert(pkg != NULL);
|
assert(pkg != NULL);
|
||||||
|
|
||||||
array = prop_dictionary_get(pkg, "run_depends");
|
array = prop_dictionary_get(pkg, "run_depends");
|
||||||
if (array && prop_array_count(array) > 0)
|
if (array && prop_array_count(array) > 0)
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user