mirror of
https://github.com/opentx/opentx.git
synced 2025-07-21 15:25:17 +03:00
[Horus] Malloc check added
This commit is contained in:
parent
05129b6785
commit
fb6c9cde6b
2 changed files with 53 additions and 30 deletions
|
@ -133,6 +133,11 @@ int cliRead(const char ** argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t * buffer = (uint8_t*) malloc(bufferSize);
|
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);
|
FRESULT result = f_open(&file, argv[1], FA_OPEN_EXISTING | FA_READ);
|
||||||
if (result != FR_OK) {
|
if (result != FR_OK) {
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
@ -177,11 +182,15 @@ int cliReadSD(const char ** argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toInt(argv, 3, &bufferSectors) == 0 || bufferSectors < 0 ) {
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t * buffer = (uint8_t*) malloc(512*bufferSectors);
|
uint8_t * buffer = (uint8_t*) malloc(512*bufferSectors);
|
||||||
|
if (!buffer) {
|
||||||
|
serialPrint("Not enough memory");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t bytesRead = numberOfSectors * 512;
|
uint32_t bytesRead = numberOfSectors * 512;
|
||||||
tmr10ms_t start = get_tmr10ms();
|
tmr10ms_t start = get_tmr10ms();
|
||||||
|
@ -236,6 +245,10 @@ int cliTestSD(const char ** argv)
|
||||||
// read last 16 sectors one sector at the time
|
// read last 16 sectors one sector at the time
|
||||||
serialPrint("Starting single sector read test, reading 16 sectors one by one");
|
serialPrint("Starting single sector read test, reading 16 sectors one by one");
|
||||||
uint8_t * buffer = (uint8_t*) malloc(512);
|
uint8_t * buffer = (uint8_t*) malloc(512);
|
||||||
|
if (!buffer) {
|
||||||
|
serialPrint("Not enough memory");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
for (uint32_t s = sectorCount - 16; s<sectorCount; ++s) {
|
for (uint32_t s = sectorCount - 16; s<sectorCount; ++s) {
|
||||||
DRESULT res = __disk_read(0, buffer, s, 1);
|
DRESULT res = __disk_read(0, buffer, s, 1);
|
||||||
if (res != RES_OK) {
|
if (res != RES_OK) {
|
||||||
|
@ -250,6 +263,11 @@ int cliTestSD(const char ** argv)
|
||||||
|
|
||||||
// read last 16 sectors, two sectors at the time with a multi-block read
|
// read last 16 sectors, two sectors at the time with a multi-block read
|
||||||
buffer = (uint8_t *) malloc(512*2);
|
buffer = (uint8_t *) malloc(512*2);
|
||||||
|
if (!buffer) {
|
||||||
|
serialPrint("Not enough memory");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
serialPrint("Starting multiple sector read test, reading two sectors at the time");
|
serialPrint("Starting multiple sector read test, reading two sectors at the time");
|
||||||
for (uint32_t s = sectorCount - 16; s<sectorCount; s+=2) {
|
for (uint32_t s = sectorCount - 16; s<sectorCount; s+=2) {
|
||||||
DRESULT res = __disk_read(0, buffer, s, 2);
|
DRESULT res = __disk_read(0, buffer, s, 2);
|
||||||
|
@ -265,6 +283,11 @@ int cliTestSD(const char ** argv)
|
||||||
|
|
||||||
// read last 16 sectors, all sectors with single multi-block read
|
// read last 16 sectors, all sectors with single multi-block read
|
||||||
buffer = (uint8_t*) malloc(512*16);
|
buffer = (uint8_t*) malloc(512*16);
|
||||||
|
if (!buffer) {
|
||||||
|
serialPrint("Not enough memory");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
serialPrint("Starting multiple sector read test, reading 16 sectors at the time");
|
serialPrint("Starting multiple sector read test, reading 16 sectors at the time");
|
||||||
DRESULT res = __disk_read(0, buffer, sectorCount-16, 16);
|
DRESULT res = __disk_read(0, buffer, sectorCount-16, 16);
|
||||||
if (res != RES_OK) {
|
if (res != RES_OK) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue