From d1c277ef6acb2aeff5421267595d12c5d67d85bd Mon Sep 17 00:00:00 2001 From: rdb Date: Thu, 28 Mar 2024 22:49:15 +0100 Subject: [PATCH] cppparser: prevent enum values having long chain of additions See #1638 [skip ci] --- dtool/src/cppparser/cppEnumType.cxx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dtool/src/cppparser/cppEnumType.cxx b/dtool/src/cppparser/cppEnumType.cxx index 5ff18a65b0..1e0e133cad 100644 --- a/dtool/src/cppparser/cppEnumType.cxx +++ b/dtool/src/cppparser/cppEnumType.cxx @@ -117,6 +117,14 @@ add_element(const std::string &name, CPPExpression *value, } else if (_last_value->_type == CPPExpression::T_integer) { value = new CPPExpression(_last_value->_u._integer + 1); + } else if (_last_value->_type == CPPExpression::T_binary_operation && + _last_value->_u._op._operator == '+' && + _last_value->_u._op._op2->_type == CPPExpression::T_integer) { + // Prevent an endless expansion of + expressions. + value = new CPPExpression('+', + _last_value->_u._op._op1, + new CPPExpression(_last_value->_u._op._op2->_u._integer + 1)); + } else { // We may not be able to determine the value just yet. No problem; // we'll just define it as another expression.