diff options
| author | Julian Andres Klode <jak@debian.org> | 2025-06-10 17:23:41 +0200 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2025-06-10 17:29:33 +0200 |
| commit | ed836aa73a87b9d60e81c607d5b4f57e9b82f948 (patch) | |
| tree | 0efad303b1247f06d1184d644c248ae93fb039e1 /apt-pkg/pkgcache.h | |
| parent | 9e6772f6bb13c2606a86e4046a9c4ebfe768881a (diff) | |
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.
Diffstat (limited to 'apt-pkg/pkgcache.h')
| -rw-r--r-- | apt-pkg/pkgcache.h | 2 |
1 files changed, 1 insertions, 1 deletions
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<const uint16_t*>(name - sizeof(uint16_t)); + size_t len = *reinterpret_cast<const uint16_t *>(__builtin_assume_aligned(name - sizeof(uint16_t), sizeof(uint16_t))); return {name, len}; } |
