[cgma-dev] r5557 - cgm/trunk/itaps
jvporter at wisc.edu
jvporter at wisc.edu
Fri Jun 8 11:05:04 CDT 2012
Author: jvporter
Date: 2012-06-08 11:05:04 -0500 (Fri, 08 Jun 2012)
New Revision: 5557
Modified:
cgm/trunk/itaps/iGeom_CGMA.cc
Log:
* Fix fread checks
* Make .cub file magic string check actually work
Modified: cgm/trunk/itaps/iGeom_CGMA.cc
===================================================================
--- cgm/trunk/itaps/iGeom_CGMA.cc 2012-06-07 23:00:08 UTC (rev 5556)
+++ cgm/trunk/itaps/iGeom_CGMA.cc 2012-06-08 16:05:04 UTC (rev 5557)
@@ -6554,7 +6554,7 @@
void
iGeom_load_cub_geometry(const char *name, int* err)
{
- size_t bytes_read;
+ size_t items_read;
FILE *cubfile = fopen(name, "rb");
if (NULL == cubfile) RETURN(iBase_FILE_NOT_FOUND);
@@ -6566,25 +6566,28 @@
}
long endpos = ftell(cubfile);
-
- char magic_str[4] = {'\0', '\0', '\0', '\0'};
- bytes_read = fread(magic_str, 1, 4, cubfile);
- if (bytes_read != 4) {
- ERROR(iBase_FAILURE, "Error reading .cub file");
+ result = fseek(cubfile, 0, 0 /*SEEK_SET*/);
+ if (result) {
+ ERROR(iBase_FAILURE, "Seek failed reading cub file header.");
}
- if (!strcmp(magic_str, "CUBE")) {
+
+ char magic_str[5] = "";
+ items_read = fread(magic_str, 1, 4, cubfile);
+ if (items_read != 4) {
+ ERROR(iBase_FAILURE, "Error reading .cub file magic string");
+ }
+ if (strcmp(magic_str, "CUBE")) {
ERROR(iBase_NOT_SUPPORTED, "Wrong magic string in .cub file.");
}
// get the model header
- //result = fseek(cubfile, 4, SEEK_SET);
- result = fseek(cubfile, 4, 0);
+ result = fseek(cubfile, 4, 0 /*SEEK_SET*/);
if (result) {
- ERROR(iBase_FAILURE, "Seek failed reading cub file header.");
+ ERROR(iBase_FAILURE, "Seek failed reading after cub file header.");
}
int header[6];
- bytes_read = fread(header, 4, 6, cubfile);
- if (bytes_read != 4*6) {
+ items_read = fread(header, 4, 6, cubfile);
+ if (items_read != 6) {
ERROR(iBase_FAILURE, "Error reading .cub file");
More information about the cgma-dev
mailing list