[PATCH] mshtml: check for NULL return from allocations

Marcus Meissner marcus at jet.franken.de
Tue Dec 1 16:28:50 CST 2009


Hi,

Coverity thinks we miss NULL checks and yes, we do.
Added some.

Ciao, Marcus
---
 dlls/mshtml/txtrange.c |   25 ++++++++++++++-----------
 1 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/dlls/mshtml/txtrange.c b/dlls/mshtml/txtrange.c
index c068c06..2ca9705 100644
--- a/dlls/mshtml/txtrange.c
+++ b/dlls/mshtml/txtrange.c
@@ -177,12 +177,14 @@ static BOOL is_space_elem(nsIDOMNode *node)
     return ret;
 }
 
-static inline void wstrbuf_init(wstrbuf_t *buf)
+static inline BOOL wstrbuf_init(wstrbuf_t *buf)
 {
     buf->len = 0;
     buf->size = 16;
     buf->buf = heap_alloc(buf->size * sizeof(WCHAR));
+    if (!buf->buf) return FALSE;
     *buf->buf = 0;
+    return TRUE;
 }
 
 static inline void wstrbuf_finish(wstrbuf_t *buf)
@@ -549,15 +551,14 @@ HRESULT get_node_text(HTMLDOMNode *node, BSTR *ret)
     wstrbuf_t buf;
     HRESULT hres = S_OK;
 
-    wstrbuf_init(&buf);
-    wstrbuf_append_node_rec(&buf, node->nsnode);
-    if(buf.buf) {
-        *ret = SysAllocString(buf.buf);
-        if(!*ret)
-            hres = E_OUTOFMEMORY;
-    }else {
+    if (!wstrbuf_init(&buf)) {
         *ret = NULL;
+        return E_OUTOFMEMORY;
     }
+    wstrbuf_append_node_rec(&buf, node->nsnode);
+    *ret = SysAllocString(buf.buf);
+    if(!*ret)
+        hres = E_OUTOFMEMORY;
     wstrbuf_finish(&buf);
 
     if(SUCCEEDED(hres))
@@ -1171,13 +1172,15 @@ static HRESULT WINAPI HTMLTxtRange_get_text(IHTMLTxtRange *iface, BSTR *p)
     if(!This->nsrange)
         return S_OK;
 
-    wstrbuf_init(&buf);
+    if (!wstrbuf_init(&buf))
+        return E_OUTOFMEMORY;
     range_to_string(This, &buf);
-    if(buf.buf)
-        *p = SysAllocString(buf.buf);
+    *p = SysAllocString(buf.buf);
     wstrbuf_finish(&buf);
 
     TRACE("ret %s\n", debugstr_w(*p));
+    if (!*p)
+        return E_OUTOFMEMORY;
     return S_OK;
 }
 
-- 
1.5.6



More information about the wine-patches mailing list