summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2023-06-21 10:11:32 -0700
committerGitHub <noreply@github.com>2023-06-21 10:11:32 -0700
commitb783932cd3c27b3a5fc1cde300a0a78bb05e15bc (patch)
treec4c687b0f80812107f2ad1def84cdc448a6944eb
parente41c4dad76aed33a90237e0a3ce140d29f75418c (diff)
downloadbinaryen-b783932cd3c27b3a5fc1cde300a0a78bb05e15bc.tar.gz
binaryen-b783932cd3c27b3a5fc1cde300a0a78bb05e15bc.tar.bz2
binaryen-b783932cd3c27b3a5fc1cde300a0a78bb05e15bc.zip
Limit literal printing to a reasonable limit (#5779)
Without this, a massive GC array for example can end up being printed as a huge amount of output, which is a problem in the fuzzer. I noticed this because a testcase was taking minutes to run. Perhaps we should add an option (BINARYEN_PRINT_FULL=1?) to disable this limit, but let's see if we ever need that.
-rw-r--r--src/wasm/literal.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/wasm/literal.cpp b/src/wasm/literal.cpp
index 53740c773..a0e3d2bf6 100644
--- a/src/wasm/literal.cpp
+++ b/src/wasm/literal.cpp
@@ -626,6 +626,10 @@ std::ostream& operator<<(std::ostream& o, Literal literal) {
return o;
}
+// Printing literals is mainly for debugging purposes, and they can be of
+// massive size, so abbreviate past some point.
+static size_t LITERALS_PRINT_LIMIT = 20;
+
std::ostream& operator<<(std::ostream& o, wasm::Literals literals) {
if (literals.size() == 1) {
return o << literals[0];
@@ -636,6 +640,10 @@ std::ostream& operator<<(std::ostream& o, wasm::Literals literals) {
}
for (size_t i = 1; i < literals.size(); ++i) {
o << ", " << literals[i];
+ if (i == LITERALS_PRINT_LIMIT) {
+ o << "[..]";
+ break;
+ }
}
return o << ')';
}