[2/5] ntdll: Handle error if RtlAllocateHeap fails in printf functions

Sebastian Lackner sebastian at fds-team.de
Fri Dec 20 00:46:06 CST 2013


---
 dlls/ntdll/printf.c |   14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

-------------- next part --------------
From 74df9b1c09f2e826f3bfa969dbd998a311c93f5b Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian at fds-team.de>
Date: Fri, 20 Dec 2013 05:55:34 +0100
Subject: ntdll: Handle error if RtlAllocateHeap fails in printf functions


---
 dlls/ntdll/printf.c |   14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/dlls/ntdll/printf.c b/dlls/ntdll/printf.c
index 49d3983..3a5067a 100644
--- a/dlls/ntdll/printf.c
+++ b/dlls/ntdll/printf.c
@@ -300,7 +300,13 @@ static void pf_integer_conv( char *buf, int buf_len, pf_flags *flags,
     char number[40], *tmp = number;
 
     if( buf_len > sizeof number )
-        tmp = RtlAllocateHeap( GetProcessHeap(), 0, buf_len );
+    {
+        if (!(tmp = RtlAllocateHeap( GetProcessHeap(), 0, buf_len )))
+        {
+            buf[0] = '\0';
+            return;
+        }
+    }
 
     base = 10;
     if( flags->Format == 'o' )
@@ -588,7 +594,8 @@ static int pf_vsnprintf( pf_output *out, const WCHAR *format, __ms_va_list valis
                         flags.FieldLength : flags.Precision) + 10;
 
             if( x_len >= sizeof number)
-                x = RtlAllocateHeap( GetProcessHeap(), 0, x_len );
+                if (!(x = RtlAllocateHeap( GetProcessHeap(), 0, x_len )))
+                    return -1;
 
             pf_integer_conv( x, x_len, &flags, va_arg(valist, LONGLONG) );
 
@@ -611,7 +618,8 @@ static int pf_vsnprintf( pf_output *out, const WCHAR *format, __ms_va_list valis
                         flags.FieldLength : flags.Precision) + 10;
 
             if( x_len >= sizeof number)
-                x = RtlAllocateHeap( GetProcessHeap(), 0, x_len );
+                if (!(x = RtlAllocateHeap( GetProcessHeap(), 0, x_len )))
+                    return -1;
 
             pf_rebuild_format_string( fmt, &flags );
 
-- 
1.7.9.5



More information about the wine-patches mailing list