1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:17:44 +00:00

LibJS/Bytecode: Update NewArray stringifier to print a register range

NewArray now only contains two elements maximum in `m_elements` to
indicate the range of registers to create the array from.

However, `m_element_count` still contains how many registers are in the
range and the stringifier was not updated to account for this. Thus, if
the range contained more than 2 registers, it would do a read OOB on
`m_elements`.

This makes it now just print the first and second entries in
`m_elements` in the format of `[<reg>-<reg>]`.
This commit is contained in:
Luke Wilde 2022-03-27 17:49:10 +01:00 committed by Andreas Kling
parent 78f8821152
commit 741745baab

View file

@ -725,13 +725,7 @@ String NewArray::to_string_impl(Bytecode::Executable const&) const
StringBuilder builder;
builder.append("NewArray");
if (m_element_count != 0) {
builder.append(" [");
for (size_t i = 0; i < m_element_count; ++i) {
builder.appendff("{}", m_elements[i]);
if (i != m_element_count - 1)
builder.append(',');
}
builder.append(']');
builder.appendff(" [{}-{}]", m_elements[0], m_elements[1]);
}
return builder.to_string();
}