Conversation
|
我没有复现出 “如何测试” 中描述的软件闪退 🤔 |
There was a problem hiding this comment.
Pull request overview
This PR fixes a crash issue that occurs when undefined macros are called in the preamble area of a TeXmacs document. The crash happens when the environment tries to execute or write back UNINIT values for variables that were never defined.
Changes:
- Added defensive checks for
UNINITtree labels in the execution path - Enhanced
exec_value()to safely handle undefined variables by returning empty strings - Modified
exec_with()andexec_until_with()to avoid writing backUNINITvalues when restoring environment state
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Typeset/Env/env_exec.cpp | Added UNINIT checks in exec(), exec_value(), exec_with(), and exec_until_with() to prevent crashes when accessing undefined variables |
| devel/201_71.md | Documentation explaining the fix and test procedure |
| TeXmacs/tests/tmu/201_71.tmu | Test case demonstrating the crash scenario with an undefined backcolor macro referenced in a preamble |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| tree r= exec (t[n - 1]); | ||
| for (i= k - 1; i >= 0; i--) | ||
| write_update (vars[i], oldv[i]); | ||
| if (L (oldv[i]) != UNINIT) write_update (vars[i], oldv[i]); |
There was a problem hiding this comment.
The fix prevents writing UNINIT values back, which avoids crashes but changes the semantics of the WITH construct. Variables that didn't exist before a WITH block will now persist after the block exits, instead of returning to their undefined state. Consider using env->reset(vars[i]) instead of skipping the write_update when oldv[i] is UNINIT, to properly restore the undefined state.
| } | ||
| for (i= k - 1; i >= 0; i--) | ||
| write_update (vars[i], oldv[i]); | ||
| if (L (oldv[i]) != UNINIT) write_update (vars[i], oldv[i]); |
There was a problem hiding this comment.
The fix prevents writing UNINIT values back, which avoids crashes but changes the semantics of the WITH construct. Variables that didn't exist before a WITH block will now persist after the block exits, instead of returning to their undefined state. Consider using env->reset(vars[i]) to properly restore the undefined state, similar to line 663 in exec_with.
| if (L (oldv[i]) != UNINIT) write_update (vars[i], oldv[i]); | |
| if (L (oldv[i]) != UNINIT) | |
| write_update (vars[i], oldv[i]); | |
| else | |
| reset (vars[i]); |
No description provided.