1
0
Fork 0
forked from len0rd/rockbox

Fix some non-portable alignment values

UBSan reports an avalanche of unaligned pointer bugs stemming from
hardcoded 4-byte alignments used in certain places. Use sizeof(long)
instead to align to the machine word size.

Change-Id: I28e505212462c5268afa24e95df3a103ac3e2213
This commit is contained in:
Aidan MacDonald 2022-05-02 15:23:37 +01:00
parent 366f00a3d3
commit 6b8c94a6e3
5 changed files with 19 additions and 37 deletions

View file

@ -80,8 +80,8 @@ void* skin_buffer_alloc(size_t size)
{
void *retval = NULL;
#endif
/* 32-bit aligned */
size = (size + 3) & ~3;
/* align to long which is enough for most types */
size = (size + sizeof(long) - 1) & ~(sizeof(long) - 1);
if (size > skin_buffer_freespace())
{
skin_error(MEMORY_LIMIT_EXCEEDED, NULL);