<div dir="ltr">Reviewed-by: Marek Chalupa <<a href="mailto:mchqwerty@gmail.com">mchqwerty@gmail.com</a>><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Jun 20, 2015 at 1:12 AM, Bryce Harrington <span dir="ltr"><<a href="mailto:bryce@osg.samsung.com" target="_blank">bryce@osg.samsung.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">It is redundant to check x*alloc's return value for null pointers, since<br>
they are guaranteed to either return non-NULL or terminate the program.<br>
<br>
In cases where we memset the malloc'd memory to 0, we can more<br>
efficiently use the xzalloc() routine. zalloc looks for opportunities<br>
to return memory chunks that have already been zero'd out, so it can<br>
provide better performance.<br>
<br>
This patch addresses this warning, reported by Denis Denisov:<br>
<br>
[clients/window.c:1164] -> [clients/window.c:1166]: (warning) Possible<br>
null pointer dereference: surface - otherwise it is redundant to check<br>
it against null.<br>
<br>
[clients/window.c:4513] -> [clients/window.c:4514]: (warning) Possible<br>
null pointer dereference: surface - otherwise it is redundant to check<br>
it against null.<br>
<br>
Signed-off-by: Bryce Harrington <<a href="mailto:bryce@osg.samsung.com">bryce@osg.samsung.com</a>><br>
---<br>
clients/window.c | 13 ++-----------<br>
1 file changed, 2 insertions(+), 11 deletions(-)<br>
<br>
diff --git a/clients/window.c b/clients/window.c<br>
index ff4be8c..8e43e18 100644<br>
--- a/clients/window.c<br>
+++ b/clients/window.c<br>
@@ -1162,12 +1162,7 @@ shm_surface_create(struct display *display, struct wl_surface *wl_surface,<br>
struct shm_surface *surface;<br>
DBG_OBJ(wl_surface, "\n");<br>
<br>
- surface = xmalloc(sizeof *surface);<br>
- memset(surface, 0, sizeof *surface);<br>
-<br>
- if (!surface)<br>
- return NULL;<br>
-<br>
+ surface = xzalloc(sizeof *surface);<br>
surface->base.prepare = shm_surface_prepare;<br>
surface->base.swap = shm_surface_swap;<br>
surface->base.acquire = shm_surface_acquire;<br>
@@ -4511,11 +4506,7 @@ surface_create(struct window *window)<br>
struct display *display = window->display;<br>
struct surface *surface;<br>
<br>
- surface = xmalloc(sizeof *surface);<br>
- memset(surface, 0, sizeof *surface);<br>
- if (!surface)<br>
- return NULL;<br>
-<br>
+ surface = xzalloc(sizeof *surface);<br>
surface->window = window;<br>
surface->surface = wl_compositor_create_surface(display->compositor);<br>
surface->buffer_scale = 1;<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.9.1<br>
<br>
_______________________________________________<br>
wayland-devel mailing list<br>
<a href="mailto:wayland-devel@lists.freedesktop.org">wayland-devel@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/wayland-devel" rel="noreferrer" target="_blank">http://lists.freedesktop.org/mailman/listinfo/wayland-devel</a><br>
</font></span></blockquote></div><br></div>