Skip to content

Commit 4467667

Browse files
authored
Merge pull request #714 from bbawj/master
Add error handling for esp_jpg_decode
2 parents 6a821a8 + aa15c51 commit 4467667

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

conversions/esp_jpg_decode.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,17 @@ esp_err_t esp_jpg_decode(size_t len, jpg_scale_t scale, jpg_reader_cb reader, jp
114114
uint16_t output_height = decoder.height / (1 << (uint8_t)(jpeg.scale));
115115

116116
//output start
117-
writer(arg, 0, 0, output_width, output_height, NULL);
117+
if (!writer(arg, 0, 0, output_width, output_height, NULL)) {
118+
ESP_LOGE(TAG, "JPG Writer Start Failed!");
119+
return ESP_FAIL;
120+
}
118121
//output write
119122
jres = jd_decomp(&decoder, _jpg_write, (uint8_t)jpeg.scale);
120123
//output end
121-
writer(arg, output_width, output_height, output_width, output_height, NULL);
124+
if (!writer(arg, output_width, output_height, output_width, output_height, NULL)) {
125+
ESP_LOGE(TAG, "JPG Writer End Failed!");
126+
return ESP_FAIL;
127+
}
122128

123129
if (jres != JDR_OK) {
124130
ESP_LOGE(TAG, "JPG Decompression Failed! %s", jd_errors[jres]);

conversions/to_bmp.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,10 @@ static bool _rgb_write(void * arg, uint16_t x, uint16_t y, uint16_t w, uint16_t
7878
jpeg->height = h;
7979
//if output is null, this is BMP
8080
if(!jpeg->output){
81-
jpeg->output = (uint8_t *)_malloc((w*h*3)+jpeg->data_offset);
81+
size_t out_size = (w*h*3)+jpeg->data_offset;
82+
jpeg->output = (uint8_t *)_malloc(out_size);
8283
if(!jpeg->output){
84+
ESP_LOGE(TAG, "_malloc failed! %zu", out_size);
8385
return false;
8486
}
8587
}
@@ -121,8 +123,10 @@ static bool _rgb565_write(void * arg, uint16_t x, uint16_t y, uint16_t w, uint16
121123
jpeg->height = h;
122124
//if output is null, this is BMP
123125
if(!jpeg->output){
124-
jpeg->output = (uint8_t *)_malloc((w*h*3)+jpeg->data_offset);
126+
size_t out_size = (w*h*3)+jpeg->data_offset;
127+
jpeg->output = (uint8_t *)_malloc(out_size);
125128
if(!jpeg->output){
129+
ESP_LOGE(TAG, "_malloc failed! %zu", out_size);
126130
return false;
127131
}
128132
}

0 commit comments

Comments
 (0)