mirror of
https://github.com/opencv/opencv.git
synced 2026-11-25 19:07:03 -06:00
AutoBuffer<uchar> (and <char>, <int8_t>, ...) is routinely used as raw storage for float/double/int64 data. The heap path (new _Tp[]) is at least 8-byte aligned everywhere, but the local array `buf` only had the alignment of _Tp: on 64-bit targets it happened to land on an 8-byte offset after the pointer and two size_t members, on 32-bit targets it was 4-byte aligned, and the object itself could sit at any 4-byte address. alignas(max(alignof(_Tp), 8)) on `buf` makes the guarantee explicit on every platform (C++11; OpenCV 5 requires C++17). Reordering the members or adding a size_t padding field would not help on 32-bit targets, where the object's own alignment stays 4. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>