File tree 1 file changed +14
-4
lines changed
1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -435,8 +435,13 @@ void TwoWire::allocateRxBuffer(size_t length)
435
435
if (rxBufferAllocated < length) {
436
436
// By default we allocate BUFFER_LENGTH bytes. It is the min size of the buffer.
437
437
if (length < BUFFER_LENGTH) { length = BUFFER_LENGTH; }
438
- rxBuffer = (uint8_t *)realloc (rxBuffer, length * sizeof (uint8_t ));
439
- rxBufferAllocated = (rxBuffer != nullptr ) ? length: 0 ;
438
+ uint8_t *tmp = (uint8_t *)realloc (rxBuffer, length * sizeof (uint8_t ));
439
+ if (tmp != nullptr ) {
440
+ rxBuffer = tmp;
441
+ rxBufferAllocated = length;
442
+ } else {
443
+ _Error_Handler (" No enough memory! (%i)\n " , length);
444
+ }
440
445
}
441
446
}
442
447
@@ -445,8 +450,13 @@ inline void TwoWire::allocateTxBuffer(size_t length)
445
450
if (txBufferAllocated < length) {
446
451
// By default we allocate BUFFER_LENGTH bytes. It is the min size of the buffer.
447
452
if (length < BUFFER_LENGTH) { length = BUFFER_LENGTH; }
448
- txBuffer = (uint8_t *)realloc (txBuffer, length * sizeof (uint8_t ));
449
- txBufferAllocated = (txBuffer != nullptr ) ? length: 0 ;
453
+ uint8_t *tmp = (uint8_t *)realloc (txBuffer, length * sizeof (uint8_t ));
454
+ if (tmp != nullptr ) {
455
+ txBuffer = tmp;
456
+ txBufferAllocated = length;
457
+ } else {
458
+ _Error_Handler (" No enough memory! (%i)\n " , length);
459
+ }
450
460
}
451
461
}
452
462
You can’t perform that action at this time.
0 commit comments