Fix seg fault

Check types before accessing typeName.

Fix #2848.
This commit is contained in:
Jeremy Hayes 2021-12-28 15:17:39 -07:00
parent ca13951205
commit 46466be045
5 changed files with 78 additions and 3 deletions

View file

@ -2446,11 +2446,15 @@ public:
//
bool sameStructType(const TType& right) const
{
// TODO: Why return true when neither types are structures?
// Most commonly, they are both nullptr, or the same pointer to the same actual structure
if ((!isStruct() && !right.isStruct()) ||
(isStruct() && right.isStruct() && structure == right.structure))
return true;
if (!isStruct() || !right.isStruct())
return false;
// Structure names have to match
if (*typeName != *right.typeName)
return false;
@ -2460,8 +2464,7 @@ public:
bool isGLPerVertex = *typeName == "gl_PerVertex";
// Both being nullptr was caught above, now they both have to be structures of the same number of elements
if (!isStruct() || !right.isStruct() ||
(structure->size() != right.structure->size() && !isGLPerVertex))
if (structure->size() != right.structure->size() && !isGLPerVertex)
return false;
// Compare the names and types of all the members, which have to match