diff options
author | Alon Zakai <azakai@google.com> | 2021-03-11 15:12:51 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-11 15:12:51 -0800 |
commit | 74870e8a77625477e2c43883ec386380b2aea4e3 (patch) | |
tree | d243093ed5d34213f010a4ef558b047c034bb4e8 /src/passes/Print.cpp | |
parent | 1f695bc88423abcf03c006e62f137ac0e76f93df (diff) | |
download | binaryen-74870e8a77625477e2c43883ec386380b2aea4e3.tar.gz binaryen-74870e8a77625477e2c43883ec386380b2aea4e3.tar.bz2 binaryen-74870e8a77625477e2c43883ec386380b2aea4e3.zip |
[Wasm GC] Avoid extremely large outputs in TypeNamePrinter (#3667)
Diffstat (limited to 'src/passes/Print.cpp')
-rw-r--r-- | src/passes/Print.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 05a639158..4346fe705 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -96,9 +96,28 @@ struct TypeNamePrinter { void print(const Struct& struct_); void print(const Array& array); void print(const Rtt& rtt); + + // FIXME: This hard limit on how many times we call print() avoids extremely + // large outputs, which can be inconveniently large in some cases, but + // we should have a better mechanism for this. + static const size_t MaxPrints = 100; + + size_t prints = 0; + + bool exceededLimit() { + if (prints >= MaxPrints) { + os << "?"; + return true; + } + prints++; + return false; + } }; void TypeNamePrinter::print(Type type) { + if (exceededLimit()) { + return; + } if (type.isBasic()) { os << type; } else if (type.isTuple()) { @@ -119,6 +138,9 @@ void TypeNamePrinter::print(Type type) { } void TypeNamePrinter::print(HeapType type) { + if (exceededLimit()) { + return; + } if (type.isBasic()) { os << type; return; |