improved error handling in RegRenameKey
authorThomas Bluemel <thomas@reactsoft.com>
Thu, 20 Oct 2005 18:17:06 +0000 (18:17 +0000)
committerThomas Bluemel <thomas@reactsoft.com>
Thu, 20 Oct 2005 18:17:06 +0000 (18:17 +0000)
svn path=/trunk/; revision=18642

reactos/subsys/system/regedit/regproc.c

index d3a8f62..c0a19e9 100644 (file)
@@ -1622,23 +1622,27 @@ LONG RegRenameKey(HKEY hKey, LPCTSTR lpSubKey, LPCTSTR lpNewName)
     LPTSTR lpNewSubKey = NULL;
        LONG Ret = 0;
 
     LPTSTR lpNewSubKey = NULL;
        LONG Ret = 0;
 
-    s = _tcsrchr(lpSubKey, '\\');
+    s = _tcsrchr(lpSubKey, _T('\\'));
     if (s)
     {
         s++;
         lpNewSubKey = (LPTSTR) HeapAlloc(GetProcessHeap(), 0, (s - lpSubKey + _tcslen(lpNewName) + 1) * sizeof(TCHAR));
     if (s)
     {
         s++;
         lpNewSubKey = (LPTSTR) HeapAlloc(GetProcessHeap(), 0, (s - lpSubKey + _tcslen(lpNewName) + 1) * sizeof(TCHAR));
-        if (lpNewName != NULL) {
-                       memcpy(lpNewSubKey, lpSubKey, (s - lpSubKey) * sizeof(TCHAR));
-                       _tcscpy(lpNewSubKey + (s - lpSubKey), lpNewName);
-                       lpNewName = lpNewSubKey;                
-               }
+        if (lpNewSubKey != NULL)
+        {
+            memcpy(lpNewSubKey, lpSubKey, (s - lpSubKey) * sizeof(TCHAR));
+            _tcscpy(lpNewSubKey + (s - lpSubKey), lpNewName);
+            lpNewName = lpNewSubKey;
+        }
+        else
+            return ERROR_NOT_ENOUGH_MEMORY;
+    }
+    
+    Ret = RegMoveKey(hKey, lpNewName, hKey, lpSubKey);
+
+    if (lpNewSubKey)
+    {
+        HeapFree(GetProcessHeap(), 0, lpNewSubKey);
     }
     }
-       if (lpNewName != NULL) {
-               Ret = RegMoveKey(hKey, lpNewName, hKey, lpSubKey);
-               if (s) {
-                       HeapFree(GetProcessHeap(), 0, lpNewSubKey);
-               }
-       }
     return Ret;
 }
 
     return Ret;
 }