[PATCH setup 00/14] Use libsolv, solve all our problems... (WIP)
Ken Brown
kbrown@cornell.edu
Wed Oct 18 15:57:00 GMT 2017
On 10/18/2017 11:28 AM, Ken Brown wrote:
> Similar considerations apply to the other public member functions of
> SolvableVersion. So my inclination is to go with something like my
> patch...
...with perhaps one tweak. Maybe we should test 'id' rather than
'pool', since id being 0 is what's used elsewhere to characterize the
empty package. And if id != 0 but pool == 0, there's a bug that we want
to catch.
Revised patch attached.
Ken
-------------- next part --------------
From 948db09180765d89639b63e37a98d3806bf199d5 Mon Sep 17 00:00:00 2001
From: Ken Brown <kbrown@cornell.edu>
Date: Tue, 17 Oct 2017 08:12:48 -0400
Subject: [PATCH] Extend the SolvableVersion member functions to the empty
package
Currently some of these functions cause crashes when the package is
empty because the libsolv function pool_id2solvable unconditionally
dereferences its first argument ('pool').
---
libsolv.cc | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/libsolv.cc b/libsolv.cc
index 78e73a8..289f19c 100644
--- a/libsolv.cc
+++ b/libsolv.cc
@@ -75,6 +75,8 @@ RelId2Operator(Id id)
const std::string
SolvableVersion::Name () const
{
+ if (!id)
+ return "";
Solvable *solvable = pool_id2solvable(pool, id);
return std::string(pool_id2str(pool, solvable->name));
}
@@ -82,6 +84,8 @@ SolvableVersion::Name () const
const std::string
SolvableVersion::Canonical_version() const
{
+ if (!id)
+ return "";
Solvable *solvable = pool_id2solvable(pool, id);
return std::string(pool_id2str(pool, solvable->evr));
}
@@ -89,6 +93,8 @@ SolvableVersion::Canonical_version() const
package_type_t
SolvableVersion::Type () const
{
+ if (!id)
+ return package_binary;
Solvable *solvable = pool_id2solvable(pool, id);
if (solvable->arch == ARCH_SRC)
return package_source;
@@ -112,6 +118,9 @@ SolvableVersion::obsoletes() const
const PackageDepends
SolvableVersion::deplist(Id keyname) const
{
+ static PackageDepends empty_package;
+ if (!id)
+ return empty_package;
Solvable *solvable = pool_id2solvable(pool, id);
Queue q;
@@ -147,13 +156,14 @@ SolvableVersion::deplist(Id keyname) const
}
// otherwise, return an empty depends list
- static PackageDepends empty_package;
return empty_package;
}
const std::string
SolvableVersion::SDesc () const
{
+ if (!id)
+ return "";
Solvable *solvable = pool_id2solvable(pool, id);
const char *sdesc = repo_lookup_str(solvable->repo, id, SOLVABLE_SUMMARY);
return sdesc;
@@ -197,6 +207,8 @@ SolvableVersion::sourcePackage () const
void
SolvableVersion::fixup_spkg_id (SolvableVersion spkg_id) const
{
+ if (!id)
+ return;
Solvable *solvable = pool_id2solvable(pool, id);
Repodata *data = repo_last_repodata(solvable->repo);
Id handle = id;
@@ -237,6 +249,8 @@ SolvableVersion::accessible () const
package_stability_t
SolvableVersion::Stability () const
{
+ if (!id)
+ return TRUST_UNKNOWN;
Solvable *solvable = pool_id2solvable(pool, id);
Id stability_attr = pool_str2id(pool, "solvable:stability", 1);
return (package_stability_t)repo_lookup_num(solvable->repo, id, stability_attr, TRUST_UNKNOWN);
--
2.14.2
More information about the Cygwin-apps
mailing list