mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-04 06:37:38 +03:00
fix: add NULL checks after malloc in drawBmp() (#80)
## Problem `drawBmp()` allocates two row buffers via `malloc()` but doesn't check if allocations succeed. On low memory, this causes a crash when the NULL pointers are dereferenced. ## Fix Add NULL check after both `malloc()` calls. If either fails, log error and return early. Changed `lib/GfxRenderer/GfxRenderer.cpp`. ## Test - Defensive addition only - no logic changes - Manual device testing appreciated
This commit is contained in:
parent
73d1839ddd
commit
9a3bb81337
@ -136,6 +136,13 @@ void GfxRenderer::drawBitmap(const Bitmap& bitmap, const int x, const int y, con
|
||||
auto* outputRow = static_cast<uint8_t*>(malloc(outputRowSize));
|
||||
auto* rowBytes = static_cast<uint8_t*>(malloc(bitmap.getRowBytes()));
|
||||
|
||||
if (!outputRow || !rowBytes) {
|
||||
Serial.printf("[%lu] [GFX] !! Failed to allocate BMP row buffers\n", millis());
|
||||
free(outputRow);
|
||||
free(rowBytes);
|
||||
return;
|
||||
}
|
||||
|
||||
for (int bmpY = 0; bmpY < bitmap.getHeight(); bmpY++) {
|
||||
// The BMP's (0, 0) is the bottom-left corner (if the height is positive, top-left if negative).
|
||||
// Screen's (0, 0) is the top-left corner.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user