Skip to content

Commit 887288e

Browse files
leonardocavagnisfacchinm
authored andcommitted
check malloc return in Arduino_H7_Video Lib
1 parent 837a82f commit 887288e

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

libraries/Arduino_H7_Video/src/Arduino_H7_Video.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ int Arduino_H7_Video::begin() {
118118
static lv_disp_draw_buf_t draw_buf;
119119
static lv_color_t * buf1;
120120
buf1 = (lv_color_t*)malloc((width() * height() / 10) * sizeof(lv_color_t)); /* Declare a buffer for 1/10 screen size */
121+
if (buf1 == NULL) {
122+
return H7V_ERR_INSUFFMEM;
123+
}
121124
lv_disp_draw_buf_init(&draw_buf, buf1, NULL, width() * height() / 10); /* Initialize the display buffer. */
122125

123126
/* Initialize display features for LVGL library */
@@ -138,7 +141,7 @@ int Arduino_H7_Video::begin() {
138141
lv_disp_drv_register(&disp_drv); /* Finally register the driver */
139142
#endif
140143

141-
return 1;
144+
return H7V_OK;
142145
}
143146

144147
void Arduino_H7_Video::end() {

libraries/Arduino_H7_Video/src/Arduino_H7_Video.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
#define H7_VIDEO_MAX_WIDTH 1280
1919
#define H7_VIDEO_MAX_HEIGHT 1024
2020

21+
#define H7V_OK 1
22+
#define H7V_ERR_INSUFFMEM 2
23+
2124
/* Exported enumeration ------------------------------------------------------*/
2225
enum DisplayShieldModel {
2326
NONE_SHIELD = 0,

0 commit comments

Comments
 (0)