...
| Code Block | ||
|---|---|---|
| ||
struct myData {
char c;
floatlong fl;
};
/* ... */
FILE *file;
struct myData data;
/* initialize file */
if (fread(&data, sizeof(struct myData), 1, file) < sizeof(struct myData)) {
/* handle error */
}
|
...
| Code Block | ||
|---|---|---|
| ||
struct myData {
char c;
floatlong fl;
};
/* ... */
FILE *file;
struct myData data;
char buf[25];
char *end_ptr;
/* initialize file */
if (fscanf(file, "%c %f\n", &data.c, &data.f) != 2) {
fgets(myData.c, 1, file) == NULL) {
/* Handle Error */
}
if (fgets(buf, sizeof(buf), file) == NULL) {
/* Handle Error */
}
myData.l = strtol(buf, &end_ptr, 10);
if ((ERANGE == errno)
|| (end_ptr == buff)
|| ('\n' != *end_ptr && '\0' != *end_ptr) {
/* handleHandle errorError */
}
|
...
Risk Assessment
Reading binary data that has a different format than expected may result in unintended program behavior.
...