From fb6c9cde6b72f40ec81ee00c45bfd30b6c854109 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Sun, 22 Jan 2017 21:32:19 +0100 Subject: [PATCH] [Horus] Malloc check added --- radio/src/cli.cpp | 35 ++++++++++++++++++++++++++------ radio/src/syscalls.c | 48 ++++++++++++++++++++++---------------------- 2 files changed, 53 insertions(+), 30 deletions(-) diff --git a/radio/src/cli.cpp b/radio/src/cli.cpp index c7198d166..2896dc884 100644 --- a/radio/src/cli.cpp +++ b/radio/src/cli.cpp @@ -133,6 +133,11 @@ int cliRead(const char ** argv) } uint8_t * buffer = (uint8_t*) malloc(bufferSize); + if (!buffer) { + serialPrint("Not enough memory"); + return 0; + } + FRESULT result = f_open(&file, argv[1], FA_OPEN_EXISTING | FA_READ); if (result != FR_OK) { free(buffer); @@ -177,11 +182,15 @@ int cliReadSD(const char ** argv) } if (toInt(argv, 3, &bufferSectors) == 0 || bufferSectors < 0 ) { - serialPrint("%s: Invalid number of buffrer sectors \"%s\"", argv[0], argv[3]); + serialPrint("%s: Invalid number of buffer sectors \"%s\"", argv[0], argv[3]); return 0; } uint8_t * buffer = (uint8_t*) malloc(512*bufferSectors); + if (!buffer) { + serialPrint("Not enough memory"); + return 0; + } uint32_t bytesRead = numberOfSectors * 512; tmr10ms_t start = get_tmr10ms(); @@ -228,15 +237,19 @@ int cliTestSD(const char ** argv) // get sector count uint32_t sectorCount; if (disk_ioctl(0, GET_SECTOR_COUNT, §orCount) != RES_OK) { - serialPrint("Error: can't read sector count"); - return 0; + serialPrint("Error: can't read sector count"); + return 0; } serialPrint("SD card has %u sectors", sectorCount); // read last 16 sectors one sector at the time serialPrint("Starting single sector read test, reading 16 sectors one by one"); uint8_t * buffer = (uint8_t*) malloc(512); - for(uint32_t s = sectorCount - 16; s