mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Check return of fread() in core/ostctools.c
Since the corresponding error message appears thrice, it is translated once at the beginning of the function (even in the non-error case). A single-byte fread() was transformed into getc(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
1c1ca8c1c7
commit
3c346bb341
1 changed files with 22 additions and 6 deletions
|
@ -43,13 +43,14 @@ void ostctools_import(const char *file, struct dive_table *divetable)
|
||||||
char *tmp;
|
char *tmp;
|
||||||
struct dive *ostcdive = alloc_dive();
|
struct dive *ostcdive = alloc_dive();
|
||||||
dc_status_t rc = 0;
|
dc_status_t rc = 0;
|
||||||
int model, ret, i = 0;
|
int model, ret, i = 0, c;
|
||||||
unsigned int serial;
|
unsigned int serial;
|
||||||
struct extra_data *ptr;
|
struct extra_data *ptr;
|
||||||
|
const char *failed_to_read_msg = translate("gettextFromC", "Failed to read '%s'");
|
||||||
|
|
||||||
// Open the archive
|
// Open the archive
|
||||||
if ((archive = subsurface_fopen(file, "rb")) == NULL) {
|
if ((archive = subsurface_fopen(file, "rb")) == NULL) {
|
||||||
report_error(translate("gettextFromC", "Failed to read '%s'"), file);
|
report_error(failed_to_read_msg, file);
|
||||||
free(ostcdive);
|
free(ostcdive);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -57,25 +58,40 @@ void ostctools_import(const char *file, struct dive_table *divetable)
|
||||||
// Read dive number from the log
|
// Read dive number from the log
|
||||||
uc_tmp = calloc(2, 1);
|
uc_tmp = calloc(2, 1);
|
||||||
fseek(archive, 258, 0);
|
fseek(archive, 258, 0);
|
||||||
fread(uc_tmp, 1, 2, archive);
|
if (fread(uc_tmp, 1, 2, archive) != 2) {
|
||||||
|
report_error(failed_to_read_msg, file);
|
||||||
|
free(uc_tmp);
|
||||||
|
free(ostcdive);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
ostcdive->number = uc_tmp[0] + (uc_tmp[1] << 8);
|
ostcdive->number = uc_tmp[0] + (uc_tmp[1] << 8);
|
||||||
free(uc_tmp);
|
free(uc_tmp);
|
||||||
|
|
||||||
// Read device's serial number
|
// Read device's serial number
|
||||||
uc_tmp = calloc(2, 1);
|
uc_tmp = calloc(2, 1);
|
||||||
fseek(archive, 265, 0);
|
fseek(archive, 265, 0);
|
||||||
fread(uc_tmp, 1, 2, archive);
|
if (fread(uc_tmp, 1, 2, archive) != 2) {
|
||||||
|
report_error(failed_to_read_msg, file);
|
||||||
|
free(uc_tmp);
|
||||||
|
free(ostcdive);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
serial = uc_tmp[0] + (uc_tmp[1] << 8);
|
serial = uc_tmp[0] + (uc_tmp[1] << 8);
|
||||||
free(uc_tmp);
|
free(uc_tmp);
|
||||||
|
|
||||||
// Read dive's raw data, header + profile
|
// Read dive's raw data, header + profile
|
||||||
fseek(archive, 456, 0);
|
fseek(archive, 456, 0);
|
||||||
while (!feof(archive)) {
|
while ((c = getc(archive)) != EOF) {
|
||||||
fread(buffer + i, 1, 1, archive);
|
buffer[i] = c;
|
||||||
if (buffer[i] == 0xFD && buffer[i - 1] == 0xFD)
|
if (buffer[i] == 0xFD && buffer[i - 1] == 0xFD)
|
||||||
break;
|
break;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
if (ferror(archive)) {
|
||||||
|
report_error(failed_to_read_msg, file);
|
||||||
|
free(ostcdive);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
// Try to determine the dc family based on the header type
|
// Try to determine the dc family based on the header type
|
||||||
if (buffer[2] == 0x20 || buffer[2] == 0x21) {
|
if (buffer[2] == 0x20 || buffer[2] == 0x21) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue