<div dir="ltr"><div>Checking for negative return value of snprintf is wrong, but snprintf can actually "fail". It can truncate the output. However, since sizeof name is 256 and the length of "XWAYLAND%d" is always shorter that this, it is safe here.<br><br></div>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 Tue, May 12, 2015 at 7:21 PM, Dima Ryazanov <span dir="ltr"><<a href="mailto:dima@gmail.com" target="_blank">dima@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">snprintf does not allocate memory, so we can never get an out-of-memory error.<br>
<br>
(Also, the error handler would free xwl_output after it was already registered<br>
as an event listener.)<br>
<br>
Signed-off-by: Dima Ryazanov <<a href="mailto:dima@gmail.com">dima@gmail.com</a>><br>
---<br>
hw/xwayland/xwayland-output.c | 6 +-----<br>
1 file changed, 1 insertion(+), 5 deletions(-)<br>
<br>
diff --git a/hw/xwayland/xwayland-output.c b/hw/xwayland/xwayland-output.c<br>
index 1d75d0b..4949363 100644<br>
--- a/hw/xwayland/xwayland-output.c<br>
+++ b/hw/xwayland/xwayland-output.c<br>
@@ -167,11 +167,7 @@ xwl_output_create(struct xwl_screen *xwl_screen, uint32_t id)<br>
&wl_output_interface, 2);<br>
wl_output_add_listener(xwl_output->output, &output_listener, xwl_output);<br>
<br>
- if (snprintf(name, sizeof name, "XWAYLAND%d", serial++) < 0) {<br>
- ErrorF("create_output ENOMEM\n");<br>
- free(xwl_output);<br>
- return NULL;<br>
- }<br>
+ snprintf(name, sizeof name, "XWAYLAND%d", serial++);<br>
<br>
xwl_output->xwl_screen = xwl_screen;<br>
xwl_output->randr_crtc = RRCrtcCreate(xwl_screen->screen, xwl_output);<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.4.0<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" target="_blank">http://lists.freedesktop.org/mailman/listinfo/wayland-devel</a><br>
</font></span></blockquote></div><br></div>