File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed
Expand file tree Collapse file tree 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)
435435 if (rxBufferAllocated < length) {
436436 // By default we allocate BUFFER_LENGTH bytes. It is the min size of the buffer.
437437 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+ }
440445 }
441446}
442447
@@ -445,8 +450,13 @@ inline void TwoWire::allocateTxBuffer(size_t length)
445450 if (txBufferAllocated < length) {
446451 // By default we allocate BUFFER_LENGTH bytes. It is the min size of the buffer.
447452 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+ }
450460 }
451461}
452462
You can’t perform that action at this time.
0 commit comments