From: Kim Kulling Date: Wed, 27 Jan 2016 19:26:38 +0000 (+0100) Subject: gltf: make code more radable and check against one possible null ptr X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bac6067869076e1ed4b7c742b77881b56a004950;p=platform%2Fupstream%2Fassimp.git gltf: make code more radable and check against one possible null ptr access. --- diff --git a/code/glTFAsset.inl b/code/glTFAsset.inl index bdc53b2..858788b 100644 --- a/code/glTFAsset.inl +++ b/code/glTFAsset.inl @@ -1041,11 +1041,14 @@ inline std::string Asset::FindUniqueID(const std::string& str, const char* suffi return id; } -namespace Util -{ +namespace Util { + + inline + bool ParseDataURI(const char* const_uri, size_t uriLen, DataURI& out) { + if ( NULL == const_uri ) { + return false; + } - inline bool ParseDataURI(const char* const_uri, size_t uriLen, DataURI& out) - { if (const_uri[0] != 0x10) { // we already parsed this uri? if (strncmp(const_uri, "data:", 5) != 0) // not a data uri? return false; @@ -1064,28 +1067,40 @@ namespace Util size_t i = 5, j; if (uri[i] != ';' && uri[i] != ',') { // has media type? uri[1] = i; - for (; uri[i] != ';' && uri[i] != ',' && i < uriLen; ++i) {} + for (; uri[i] != ';' && uri[i] != ',' && i < uriLen; ++i) { + // nothing to do! + } } while (uri[i] == ';' && i < uriLen) { uri[i++] = '\0'; - for (j = i; uri[i] != ';' && uri[i] != ',' && i < uriLen; ++i) {} + for (j = i; uri[i] != ';' && uri[i] != ',' && i < uriLen; ++i) { + // nothing to do! + } - if (strncmp(uri + j, "charset=", 8) == 0) uri[2] = j + 8; - else if (strncmp(uri + j, "base64", 6) == 0) uri[3] = j; + if ( strncmp( uri + j, "charset=", 8 ) == 0 ) { + uri[ 2 ] = j + 8; + } else if ( strncmp( uri + j, "base64", 6 ) == 0 ) { + uri[ 3 ] = j; + } } if (i < uriLen) { uri[i++] = '\0'; uri[4] = i; - } - else { + } else { uri[1] = uri[2] = uri[3] = 0; uri[4] = 5; } } - if (uri[1] != 0) out.mediaType = uri + uri[1]; - if (uri[2] != 0) out.charset = uri + uri[2]; - if (uri[3] != 0) out.base64 = true; + if ( uri[ 1 ] != 0 ) { + out.mediaType = uri + uri[ 1 ]; + } + if ( uri[ 2 ] != 0 ) { + out.charset = uri + uri[ 2 ]; + } + if ( uri[ 3 ] != 0 ) { + out.base64 = true; + } out.data = uri + uri[4]; out.dataLength = (uri + uriLen) - out.data;