MeshCache: add error handling to fread() calls
Handle return value of `fread()`, by showing an error message when the
file cannot be read from and stopping further processing. Not only is
error handing a good idea, it also prevents GCC from warning that the
return value of `fread()` should not be ignored.
This is similar to {D9916}.
Reviewed By: campbellbarton
Differential Revision: https://developer.blender.org/D10079
This commit is contained in:
@@ -151,11 +151,13 @@ bool MOD_meshcache_read_pc2_index(FILE *fp,
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t num_verts_read = 0;
|
||||
errno = 0;
|
||||
if (factor >= 1.0f) {
|
||||
float *vco = *vertexCos;
|
||||
uint i;
|
||||
for (i = pc2_head.verts_tot; i != 0; i--, vco += 3) {
|
||||
fread(vco, sizeof(float[3]), 1, fp);
|
||||
num_verts_read += fread(vco, sizeof(float[3]), 1, fp);
|
||||
|
||||
#ifdef __BIG_ENDIAN__
|
||||
BLI_endian_switch_float(vco + 0);
|
||||
@@ -170,7 +172,7 @@ bool MOD_meshcache_read_pc2_index(FILE *fp,
|
||||
uint i;
|
||||
for (i = pc2_head.verts_tot; i != 0; i--, vco += 3) {
|
||||
float tvec[3];
|
||||
fread(tvec, sizeof(float[3]), 1, fp);
|
||||
num_verts_read += fread(tvec, sizeof(float[3]), 1, fp);
|
||||
|
||||
#ifdef __BIG_ENDIAN__
|
||||
BLI_endian_switch_float(tvec + 0);
|
||||
@@ -184,6 +186,11 @@ bool MOD_meshcache_read_pc2_index(FILE *fp,
|
||||
}
|
||||
}
|
||||
|
||||
if (num_verts_read != pc2_head.verts_tot) {
|
||||
*err_str = errno ? strerror(errno) : "Vertex coordinate read failed";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user