@@ -335,9 +335,11 @@ ImageReturnCode loadEyelid(char *filename,
335335 // This is the "booster seat" described in m4eyes.ino
336336 if (reader->bmpDimensions (filename, &w, &h) == IMAGE_SUCCESS) {
337337 tempBytes = ((w + 7 ) / 8 ) * h; // Bitmap size in bytes
338- if (tempPtr = (uint8_t *)malloc (maxRam - tempBytes)) {
339- // Make SOME tempPtr reference, or optimizer removes the alloc!
340- tempPtr[0 ] = 0 ;
338+ if (maxRam > tempBytes) {
339+ if (tempPtr = (uint8_t *)malloc (maxRam - tempBytes)) {
340+ // Make SOME tempPtr reference, or optimizer removes the alloc!
341+ tempPtr[0 ] = 0 ;
342+ }
341343 }
342344 // DON'T nest the image-reading case in here. If the fragmentation
343345 // culprit can be found, this block of code (and the free() block
@@ -416,9 +418,11 @@ ImageReturnCode loadTexture(char *filename, uint16_t **data,
416418 // This is the "booster seat" described in m4eyes.ino
417419 if (reader->bmpDimensions (filename, &w, &h) == IMAGE_SUCCESS) {
418420 tempBytes = w * h * 2 ; // Image size in bytes (converted to 16bpp)
419- if (tempPtr = (uint8_t *)malloc (maxRam - tempBytes)) {
420- // Make SOME tempPtr reference, or optimizer removes the alloc!
421- tempPtr[0 ] = 0 ;
421+ if (maxRam > tempBytes) {
422+ if (tempPtr = (uint8_t *)malloc (maxRam - tempBytes)) {
423+ // Make SOME tempPtr reference, or optimizer removes the alloc!
424+ tempPtr[0 ] = 0 ;
425+ }
422426 }
423427 // DON'T nest the image-reading case in here. If the fragmentation
424428 // culprit can be found, this block of code (and the free() block
0 commit comments