From 925f5fb608b12ad0c29cc38b8f870e3677bb276b Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sun, 4 Jun 2023 15:58:26 -0700 Subject: [PATCH] Fix incorrect assert for partial oob write to function return value Partial out-of-bounds write to a function's return value will trigger an assert, even though the operation is valid. The assert checks that the truncated value has the expected width, but instead it should check that the non-truncated value has the expected with. Move the assert before the truncation to fix this. Signed-off-by: Lars-Peter Clausen --- vvp/vthread.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vvp/vthread.cc b/vvp/vthread.cc index 2b35315b0..397bc7ba9 100644 --- a/vvp/vthread.cc +++ b/vvp/vthread.cc @@ -5453,6 +5453,7 @@ bool of_RET_VEC4(vthread_t thr, vvp_code_t cp) vthread_t fun_thr = get_func(thr); assert(index < get_max(fun_thr, val)); + assert(val.size() == wid); unsigned depth = get_depth(fun_thr, index, val); int64_t off = off_index ? thr->words[off_index].w_int : 0; @@ -5472,7 +5473,6 @@ bool of_RET_VEC4(vthread_t thr, vvp_code_t cp) fun_thr->parent->poke_vec4(depth, val); } else { vvp_vector4_t tmp_dst = fun_thr->parent->peek_vec4(depth); - assert(val.size() == wid); tmp_dst.set_vec(off, val); fun_thr->parent->poke_vec4(depth, tmp_dst); }