Skip to content

Commit c5ad72b

Browse files
Ganesh RamachandranGanesh Ramachandran
authored andcommitted
Error check for reallocation memory fail
1 parent 84e4dec commit c5ad72b

File tree

1 file changed

+8
-0
lines changed
  • targets/TARGET_TOSHIBA/TARGET_TMPM46B

1 file changed

+8
-0
lines changed

targets/TARGET_TOSHIBA/TARGET_TMPM46B/i2c_api.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop)
219219

220220
i2c_num = obj->index;
221221
gI2C_TxData = (char *)calloc(length, sizeof(int8_t));
222+
if (gI2C_TxData == NULL) {
223+
error("Insufficient memory");
224+
return 0;
225+
}
222226

223227
for (i = 0; i < length; i++) {
224228
gI2C_TxData[i] = data[i];
@@ -258,6 +262,10 @@ int i2c_byte_write(i2c_t *obj, int data)
258262
byte_func = 1;
259263
if (start_flag == 0 && send_byte == 0) {
260264
gI2C_LTxData = (char *)realloc(gI2C_LTxData, counter++);
265+
if (gI2C_LTxData == NULL) {
266+
error("Insufficient memory");
267+
return 0;
268+
}
261269
gI2C_LTxData[counter - 2] = data;
262270
}
263271

0 commit comments

Comments
 (0)