[PATCH] clients/terminal: check for asprintf error condition instead

U. Artie Eoff ullysses.a.eoff at intel.com
Thu May 15 13:36:12 PDT 2014


asprintf returns -1 if memory allocation fails and that's what
we're really protecting here. So check for -1 instead of > 0
result.

In general, when asprintf returns 0, then the memory allocation
succeeded, but no bytes printed.  If we only free the allocated
memory when the result is > 0, then we miss the 0 condition and
leak.  asprintf docs don't say much about whether a 0 result
can occur when the string passed in is clearly not empty... but
better safe than sorry.

Signed-off-by: U. Artie Eoff <ullysses.a.eoff at intel.com>
---
 clients/terminal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clients/terminal.c b/clients/terminal.c
index cc603e9..a2253c1 100644
--- a/clients/terminal.c
+++ b/clients/terminal.c
@@ -838,7 +838,7 @@ update_title(struct terminal *terminal)
 {
 	if (window_is_resizing(terminal->window)) {
 		char *p;
-		if (asprintf(&p, "%s — [%dx%d]", terminal->title, terminal->width, terminal->height) > 0) {
+		if (asprintf(&p, "%s — [%dx%d]", terminal->title, terminal->width, terminal->height) != -1) {
 			window_set_title(terminal->window, p);
 			free(p);
 		}
-- 
1.9.0



More information about the wayland-devel mailing list