From c04a64352fd3f8333caabf0983f0572564961cc6 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Fri, 15 Mar 2013 16:50:30 -0500 Subject: [PATCH] cache: handle pkg being NULL on pkg_cache_add()/pkg_cache_remove() --- cache.c | 6 ++++++ tests/run.sh.in | 2 ++ 2 files changed, 8 insertions(+) diff --git a/cache.c b/cache.c index 40c6f54..43bb5c6 100644 --- a/cache.c +++ b/cache.c @@ -49,6 +49,9 @@ pkg_cache_lookup(const char *id) void pkg_cache_add(pkg_t *pkg) { + if (pkg == NULL) + return; + pkg_ref(pkg); pkg_node_insert(&pkg->cache_iter, pkg, &pkg_cache); @@ -62,6 +65,9 @@ pkg_cache_add(pkg_t *pkg) void pkg_cache_remove(pkg_t *pkg) { + if (pkg == NULL) + return; + pkg_node_delete(&pkg->cache_iter, &pkg_cache); } diff --git a/tests/run.sh.in b/tests/run.sh.in index 6ba296f..f6a53a9 100644 --- a/tests/run.sh.in +++ b/tests/run.sh.in @@ -64,6 +64,8 @@ run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --cflags --libs 'foo' '>' '1.2' '-lfoo' '-I/usr/include/foo' '-fPIC' run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --exists nonexistant; echo \$?" \ '1' +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} nonexistant; echo \$?" \ + '1' run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --exists 'foo > 1.2'; echo \$?" \ '0' run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --exists 'foo > 1.2.3'; echo \$?" \