mirror of
https://github.com/opentx/opentx.git
synced 2025-07-19 22:35:12 +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,7 +245,11 @@ 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);
|
||||||
for(uint32_t s = sectorCount - 16; s<sectorCount; ++s) {
|
if (!buffer) {
|
||||||
|
serialPrint("Not enough memory");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
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) {
|
||||||
serialPrint("sector %d read FAILED, err: %d", s, res);
|
serialPrint("sector %d read FAILED, err: %d", s, res);
|
||||||
|
@ -249,9 +262,14 @@ int cliTestSD(const char ** argv)
|
||||||
serialCrlf();
|
serialCrlf();
|
||||||
|
|
||||||
// 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);
|
||||||
if (res != RES_OK) {
|
if (res != RES_OK) {
|
||||||
serialPrint("sector %d-%d read FAILED, err: %d", s, s+1, res);
|
serialPrint("sector %d-%d read FAILED, err: %d", s, s+1, res);
|
||||||
|
@ -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) {
|
||||||
|
|
|
@ -54,17 +54,17 @@ extern void _exit( int status ) ;
|
||||||
extern void _kill( int pid, int sig ) ;
|
extern void _kill( int pid, int sig ) ;
|
||||||
extern int _getpid ( void ) ;
|
extern int _getpid ( void ) ;
|
||||||
|
|
||||||
unsigned char *heap = (unsigned char *)&_end;
|
unsigned char * heap = (unsigned char *)&_end;
|
||||||
extern caddr_t _sbrk(int nbytes)
|
extern caddr_t _sbrk(int nbytes)
|
||||||
{
|
{
|
||||||
if (heap + nbytes < (unsigned char *)&_heap_end) {
|
if (heap + nbytes < (unsigned char *)&_heap_end) {
|
||||||
unsigned char *prev_heap = heap;
|
unsigned char * prev_heap = heap;
|
||||||
heap += nbytes;
|
heap += nbytes;
|
||||||
return (caddr_t) prev_heap;
|
return (caddr_t)prev_heap;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
errno = ENOMEM;
|
errno = ENOMEM;
|
||||||
return ((void*)-1);
|
return ((void *)-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue