From: Dmitry Frolov Date: Wed, 30 Jul 2025 06:21:43 +0000 (+0300) Subject: target/xtensa: Replace malloc() with g_strdup_printf() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6e577c8906467f7b6e13635bb2fcb4289e5e264e;p=thirdparty%2Fqemu.git target/xtensa: Replace malloc() with g_strdup_printf() malloc() return value is used without a check. Found by Linux Verification Center (linuxtesting.org) with SVACE. Signed-off-by: Dmitry Frolov Reviewed-by: Max Filippov Message-ID: <20250730062142.1665980-1-frolov@swemel.ru> Signed-off-by: Thomas Huth --- diff --git a/target/xtensa/translate.c b/target/xtensa/translate.c index 6f9dd9fb5cf..175fd4b5cfc 100644 --- a/target/xtensa/translate.c +++ b/target/xtensa/translate.c @@ -112,17 +112,12 @@ void xtensa_collect_sr_names(const XtensaConfig *config) if (*pname) { if (strstr(*pname, name) == NULL) { - char *new_name = - malloc(strlen(*pname) + strlen(name) + 2); - - strcpy(new_name, *pname); - strcat(new_name, "/"); - strcat(new_name, name); - free(*pname); + char *new_name = g_strdup_printf("%s/%s", *pname, name); + g_free(*pname); *pname = new_name; } } else { - *pname = strdup(name); + *pname = g_strdup(name); } } }