[PATCH weston 02/21] compositor-drm: use asprintf in make_connector_name()

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


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

Gets rid of the constant size char array.

While here, document the function.

Signed-off-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
---
 libweston/compositor-drm.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/libweston/compositor-drm.c b/libweston/compositor-drm.c
index ea2c6991..885b5f0f 100644
--- a/libweston/compositor-drm.c
+++ b/libweston/compositor-drm.c
@@ -2508,11 +2508,20 @@ static const char * const connector_type_names[] = {
 #endif
 };
 
+/** Create a name given a DRM connector
+ *
+ * \param con The DRM connector whose type and id form the name.
+ * \return A newly allocate string, or NULL on error. Must be free()'d
+ * after use.
+ *
+ * The name does not identify the DRM display device.
+ */
 static char *
 make_connector_name(const drmModeConnector *con)
 {
-	char name[32];
+	char *name;
 	const char *type_name = NULL;
+	int ret;
 
 	if (con->connector_type < ARRAY_LENGTH(connector_type_names))
 		type_name = connector_type_names[con->connector_type];
@@ -2520,9 +2529,11 @@ make_connector_name(const drmModeConnector *con)
 	if (!type_name)
 		type_name = "UNNAMED";
 
-	snprintf(name, sizeof name, "%s-%d", type_name, con->connector_type_id);
+	ret = asprintf(&name, "%s-%d", type_name, con->connector_type_id);
+	if (ret < 0)
+		return NULL;
 
-	return strdup(name);
+	return name;
 }
 
 static int
-- 
2.13.5



More information about the wayland-devel mailing list