Skip to content

Commit

Permalink
Fix invalid eof detection for point clouds
Browse files Browse the repository at this point in the history
  • Loading branch information
nmellado committed May 26, 2016
1 parent 84d079e commit 0c74d2a
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 additions & 27 deletions super4pcs/io/io_ply.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,22 +221,24 @@ readBinary1Body (const std::string & filename,
}
delete [] v;

if (feof (in)){
cerr << "(PLY) incomplete file" << endl;
return false;
}
if (numOfFaces != 0){
if (feof (in)){
cerr << "(PLY) incomplete file" << endl;
return false;
}

// *****************
// Reading topology.
// *****************
for (unsigned int i = 0; i < numOfFaces && !feof (in); i++) {
unsigned int f[4];
char polygonSize;
/*count = */fread (&polygonSize, 1, 1, in);
/*count = */fread (f, 4, 3, in);
if (bigEndian == true)
bigLittleEndianSwap (f, 3);
face.push_back(tripple(f[0],f[1],f[2]));
// *****************
// Reading topology.
// *****************
for (unsigned int i = 0; i < numOfFaces && !feof (in); i++) {
unsigned int f[4];
char polygonSize;
/*count = */fread (&polygonSize, 1, 1, in);
/*count = */fread (f, 4, 3, in);
if (bigEndian == true)
bigLittleEndianSwap (f, 3);
face.push_back(tripple(f[0],f[1],f[2]));
}
}

return true;
Expand Down Expand Up @@ -335,19 +337,21 @@ readASCII1Body (const std::string & filename,
}
}

if (feof (in)){
cerr << "(PLY) incomplete file" << endl;
return false;
}
if (numOfFaces != 0){
if (feof (in)){
cerr << "(PLY) incomplete file" << endl;
return false;
}

// *****************
// Reading topology.
// *****************
for (unsigned int i = 0; i < numOfFaces && !feof (in); i++) {
int f[3];
int polygonSize;
/*count = */fscanf (in, "%d %d %d %d", &polygonSize, &f[0], &f[1], &f[2]);
face.push_back(tripple(f[0],f[1],f[2]));
// *****************
// Reading topology.
// *****************
for (unsigned int i = 0; i < numOfFaces && !feof (in); i++) {
int f[3];
int polygonSize;
/*count = */fscanf (in, "%d %d %d %d", &polygonSize, &f[0], &f[1], &f[2]);
face.push_back(tripple(f[0],f[1],f[2]));
}
}

return true;
Expand Down

0 comments on commit 0c74d2a

Please sign in to comment.