commit:     b7edba4e6c51901f40aefca78be5095e9dd434a4
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Tue Feb  7 02:58:50 2017 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Tue Feb  7 02:58:50 2017 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=b7edba4e

avoid assert() with active code

Since assert can be compiled out via -DNDEBUG, make sure
we don't put function calls in there we need to work.

Reported-by: Ian Coolidge <icoolidge <AT> google.com>

 qmerge.c | 6 ++++--
 qxpak.c  | 4 +++-
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/qmerge.c b/qmerge.c
index e84fcbb..07da4cc 100644
--- a/qmerge.c
+++ b/qmerge.c
@@ -902,11 +902,13 @@ pkg_merge(int level, const depend_atom *atom, const 
struct pkg_t *pkg)
 
        /* split the tbz and xpak data */
        xasprintf(&tbz2, "%s/%s/%s.tbz2", pkgdir, pkg->CATEGORY, pkg->PF);
-       assert(run_applet_l("qtbz2", "-s", tbz2, NULL) == 0);
+       if (run_applet_l("qtbz2", "-s", tbz2, NULL) != 0)
+               err("`qtbz2 -s %s` failed", tbz2);
 
        mkdir("vdb", 0755);
        sprintf(tbz2, "%s.xpak", pkg->PF);
-       assert(run_applet_l("qxpak", "-d", "vdb", "-x", tbz2, NULL) == 0);
+       if (run_applet_l("qxpak", "-d", "vdb", "-x", tbz2, NULL) != 0)
+               err("`qxpak -d vdb -x %s` failed", tbz2);
 
        free(tbz2);
 

diff --git a/qxpak.c b/qxpak.c
index 58b29ef..95fb779 100644
--- a/qxpak.c
+++ b/qxpak.c
@@ -154,6 +154,7 @@ xpak_list(int dir_fd, const char *file, int argc, char 
**argv)
 {
        _xpak_archive *x;
        char buf[BUFSIZE];
+       size_t ret;
 
        x = _xpak_open(file);
        if (!x)
@@ -162,7 +163,8 @@ xpak_list(int dir_fd, const char *file, int argc, char 
**argv)
        x->dir_fd = dir_fd;
        x->index = buf;
        assert((size_t)x->index_len < sizeof(buf));
-       assert(fread(x->index, 1, x->index_len, x->fp) == (size_t)x->index_len);
+       ret = fread(x->index, 1, x->index_len, x->fp);
+       assert(ret == (size_t)x->index_len);
        _xpak_walk_index(x, argc, argv, &_xpak_list_callback);
 
        _xpak_close(x);

Reply via email to