Don't query names of empty symbols
This makes it possible to return a reference from TSymbol::name()
instead of a pointer. This is safer since it completely avoids the
possibility of a nullptr dereference. An assert is making sure that
the function is not being called for empty symbols.
BUG=angleproject:2267
TEST=angle_unittests
Change-Id: I44279f65989dbb828322843fc0216ba84d91dedf
Reviewed-on: https://chromium-review.googlesource.com/836894
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
diff --git a/src/compiler/translator/Symbol.cpp b/src/compiler/translator/Symbol.cpp
index fe5914c..f85e7eb 100644
--- a/src/compiler/translator/Symbol.cpp
+++ b/src/compiler/translator/Symbol.cpp
@@ -38,22 +38,22 @@
mSymbolType == SymbolType::NotResolved || mSymbolType == SymbolType::Empty);
}
-const TString *TSymbol::name() const
+const TString &TSymbol::name() const
{
- if (mName != nullptr || mSymbolType == SymbolType::Empty)
+ if (mName != nullptr)
{
- return mName;
+ return *mName;
}
ASSERT(mSymbolType == SymbolType::AngleInternal);
TInfoSinkBase symbolNameOut;
symbolNameOut << "s" << mUniqueId.get();
- return NewPoolTString(symbolNameOut.c_str());
+ return *NewPoolTString(symbolNameOut.c_str());
}
const TString &TSymbol::getMangledName() const
{
ASSERT(mSymbolType != SymbolType::Empty);
- return *name();
+ return name();
}
TVariable::TVariable(TSymbolTable *symbolTable,
@@ -160,7 +160,7 @@
const TString *TFunction::buildMangledName() const
{
- std::string newName = name()->c_str();
+ std::string newName = name().c_str();
newName += kFunctionMangledNameSeparator;
for (const auto &p : parameters)
@@ -185,13 +185,13 @@
bool TFunction::isMain() const
{
- return symbolType() == SymbolType::UserDefined && *name() == "main";
+ return symbolType() == SymbolType::UserDefined && name() == "main";
}
bool TFunction::isImageFunction() const
{
return symbolType() == SymbolType::BuiltIn &&
- (*name() == "imageSize" || *name() == "imageLoad" || *name() == "imageStore");
+ (name() == "imageSize" || name() == "imageLoad" || name() == "imageStore");
}
} // namespace sh