Skip to content

Commit d4f3b30

Browse files
Fix #14667 Stack overflow in ValueType::getSizeOf() (#8440)
Co-authored-by: chrchr-github <noreply@github.com>
1 parent caff3d4 commit d4f3b30

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
@@ -11684,6 +11684,19 @@ class TestOther : public TestFixture {
1168411684
"void f(S<char, 3> s) {}\n");
1168511685
ASSERT_EQUALS("", errout_str());
1168611686

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

0 commit comments

Comments
 (0)