From 0ee745995b1f45ed321b0c20b151ec8e76e4344f Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Fri, 12 Jan 2024 13:47:52 +0100 Subject: pkgcachegen: Use placement new to construct header Avoid copying the header from a stack allocated object as this will copy uninitialized padding bytes into the cache, triggering valgrind errors which people then use as a strawman for unrelated errors on armhf. In an optimal world we should annotate the allocator however such that valgrind actually does treat those bytes as uninitialized and then supress warnings in the harmless places, such that when you then go and try to access it in a place that matters, you do get an error for uninitialized memory. Currently any access within the pool will be considered initialized which is clearly suboptimal. But this is very much a TBD topic and involves annotating the allocator everywhere. --- apt-pkg/pkgcachegen.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index 9e47ef369..3a85a9585 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -89,7 +89,7 @@ bool pkgCacheGenerator::Start() Map.UsePools(*Cache.HeaderP->Pools,sizeof(Cache.HeaderP->Pools)/sizeof(Cache.HeaderP->Pools[0])); // Starting header - *Cache.HeaderP = pkgCache::Header(); + new (Cache.HeaderP) pkgCache::Header(); // make room for the hashtables for packages and groups if (Map.RawAllocate(2 * (Cache.HeaderP->GetHashTableSize() * sizeof(map_pointer))) == 0) -- cgit v1.2.3-70-g09d2