Patch #2875 2009-12-27 17:18

techy

EditorManager accesses invalid page (debug3)
Download
2875-EditorManager.patch (896 bytes)
Category
Application::Bugfix
Status
Accepted
Close date
2009-12-31 14:52
Assigned to
mortenmacfly
Index: src/sdk/editormanager.cpp
===================================================================
--- src/sdk/editormanager.cpp    (revision 5986)
+++ src/sdk/editormanager.cpp    (working copy)
@@ -365,8 +365,11 @@
 
 EditorBase* EditorManager::InternalGetEditorBase(int page)
 {
-    EditorBase* eb = static_cast<EditorBase*>(m_pNotebook->GetPage(page));
-    return eb;
+    if (page < m_pNotebook->GetPageCount())
+    {
+        return static_cast<EditorBase*>(m_pNotebook->GetPage(page));
+    }
+    return 0;
 }
 
 cbEditor* EditorManager::InternalGetBuiltinEditor(int page)
@@ -518,7 +521,11 @@
 
 EditorBase* EditorManager::GetActiveEditor()
 {
-    return InternalGetEditorBase(m_pNotebook->GetSelection());
+    if (m_pNotebook->GetPageCount() > 0)
+    {
+        return InternalGetEditorBase(m_pNotebook->GetSelection());
+    }
+    return 0;
 }
 
 void EditorManager::ActivateNext()
techy 2009-12-27 17:26

When no editor is opened and GetActiveEditor() is called, it asks for page 0 that doesn't exist. This patch adds some code that protects GetSelection() and GetPage() from being called when the number of pages is 0.