Skip to content

Commit 7b8814a

Browse files
committed
Fix #14667 Stack overflow in ValueType::getSizeOf()
1 parent 8e2ff1b commit 7b8814a

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

lib/symboldatabase.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8508,7 +8508,7 @@ static size_t bitCeil(size_t x)
85088508

85098509
static size_t getAlignOf(const ValueType& vt, const Settings& settings, ValueType::Accuracy accuracy, ValueType::SizeOf sizeOf, int maxRecursion = 0)
85108510
{
8511-
if (maxRecursion == settings.vfOptions.maxAlignOfRecursion) {
8511+
if (maxRecursion > settings.vfOptions.maxAlignOfRecursion) {
85128512
// TODO: add bailout message
85138513
return 0;
85148514
}
@@ -8539,7 +8539,7 @@ static size_t getAlignOf(const ValueType& vt, const Settings& settings, ValueTyp
85398539

85408540
size_t ValueType::getSizeOf( const Settings& settings, Accuracy accuracy, SizeOf sizeOf, int maxRecursion) const
85418541
{
8542-
if (maxRecursion == settings.vfOptions.maxSizeOfRecursion) {
8542+
if (maxRecursion > settings.vfOptions.maxSizeOfRecursion) {
85438543
// TODO: add bailout message
85448544
return 0;
85458545
}

test/testother.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11683,6 +11683,19 @@ class TestOther : public TestFixture {
1168311683
"void f(S<char, 3> s) {}\n");
1168411684
ASSERT_EQUALS("", errout_str());
1168511685

11686+
check("struct T {\n" // #14667
11687+
" U u1, u2;\n"
11688+
" union {\n"
11689+
" enum { E0, E1 } e;\n"
11690+
" U u3;\n"
11691+
" T i;\n"
11692+
" } x;\n"
11693+
"};\n"
11694+
"T f(T t) {\n"
11695+
" return t;\n"
11696+
"}");
11697+
ASSERT_EQUALS("", errout_str()); // don't crash
11698+
1168611699
Settings settingsUnix32 = settingsBuilder().platform(Platform::Type::Unix32).build();
1168711700
check("struct S {\n" // #13850
1168811701
" int i0 : 32;\n"

0 commit comments

Comments
 (0)