From 8fac676a82927e608a858744f120f58c9492ffcc Mon Sep 17 00:00:00 2001 From: hbb Date: Wed, 15 Jan 2014 12:39:56 +0800 Subject: [PATCH] add check data valid in getStringFromFile so far no check would be crashed when getData faild. maybe return an empty string is better. --- cocos/2d/platform/CCFileUtils.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cocos/2d/platform/CCFileUtils.cpp b/cocos/2d/platform/CCFileUtils.cpp index 3404675922..1434eea8e6 100644 --- a/cocos/2d/platform/CCFileUtils.cpp +++ b/cocos/2d/platform/CCFileUtils.cpp @@ -547,6 +547,8 @@ static Data getData(const std::string& filename, bool forString) std::string FileUtils::getStringFromFile(const std::string& filename) { Data data = getData(filename, true); + if (! data.getBytes()) + return ""; std::string ret((const char*)data.getBytes()); return ret; }