mirror of
https://github.com/sanni/cartreader.git
synced 2024-12-18 00:51:49 +01:00
Merge pull request #85 from Kreeblah/master
Additional error checks when reading snes_clk.txt clock offset file
This commit is contained in:
commit
2e3757bc71
@ -6,20 +6,38 @@ int32_t readClockOffset() {
|
|||||||
unsigned char* clock_buf;
|
unsigned char* clock_buf;
|
||||||
int16_t i;
|
int16_t i;
|
||||||
int32_t clock_offset;
|
int32_t clock_offset;
|
||||||
|
|
||||||
if(!clock_file.open("/snes_clk.txt", FILE_READ)) {
|
if(!clock_file.open("/snes_clk.txt", FILE_READ)) {
|
||||||
return INT32_MIN;
|
return INT32_MIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
clock_buf = malloc(16 * sizeof(char));
|
clock_buf = malloc(12 * sizeof(char));
|
||||||
i = clock_file.read(clock_buf, 16);
|
i = clock_file.read(clock_buf, 11);
|
||||||
clock_file.close();
|
clock_file.close();
|
||||||
if(i == -1) {
|
if(i == -1) {
|
||||||
free(clock_buf);
|
free(clock_buf);
|
||||||
return INT32_MIN;
|
return INT32_MIN;
|
||||||
} else if(i < 16) {
|
} else if((i == 11) && (clock_buf[0] != '-')) {
|
||||||
|
free(clock_buf);
|
||||||
|
return INT32_MIN;
|
||||||
|
} else {
|
||||||
clock_buf[i] = 0;
|
clock_buf[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(i = 0; i < 12; i++) {
|
||||||
|
if(clock_buf[i] != '-' && clock_buf[i] < '0' && clock_buf[i] > '9') {
|
||||||
|
if(i == 0) {
|
||||||
|
free(clock_buf);
|
||||||
|
return INT32_MIN;
|
||||||
|
} else if((i == 1) && (clock_buf[0] == '-')) {
|
||||||
|
free(clock_buf);
|
||||||
|
return INT32_MIN;
|
||||||
|
} else {
|
||||||
|
clock_buf[i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
clock_offset = (int32_t)atoi(clock_buf);
|
clock_offset = (int32_t)atoi(clock_buf);
|
||||||
free(clock_buf);
|
free(clock_buf);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user