add check data valid in getStringFromFile

so far no check would be crashed when getData faild.
maybe return an empty string is better.
This commit is contained in:
hbb 2014-01-15 12:39:56 +08:00
parent e5aaed49cf
commit 8fac676a82
1 changed files with 2 additions and 0 deletions

View File

@ -547,6 +547,8 @@ static Data getData(const std::string& filename, bool forString)
std::string FileUtils::getStringFromFile(const std::string& filename) std::string FileUtils::getStringFromFile(const std::string& filename)
{ {
Data data = getData(filename, true); Data data = getData(filename, true);
if (! data.getBytes())
return "";
std::string ret((const char*)data.getBytes()); std::string ret((const char*)data.getBytes());
return ret; return ret;
} }