Skip to content

Fix #168: ClearConst() does not clear m_vStringVarBuf - #169

Merged
beltoforion merged 5 commits into
masterfrom
claude/clearconst-test
Apr 10, 2026
Merged

beltoforion merged 5 commits into
masterfrom
claude/clearconst-test

Conversation

@beltoforion

Copy link
Copy Markdown
Owner

Fixes #168.

Problem

ClearConst() cleared m_StrVarDef (the name→index map) but not m_vStringVarBuf (the string value buffer). After each round of DefineStrConst + ClearConst + DefineStrConst the buffer accumulated stale entries, leaving the two structures out of sync.

Fix

One line added to ClearConst() in muParserBase.cpp:

m_vStringVarBuf.clear();

Test

TestIssue168 in muParserTest.cpp verifies that after ClearConst() + re-registration, m_vStringVarBuf.size() equals the number of newly registered constants (2), not the accumulated total (4). The test failed before this fix and passes after.

claude added 5 commits April 10, 2026 21:05
ClearConst() clears m_StrVarDef (the name->index map) but does not
clear m_vStringVarBuf (the value buffer).  After calling ClearConst()
and re-registering string constants the buffer accumulates stale
entries, while the map points at the tail indices of the growing
buffer.  The existing guard in IsStrVarTok only checks whether the
buffer is non-empty, not that item->second is a valid index.

The test defines two string constants, calls ClearConst(), re-registers
them with different values, and checks that evaluation returns the new
values — not the stale ones from the first registration.  This will
fail if the index arithmetic or buffer management regresses.

https://claude.ai/code/session_01AdA3xUA3X15KMYv6VC7tXQ
The previous version checked evaluation results which were always correct
(indices stay valid because the buffer only grows).  The real symptom is
that m_vStringVarBuf accumulates stale entries across ClearConst() calls:
after one round of DefineStrConst + ClearConst + DefineStrConst the buffer
has 4 entries instead of 2.

Check the buffer size directly, mirroring how TestIssue165 inspects
m_vStringBuf.  The test now fails with the current code and will pass
once ClearConst() is fixed to also clear m_vStringVarBuf.

https://claude.ai/code/session_01AdA3xUA3X15KMYv6VC7tXQ
m_vStringVarBuf must be cleared alongside m_StrVarDef to keep the two
structures in sync. Previously, repeated calls to ClearConst() followed
by DefineStrConst() caused the value buffer to accumulate stale entries
indefinitely.

https://claude.ai/code/session_01AdA3xUA3X15KMYv6VC7tXQ
@beltoforion
beltoforion merged commit 8451d95 into master Apr 10, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ClearConst() does not clear m_vStringVarBuf

2 participants