From 1f21ef1df77fc105502cdad3b72f14bbf6ef4b9d Mon Sep 17 00:00:00 2001 From: Pekka Paalanen Date: Mon, 3 Apr 2017 13:33:26 +0300 Subject: [PATCH] compositor-drm: use asprintf in make_connector_name() Gets rid of the constant size char array. While here, document the function. Signed-off-by: Pekka Paalanen Reviewed-by: Ian Ray --- 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 1a96138..578ff9d 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.7.4