Commit a2b0b3d9 authored by Jakob Kummerow's avatar Jakob Kummerow Committed by V8 LUCI CQ

[wasm] Disassembler: make label printing more robust

The return value of StringBuilder::cursor() isn't safe to store across
print operations, because it will become stale if the StringBuilder
needs to grow its buffer. The solution is to store the length() instead,
and recompute the raw pointer from the updated start() when needed.

Change-Id: Id453e39743644a5df9f7cbb8b1acaea7f5890453
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3782671
Auto-Submit: Jakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
Reviewed-by: 's avatarManos Koukoutos <manoskouk@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81912}
parent 40a5328b
...@@ -290,7 +290,7 @@ class ImmediatesPrinter { ...@@ -290,7 +290,7 @@ class ImmediatesPrinter {
void PrintDepthAsLabel(int imm_depth) { void PrintDepthAsLabel(int imm_depth) {
out_ << " "; out_ << " ";
const char* label_start = out_.cursor(); size_t label_start_position = out_.length();
int depth = imm_depth; int depth = imm_depth;
if (owner_->current_opcode_ == kExprDelegate) depth++; if (owner_->current_opcode_ == kExprDelegate) depth++;
// Be robust: if the module is invalid, print what we got. // Be robust: if the module is invalid, print what we got.
...@@ -309,8 +309,8 @@ class ImmediatesPrinter { ...@@ -309,8 +309,8 @@ class ImmediatesPrinter {
names()->PrintLabelName(out_, owner_->func_index_, names()->PrintLabelName(out_, owner_->func_index_,
label_info.name_section_index, label_info.name_section_index,
owner_->label_generation_index_++); owner_->label_generation_index_++);
label_info.length = static_cast<size_t>(out_.cursor() - label_start); label_info.length = out_.length() - label_start_position;
owner_->out_->PatchLabel(label_info, label_start); owner_->out_->PatchLabel(label_info, out_.start() + label_start_position);
} }
void BlockType(BlockTypeImmediate<validate>& imm) { void BlockType(BlockTypeImmediate<validate>& imm) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment