summaryrefslogtreecommitdiff
path: root/apt-pkg/cacheiterators.h
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2020-06-08 17:07:43 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2021-02-04 11:00:00 +0100
commitf7e6eaf84bebac565f462e2ce48f30808cc771eb (patch)
treed02dc088bc7cc5e0127be271cbe9fed505e42b6c /apt-pkg/cacheiterators.h
parentc4da2ff42da55ffc38c77a9170dc151216d75962 (diff)
Avoid undefined pointer arithmetic while growing mmap
The undefined behaviour sanitizer complains with: runtime error: addition of unsigned offset to 0x… overflowed to 0x… Compilers and runtime do the right thing in any case and it is a codepath that can (and ideally should) be avoided for speed reasons alone, but fixing it can't hurt (too much).
Diffstat (limited to 'apt-pkg/cacheiterators.h')
-rw-r--r--apt-pkg/cacheiterators.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/apt-pkg/cacheiterators.h b/apt-pkg/cacheiterators.h
index 6261b5089..466492442 100644
--- a/apt-pkg/cacheiterators.h
+++ b/apt-pkg/cacheiterators.h
@@ -82,10 +82,10 @@ template<typename Str, typename Itr> class APT_PUBLIC pkgCache::Iterator :
inline unsigned long Index() const {return S - OwnerPointer();}
inline map_pointer<Str> MapPointer() const {return map_pointer<Str>(Index()) ;}
- void ReMap(void const * const oldMap, void const * const newMap) {
+ void ReMap(void const * const oldMap, void * const newMap) {
if (Owner == 0 || S == 0)
return;
- S += static_cast<Str const *>(newMap) - static_cast<Str const *>(oldMap);
+ S = static_cast<Str *>(newMap) + (S - static_cast<Str const *>(oldMap));
}
// Constructors - look out for the variable assigning
@@ -350,12 +350,12 @@ class APT_PUBLIC pkgCache::DepIterator : public Iterator<Dependency, DepIterator
};
inline DependencyProxy operator->() const {return (DependencyProxy) { S2->Version, S2->Package, S->ID, S2->Type, S2->CompareOp, S->ParentVer, S->DependencyData, S->NextRevDepends, S->NextDepends, S2->NextData };}
inline DependencyProxy operator->() {return (DependencyProxy) { S2->Version, S2->Package, S->ID, S2->Type, S2->CompareOp, S->ParentVer, S->DependencyData, S->NextRevDepends, S->NextDepends, S2->NextData };}
- void ReMap(void const * const oldMap, void const * const newMap)
+ void ReMap(void const * const oldMap, void * const newMap)
{
Iterator<Dependency, DepIterator>::ReMap(oldMap, newMap);
if (Owner == 0 || S == 0 || S2 == 0)
return;
- S2 += static_cast<DependencyData const *>(newMap) - static_cast<DependencyData const *>(oldMap);
+ S2 = static_cast<DependencyData *>(newMap) + (S2 - static_cast<DependencyData const *>(oldMap));
}
//Nice printable representation