Skip to content

Commit aa0e3dd

Browse files
Fix off-by-one in Stack::push() and Stack::pushZeroes() boundary checks (#5015)
Change strict less-than (<) to less-than-or-equal (<=) in the FW_ASSERT guards of Stack::push<T>() and Stack::pushZeroes(), matching the existing Stack::push(U8*, StackSizeType) overload. The old strict check rejected exact-fit growth (size + growth == MAX_STACK_SIZE) with a hard assertion, even though the directive handlers (ALLOCATE, CALL, etc.) correctly allow it. This mismatch let validated sequences abort the process at runtime instead of returning a handled STACK_OVERFLOW error. Fixes #5008 Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 9cf0ad0 commit aa0e3dd

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

Svc/FpySequencer/FpySequencerStack.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ F64 FpySequencer::Stack::pop<F64>() {
5757
template <typename T>
5858
void FpySequencer::Stack::push(T val) {
5959
static_assert(sizeof(T) == 8 || sizeof(T) == 4 || sizeof(T) == 2 || sizeof(T) == 1, "size must be 1, 2, 4, 8");
60-
FW_ASSERT(this->size + sizeof(val) < Fpy::MAX_STACK_SIZE, static_cast<FwAssertArgType>(this->size),
60+
FW_ASSERT(this->size + sizeof(val) <= Fpy::MAX_STACK_SIZE, static_cast<FwAssertArgType>(this->size),
6161
static_cast<FwAssertArgType>(sizeof(T)));
6262
// first make a byte array which can definitely store our val
6363
U8 valBytes[8] = {0};
@@ -131,7 +131,7 @@ void FpySequencer::Stack::push(U8* src, Fpy::StackSizeType srcSize) {
131131

132132
// pushes zero bytes to the stack
133133
void FpySequencer::Stack::pushZeroes(Fpy::StackSizeType byteCount) {
134-
FW_ASSERT(this->size + byteCount < Fpy::MAX_STACK_SIZE, static_cast<FwAssertArgType>(this->size),
134+
FW_ASSERT(this->size + byteCount <= Fpy::MAX_STACK_SIZE, static_cast<FwAssertArgType>(this->size),
135135
static_cast<FwAssertArgType>(byteCount));
136136
memset(this->top(), 0, byteCount);
137137
this->size += byteCount;

0 commit comments

Comments
 (0)