diff --git a/gfx/angle/src/compiler/MapLongVariableNames.cpp b/gfx/angle/src/compiler/MapLongVariableNames.cpp index 3852743fb47f..f99438044632 100644 --- a/gfx/angle/src/compiler/MapLongVariableNames.cpp +++ b/gfx/angle/src/compiler/MapLongVariableNames.cpp @@ -14,12 +14,18 @@ TString mapLongName(int id, const TString& name, bool isGlobal) ASSERT(name.size() > MAX_SHORTENED_IDENTIFIER_SIZE); TStringStream stream; uint64 hash = SpookyHash::Hash64(name.data(), name.length(), 0); - stream << "webgl_" + + // We want to avoid producing a string with a double underscore, + // which would be an illegal GLSL identifier. We can assume that the + // original identifier doesn't have a double underscore, otherwise + // it's illegal anyway. + stream << (name[0] == '_' ? "webgl" : "webgl_") << name.substr(0, 9) - << "_" + << (name[8] == '_' ? "" : "_") << std::hex << hash; - ASSERT(stream.str().length() == MAX_SHORTENED_IDENTIFIER_SIZE); + ASSERT(stream.str().length() <= MAX_SHORTENED_IDENTIFIER_SIZE); + ASSERT(stream.str().length() >= MAX_SHORTENED_IDENTIFIER_SIZE - 2); return stream.str(); }