From ed836aa73a87b9d60e81c607d5b4f57e9b82f948 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 10 Jun 2025 17:23:41 +0200 Subject: Avoid cast alignment warning in cache string view The cache allocates strings as uint16_t size; char content[]; char zero; Aligned to the uint16_t. When doing the casting, this causes a warning on some architectures that cannot do unaligned loads, such as armhf. Use __builtin_assume_aligned() to explictly say that the pointer is aligned to 16 bits. This is a bit of a backhanded approach, as the warning seems to be actually avoided by the function returning a void* rather than the assumed alignment, but this is very much self-documenting. --- apt-pkg/pkgcache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-pkg') diff --git a/apt-pkg/pkgcache.h b/apt-pkg/pkgcache.h index b832106ed..7a9db3d20 100644 --- a/apt-pkg/pkgcache.h +++ b/apt-pkg/pkgcache.h @@ -258,7 +258,7 @@ class APT_PUBLIC pkgCache /*{{{*/ std::string_view ViewString(map_stringitem_t idx) const { char *name = StrP + idx; - size_t len = *reinterpret_cast(name - sizeof(uint16_t)); + size_t len = *reinterpret_cast(__builtin_assume_aligned(name - sizeof(uint16_t), sizeof(uint16_t))); return {name, len}; } -- cgit v1.2.3-70-g09d2