https://git.reactos.org/?p=reactos.git;a=commitdiff;h=7f45cac9ab975402cc98d491c8ac0c67733f0a3b
commit 7f45cac9ab975402cc98d491c8ac0c67733f0a3b
Author:     Jose Carlos Jesus <zecarlos1...@hotmail.com>
AuthorDate: Thu May 18 06:16:49 2023 -0400
Commit:     GitHub <nore...@github.com>
CommitDate: Thu May 18 19:16:49 2023 +0900

    [REGEDIT] Creating a new Key should add a new entry even when no child 
exist. CORE-18878 (#5274)
    
    - Avoid using a NULL pointer when My Computer is selected, by disabling the 
New Key menu item.
    - Simplifies and fix code style in GetItemPath function.
    - Add a new entry even when no child items exist.
    CORE-18878
---
 base/applications/regedit/treeview.c | 30 +++++++++++++++++++++---------
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/base/applications/regedit/treeview.c 
b/base/applications/regedit/treeview.c
index 9c957cfe2ad..958aae6cdc7 100644
--- a/base/applications/regedit/treeview.c
+++ b/base/applications/regedit/treeview.c
@@ -90,14 +90,25 @@ LPCWSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY* 
phRootKey)
     int pathLen = 0, maxLen;
 
     *phRootKey = NULL;
-    if (!pathBuffer) pathBuffer = HeapAlloc(GetProcessHeap(), 0, 1024);
-    if (!pathBuffer) return NULL;
-    *pathBuffer = 0;
+
+    if (!pathBuffer)
+    {
+        pathBuffer = HeapAlloc(GetProcessHeap(), 0, 1024);
+    }
+    if (!pathBuffer)
+    {
+        return NULL;
+    }
+
+    *pathBuffer = UNICODE_NULL;
+
     maxLen = (int) HeapSize(GetProcessHeap(), 0, pathBuffer);
-    if (maxLen == -1) return NULL;
-    if (!hItem) hItem = TreeView_GetSelection(hwndTV);
-    if (!hItem) return NULL;
-    if (!get_item_path(hwndTV, hItem, phRootKey, &pathBuffer, &pathLen, 
&maxLen))
+
+    if (!hItem)
+    {
+        hItem = TreeView_GetSelection(hwndTV);
+    }
+    if (maxLen == -1 || !hItem || !get_item_path(hwndTV, hItem, phRootKey, 
&pathBuffer, &pathLen, &maxLen))
     {
         return NULL;
     }
@@ -353,7 +364,7 @@ HTREEITEM InsertNode(HWND hwndTV, HTREEITEM hItem, LPWSTR 
name)
     if (!TreeView_GetItem(hwndTV, &item))
         return FALSE;
 
-    if ((item.state & TVIS_EXPANDEDONCE) && (item.cChildren > 0))
+    if (item.state & TVIS_EXPANDEDONCE)
     {
         hNewItem = AddEntryToTree(hwndTV, hItem, name, 0, 0);
         SendMessageW(hwndTV, TVM_SORTCHILDREN, 0, (LPARAM) hItem);
@@ -645,8 +656,9 @@ BOOL TreeWndNotifyProc(HWND hWnd, WPARAM wParam, LPARAM 
lParam, BOOL *Result)
 
             UpdateAddress(pnmtv->itemNew.hItem, NULL, NULL, TRUE);
 
-            /* Disable the Permissions menu item for 'My Computer' */
+            /* Disable the Permissions and new key menu items for 'My 
Computer' */
             EnableMenuItem(hMenuFrame, ID_EDIT_PERMISSIONS, MF_BYCOMMAND | 
(hParentItem ? MF_ENABLED : MF_GRAYED));
+            EnableMenuItem(hMenuFrame, ID_EDIT_NEW_KEY, MF_BYCOMMAND | 
(hParentItem ? MF_ENABLED : MF_GRAYED));
 
             /*
              * Disable Delete/Rename menu options for 'My Computer' (first 
item so doesn't have any parent)

Reply via email to