From 9d466e5830dda5678073673565152450b65a1ad7 Mon Sep 17 00:00:00 2001 From: xiepengfei Date: Fri, 18 Sep 2026 19:25:27 +0800 Subject: [PATCH] fix: guard null sidebar pointer in setAlive close path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Root cause: m_sidebar is initialized to nullptr and the same function already guards with "if (m_sidebar && ...)" at line 1776, but the changeResetModelData() call at line 1800 omits the null check, causing a potential null pointer dereference 2. Fix: add "if (m_sidebar)" guard before calling changeResetModelData() to skip the call when sidebar is null 3. Impact: no behavior change when sidebar is non-null; prevents crash when sidebar pointer is null during document close path Influence: 1. Test opening and closing documents with sidebar visible 2. Test closing documents when sidebar is not initialized 3. Verify no regression on annotation save and bookmark persistence fix: 修复关闭文档路径中侧边栏空指针解引用 1. 根因:m_sidebar 初始化为 nullptr,同函数第 1776 行已有 "if (m_sidebar && ...)" 守卫,但第 1800 行调用 changeResetModelData() 时遗漏空检查,存在空指针解引用风险 2. 方案:在调用 changeResetModelData() 前增加 "if (m_sidebar)" 守卫,指针为空时跳过调用 3. 影响:侧边栏非空时行为不变;侧边栏为空时避免崩溃 Influence: 1. 测试侧边栏可见时打开和关闭文档 2. 测试侧边栏未初始化时关闭文档 3. 验证批注保存和书签持久化无回归 PMS: BUG-213 --- reader/uiframe/DocSheet.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/reader/uiframe/DocSheet.cpp b/reader/uiframe/DocSheet.cpp index a07111aa9..df567eb35 100644 --- a/reader/uiframe/DocSheet.cpp +++ b/reader/uiframe/DocSheet.cpp @@ -1797,7 +1797,9 @@ void DocSheet::setAlive(bool alive) if (m_documentChanged && m_renderer) { if (m_renderer->save()) { m_documentChanged = false; - m_sidebar->changeResetModelData(); + if (m_sidebar) { + m_sidebar->changeResetModelData(); + } // 注释保存后文件内容已变化,重写书签刷新内容指纹, // 避免下次打开时书签因指纹不匹配被误判为旧文件遗留 Database::instance()->saveBookmarks(filePath(), m_bookmarks);