diff options
author | Albert Astals Cid <aacid@kde.org> | 2023-10-22 16:47:57 +0200 |
---|---|---|
committer | Albert Astals Cid <aacid@kde.org> | 2023-10-22 16:47:57 +0200 |
commit | 4d45d3304a94bc70d5f8a74dcc30b24dc7e54a45 (patch) | |
tree | 1f24b02adb003233edcae58b037b7405401131f1 | |
parent | c45800a26a1c7c511cb088b2078c7beff3701f63 (diff) |
Use RefRecursionChecker instead std::set
Much simpler code
-rw-r--r-- | poppler/Catalog.cc | 26 | ||||
-rw-r--r-- | poppler/Catalog.h | 4 |
2 files changed, 11 insertions, 19 deletions
diff --git a/poppler/Catalog.cc b/poppler/Catalog.cc index 372d7047..2e3dbd5b 100644 --- a/poppler/Catalog.cc +++ b/poppler/Catalog.cc @@ -14,7 +14,7 @@ // under GPL version 2 or later // // Copyright (C) 2005 Kristian Høgsberg <krh@redhat.com> -// Copyright (C) 2005-2013, 2015, 2017-2022 Albert Astals Cid <aacid@kde.org> +// Copyright (C) 2005-2013, 2015, 2017-2023 Albert Astals Cid <aacid@kde.org> // Copyright (C) 2005 Jeff Muizelaar <jrmuizel@nit.ca> // Copyright (C) 2005 Jonathan Blandford <jrb@redhat.com> // Copyright (C) 2005 Marco Pesenti Gritti <mpg@redhat.com> @@ -698,14 +698,14 @@ int NameTree::Entry::cmpEntry(const void *voidEntry, const void *voidOtherEntry) void NameTree::init(XRef *xrefA, Object *tree) { xref = xrefA; - std::set<int> seen; + RefRecursionChecker seen; parse(tree, seen); if (entries && length > 0) { qsort(entries, length, sizeof(Entry *), Entry::cmpEntry); } } -void NameTree::parse(const Object *tree, std::set<int> &seen) +void NameTree::parse(const Object *tree, RefRecursionChecker &seen) { if (!tree->isDict()) { return; @@ -725,24 +725,16 @@ void NameTree::parse(const Object *tree, std::set<int> &seen) // root or intermediate node Ref ref; const Object kids = tree->getDict()->lookup("Kids", &ref); - if (ref != Ref::INVALID()) { - const int numObj = ref.num; - if (seen.find(numObj) != seen.end()) { - error(errSyntaxError, -1, "loop in NameTree (numObj: {0:d})", numObj); - return; - } - seen.insert(numObj); + if (!seen.insert(ref)) { + error(errSyntaxError, -1, "loop in NameTree (numObj: {0:d})", ref.num); + return; } if (kids.isArray()) { for (int i = 0; i < kids.arrayGetLength(); ++i) { const Object kid = kids.getArray()->get(i, &ref); - if (ref != Ref::INVALID()) { - const int numObj = ref.num; - if (seen.find(numObj) != seen.end()) { - error(errSyntaxError, -1, "loop in NameTree (numObj: {0:d})", numObj); - continue; - } - seen.insert(numObj); + if (!seen.insert(ref)) { + error(errSyntaxError, -1, "loop in NameTree (numObj: {0:d})", ref.num); + continue; } if (kid.isDict()) { parse(&kid, seen); diff --git a/poppler/Catalog.h b/poppler/Catalog.h index 03df89ac..8848e44a 100644 --- a/poppler/Catalog.h +++ b/poppler/Catalog.h @@ -14,7 +14,7 @@ // under GPL version 2 or later // // Copyright (C) 2005 Kristian Høgsberg <krh@redhat.com> -// Copyright (C) 2005, 2007, 2009-2011, 2013, 2017-2022 Albert Astals Cid <aacid@kde.org> +// Copyright (C) 2005, 2007, 2009-2011, 2013, 2017-2023 Albert Astals Cid <aacid@kde.org> // Copyright (C) 2005 Jonathan Blandford <jrb@redhat.com> // Copyright (C) 2005, 2006, 2008 Brad Hards <bradh@frogmouth.net> // Copyright (C) 2007 Julien Rebetez <julienr@svn.gnome.org> @@ -94,7 +94,7 @@ private: static int cmp(const void *key, const void *entry); }; - void parse(const Object *tree, std::set<int> &seen); + void parse(const Object *tree, RefRecursionChecker &seen); void addEntry(Entry *entry); XRef *xref; |