Lines
100 %
Functions
Branches
//! Tests for `write_debug_string_gc` (moved out of `debug_values.rs` per
//! CLAUDE.md's file-size guideline).
use super::*;
use crate::compiler::emit::FunctionEmitter;
use crate::compiler::layout::GcLocals;
const LOCAL_GC_ARR_FOR_TEST: u32 = 0;
const LOCAL_IDX_FOR_TEST: u32 = 1;
/// Carried-in fix (ADR-0033 Phase 3): `write_debug_string_gc` used to
/// compute `DEBUG_VALUE_DATA_SIZE as u32 + len` and `DEBUG_ENTITY_BYTES +
/// len` with plain `+`, which wraps silently in release on overflow. A
/// string length near `u32::MAX` (unreachable from a real script byte
/// buffer, but the guest supplies `len` as a plain i32) must now error
/// rather than compute a wrapped, wrong entity size.
#[test]
fn write_debug_string_gc_errors_on_a_length_that_would_overflow() {
let mut serializer = OutputSerializer::new(0);
let mut emit = FunctionEmitter::new();
let gc = GcLocals {
type_idx: 0,
arr: LOCAL_GC_ARR_FOR_TEST,
idx: LOCAL_IDX_FOR_TEST,
};
let err = serializer
.write_debug_string_gc(&mut emit, ValueType::String, 0, u32::MAX, &gc)
.expect_err("a length this close to u32::MAX must overflow the debug entity size");
assert!(err.to_string().contains("overflows a debug entity"));
}