[PATCH weston 03/21] compositor-wayland: use asprintf for output title

Pekka Paalanen ppaalanen at gmail.com
Fri Sep 22 14:31:11 UTC 2017


From: Pekka Paalanen <pekka.paalanen at collabora.co.uk>

Simplifies the code, and makes moving weston_output_init() into
wayland_output_create_common() a little easier.

Signed-off-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
---
 libweston/compositor-wayland.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/libweston/compositor-wayland.c b/libweston/compositor-wayland.c
index 625a352c..1fb1be6c 100644
--- a/libweston/compositor-wayland.c
+++ b/libweston/compositor-wayland.c
@@ -1245,7 +1245,7 @@ static struct wayland_output *
 wayland_output_create_common(const char *name)
 {
 	struct wayland_output *output;
-	size_t len;
+	char *title;
 
 	/* name can't be NULL. */
 	assert(name);
@@ -1256,21 +1256,16 @@ wayland_output_create_common(const char *name)
 		return NULL;
 	}
 
-	output->base.destroy = wayland_output_destroy;
-	output->base.disable = wayland_output_disable;
-	output->base.enable = wayland_output_enable;
-	output->base.name = strdup(name);
-
-	/* setup output name/title. */
-	len = strlen(WINDOW_TITLE " - ") + strlen(name) + 1;
-	output->title = zalloc(len);
-	if (!output->title) {
-		free(output->base.name);
+	if (asprintf(&title, "%s - %s", WINDOW_TITLE, name) < 0) {
 		free(output);
 		return NULL;
 	}
+	output->title = title;
 
-	snprintf(output->title, len, WINDOW_TITLE " - %s", name);
+	output->base.destroy = wayland_output_destroy;
+	output->base.disable = wayland_output_disable;
+	output->base.enable = wayland_output_enable;
+	output->base.name = strdup(name);
 
 	return output;
 }
-- 
2.13.5



More information about the wayland-devel mailing list