Skip to content

Commit

Permalink
Merge pull request #192 from dot4qu/fix-malloc-fail-heap-protection
Browse files Browse the repository at this point in the history
Don't try to malloc for a character glyph with size zero
  • Loading branch information
martinberlin committed Jul 9, 2022
2 parents 7ce79de + d590ca6 commit b4c582b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/epd_driver/font.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ static enum EpdDrawError IRAM_ATTR draw_char(const EpdFont *font, uint8_t *buffe
int byte_width = (width / 2 + width % 2);
unsigned long bitmap_size = byte_width * height;
const uint8_t *bitmap = NULL;
if (font->compressed) {
if (bitmap_size > 0 && font->compressed) {
uint8_t* tmp_bitmap = (uint8_t *)malloc(bitmap_size);
if (tmp_bitmap == NULL && bitmap_size) {
ESP_LOGE("font", "malloc failed.");
Expand Down Expand Up @@ -175,7 +175,7 @@ static enum EpdDrawError IRAM_ATTR draw_char(const EpdFont *font, uint8_t *buffe
x++;
}
}
if (font->compressed) {
if (bitmap_size > 0 && font->compressed) {
free((uint8_t*)bitmap);
}
*cursor_x += glyph->advance_x;
Expand Down

0 comments on commit b4c582b

Please sign in to comment.