commit c0400957c65a6e707dd7dd5670f7c2a0a33386ea
parent bcf67f162019e8ffcd42e01851f679c6561e198f
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Thu, 10 Apr 2025 17:03:47 +0200
Fix of several problems in the binary loading procedure
Read error checks were incorrect, and conversion to host endianness had
type conversion problems.
Diffstat:
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/sstl_binary.c b/src/sstl_binary.c
@@ -27,7 +27,7 @@ parse_header(struct sstl* sstl, FILE* fp, const char* name)
char header[80];
ASSERT(sstl && fp && fp);
- if(fread(header, sizeof(header), 1, fp) != sizeof(header)) {
+ if(fread(header, sizeof(header), 1, fp) != 1) {
ERROR(sstl, "%s: invalid header\n", name);
return RES_BAD_ARG;
}
@@ -44,7 +44,7 @@ parse_triangle_count
char bytes[4]; /* Little endian */
ASSERT(sstl && fp && name && ntri);
- if(fread(bytes, sizeof(bytes), 1, fp) != sizeof(bytes)) {
+ if(fread(bytes, sizeof(bytes), 1, fp) != 1) {
ERROR(sstl, "%s: invalid triangle count\n", name);
return RES_BAD_ARG;
}
@@ -65,7 +65,7 @@ parse_triangle
const char* name,
const uint32_t itri) /* Triangle identifier */
{
- char bytes[4/*#bytes*/*12/*#vectors*/+2/*attribute*/];
+ uint8_t bytes[4/*#bytes*/*12/*#vectors*/+2/*attribute*/];
union { uint32_t ui32; float f; } ucast;
float* N = NULL; /* Normal */
float v[3][3] = {0}; /* Vertices */
@@ -73,7 +73,7 @@ parse_triangle
res_T res = RES_OK;
ASSERT(sstl && fp && name);
- if(fread(bytes, sizeof(bytes), 1, fp) != sizeof(bytes)) {
+ if(fread(bytes, sizeof(bytes), 1, fp) != 1) {
ERROR(sstl, "%s: invalid triangle %i\n", name, itri);
res = RES_BAD_ARG;
goto error;