From 7117fe1ff50de266436d0f84d50a5e0f52ae8078 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Fri, 30 Apr 2021 12:04:19 +0200 Subject: [PATCH] Malloc alignment to 32bits for H7 --- radio/src/thirdparty/libopenui/src/bitmapbuffer.h | 5 +++-- radio/src/thirdparty/libopenui/src/libopenui_helpers.h | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/radio/src/thirdparty/libopenui/src/bitmapbuffer.h b/radio/src/thirdparty/libopenui/src/bitmapbuffer.h index 7aeda8e0e..77e8dfd87 100755 --- a/radio/src/thirdparty/libopenui/src/bitmapbuffer.h +++ b/radio/src/thirdparty/libopenui/src/bitmapbuffer.h @@ -25,6 +25,7 @@ #include "libopenui_types.h" #include "libopenui_defines.h" #include "libopenui_depends.h" +#include "libopenui_helpers.h" #include "debug.h" constexpr uint8_t SOLID = 0xFF; @@ -188,7 +189,7 @@ class RLEBitmap: _width = *((uint16_t *)rle_data); _height = *(((uint16_t *)rle_data)+1); uint32_t pixels = _width * _height; - data = (uint16_t*)malloc(pixels * sizeof(uint16_t)); + data = (uint16_t*)malloc(align32(pixels * sizeof(uint16_t))); decode((uint8_t *)data, pixels * sizeof(uint16_t), rle_data+4); data_end = data + pixels; } @@ -248,7 +249,7 @@ class BitmapBuffer: public BitmapBufferBase , leakReported(false) #endif { - data = (uint16_t *)malloc(width * height * sizeof(uint16_t)); + data = (uint16_t *)malloc(align32(width * height * sizeof(uint16_t))); data_end = data + (width * height); } diff --git a/radio/src/thirdparty/libopenui/src/libopenui_helpers.h b/radio/src/thirdparty/libopenui/src/libopenui_helpers.h index b91388966..a5914a95a 100644 --- a/radio/src/thirdparty/libopenui/src/libopenui_helpers.h +++ b/radio/src/thirdparty/libopenui/src/libopenui_helpers.h @@ -66,6 +66,12 @@ inline int mod(int k, int n) return ((k %= n) < 0) ? k + n : k; } +inline unsigned align32(unsigned n) +{ + unsigned rest = (n & 3u); + return rest ? n + 4u - rest : n; +} + template inline T sgn(T a) {