cmd: Handle NULL params/failed allocations in WCMD_strdupW

Frédéric Delanoy frederic.delanoy at gmail.com
Sat Sep 17 09:50:36 CDT 2011


---
 programs/cmd/wcmdmain.c |   15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c
index 92b76fc..87061d8 100644
--- a/programs/cmd/wcmdmain.c
+++ b/programs/cmd/wcmdmain.c
@@ -441,11 +441,16 @@ static void WCMD_show_prompt (void) {
  * WCMD_strdupW
  *    A wide version of strdup as its missing from unicode.h
  */
-WCHAR *WCMD_strdupW(const WCHAR *input) {
-   int len=strlenW(input)+1;
-   WCHAR *result = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
-   memcpy(result, input, len * sizeof(WCHAR));
-   return result;
+WCHAR *WCMD_strdupW(const WCHAR *input)
+{
+    unsigned int len;
+    WCHAR *result;
+    if (!input) return NULL;
+    len = strlenW(input) + 1;
+    result = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
+    if (result)
+        memcpy(result, input, len * sizeof(WCHAR));
+    return result;
 }
 
 /*************************************************************************
-- 
1.7.6.3




More information about the wine-patches mailing list