Skip to content

[201_71] 修复导言区调用未定义的宏导致软件crash问题#2751

Closed
jackmath5261-bit wants to merge 4 commits intomainfrom
jie/201_71/crash
Closed

[201_71] 修复导言区调用未定义的宏导致软件crash问题#2751
jackmath5261-bit wants to merge 4 commits intomainfrom
jie/201_71/crash

Conversation

@jackmath5261-bit
Copy link
Contributor

No description provided.

JackChen added 3 commits February 3, 2026 20:09
@jetjinser
Copy link
Contributor

我没有复现出 “如何测试” 中描述的软件闪退 🤔
另外,201_71.tmu,无论是 main 分支还是本 PR,我打开后都会报错,置空页面

@MoonL79 MoonL79 added the bug Something isn't working label Feb 5, 2026
@MoonL79 MoonL79 requested a review from Copilot February 5, 2026 02:06
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 UNINIT tree labels in the execution path
  • Enhanced exec_value() to safely handle undefined variables by returning empty strings
  • Modified exec_with() and exec_until_with() to avoid writing back UNINIT values 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]);
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
}
for (i= k - 1; i >= 0; i--)
write_update (vars[i], oldv[i]);
if (L (oldv[i]) != UNINIT) write_update (vars[i], oldv[i]);
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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]);

Copilot uses AI. Check for mistakes.
@MoonL79 MoonL79 closed this Feb 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants