From bed6c21a24b701a195154b5fcde0b7ec8bb730dc Mon Sep 17 00:00:00 2001 From: "Zane U. Ji" Date: Sun, 1 Jun 2014 17:16:02 +0800 Subject: [PATCH] Fixed compiling problems --- src/wraplibxml.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/wraplibxml.cpp b/src/wraplibxml.cpp index 00a52e2..a7ed8e2 100644 --- a/src/wraplibxml.cpp +++ b/src/wraplibxml.cpp @@ -492,14 +492,20 @@ std::string WrapLibxml::dumpXPathObject ( xmlXPathObjectPtr obj ) FILE *fp = tmpfile(); xmlXPathDebugDumpObject ( fp, obj, 0/*depth*/ ); - fpos_t size = ftell ( fp ); std::string str; - str.resize ( size ); - fseek ( fp, 0, SEEK_SET ); - fread ( ( char * ) str.c_str(), 1, str.capacity(), fp ); + long size = ftell ( fp ); + if ( size == -1 ) + return str; + + str.resize ( size + 1 ); + if ( str.capacity() != ( size_t ) size + 1 ) + return str; + rewind ( fp ); + size_t read = fread ( ( char * ) str.c_str(), 1, str.capacity(), fp ); + str[size] = '\0'; fclose ( fp ); - return str; + return read == str.capacity() ? str : sstream.str(); } return sstream.str();