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 <frolov@swemel.ru>
Reviewed-by: Max Filippov <jcmvbkbc@gmail.com>
Message-ID: <20250730062142.1665980-1-frolov@swemel.ru>
Signed-off-by: Thomas Huth <thuth@redhat.com>
This commit is contained in:
Dmitry Frolov
2025-07-30 09:21:43 +03:00
committed by Thomas Huth
parent 0f25e8a5e6
commit 6e577c8906

View File

@@ -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);
}
}
}