Skip to content

Commit

Permalink
tighten up the error checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee Thomason committed May 22, 2015
1 parent 2ecc203 commit 7a93b33
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tinyxml2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1857,7 +1857,7 @@ XMLError XMLDocument::LoadFile( FILE* fp )
return _errorID;
}

if ( filelength >= (size_t)-1 ) {
if ( (size_t)filelength >= (size_t)-1 ) {

This comment has been minimized.

Copy link
@Dmitry-Me

Dmitry-Me May 22, 2015

Contributor

@leethomason What motivated you to do this change? The problem is you cannot assume long is larger than size_t or vice versa. The original code would cause a promotion but new code can cause undefined behavior.

This comment has been minimized.

Copy link
@leethomason

leethomason May 22, 2015

Owner

Warning from GCC. I was assuming that size_t promotes to an unsigned 64 - but if that's not the case, then yeah, not the right fix. I'm not sure how to fix the warning then.

This comment has been minimized.

Copy link
@Dmitry-Me

Dmitry-Me May 25, 2015

Contributor

I opened #339

// Cannot handle files which won't fit in buffer together with null terminator
SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 );
return _errorID;
Expand Down
4 changes: 2 additions & 2 deletions xmltest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1474,9 +1474,9 @@ int main( int argc, const char ** argv )
doc.Parse(xml0);
XMLTest("Test that the code changes do not affect normal parsing", doc.Error(), false);
doc.Parse(xml1);
XMLTest("Test that the second declaration throws an error", doc.Error(), true);
XMLTest("Test that the second declaration throws an error", doc.ErrorID(), XML_ERROR_PARSING_DECLARATION);
doc.Parse(xml2);
XMLTest("Test that declaration after a child throws an error", doc.Error(), true);
XMLTest("Test that declaration after a child throws an error", doc.ErrorID(), XML_ERROR_PARSING_DECLARATION);
}

// ----------- Performance tracking --------------
Expand Down

0 comments on commit 7a93b33

Please sign in to comment.