tests: Add an xmalloc helper function
authorBryce Harrington <bryce@osg.samsung.com>
Thu, 23 Apr 2015 01:23:01 +0000 (18:23 -0700)
committerBryce Harrington <bryce@osg.samsung.com>
Thu, 21 May 2015 22:05:28 +0000 (15:05 -0700)
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-By: Derek Foreman <derekf@osg.samsung.com>
tests/weston-test-client-helper.c
tests/weston-test-client-helper.h

index 00fdf8f93d097bc5989396efa3bf4cd753d2d693..080bb629bf3113317c2a665ca9676f006610b6ec 100644 (file)
 #include "../shared/os-compatibility.h"
 #include "weston-test-client-helper.h"
 
+void *
+fail_on_null(void *p)
+{
+       if (p == NULL) {
+               fprintf(stderr, "out of memory\n");
+               exit(EXIT_FAILURE);
+       }
+       return p;
+}
+
+
 int
 surface_contains(struct surface *surface, int x, int y)
 {
index b46f158a7629abe97f83293b2bed5cb1553c9ce4..43a5aa706e2b052b5c93155b33ee4fce758ac1c4 100644 (file)
@@ -132,15 +132,19 @@ struct surface {
        void *data;
 };
 
+void *
+fail_on_null(void *p);
+
 static inline void *
-xzalloc(size_t size)
+xzalloc(size_t s)
 {
-        void *p;
-
-        p = calloc(1, size);
-        assert(p);
+       return fail_on_null(calloc(1, s));
+}
 
-        return p;
+static inline void *
+xmalloc(size_t s)
+{
+       return fail_on_null(malloc(s));
 }
 
 struct client *