@samitouri / QOSamiQemu / commits / 6e577c8906

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>

Dmitry Frolov committed Jul 30, 2025 at 09:21 UTC 6e577c8906467f7b6e13635bb2fcb4289e5e264e
1 file changed +3 -8
target/xtensa/translate.c
+3 -8
@@ -112,17 +112,12 @@ void xtensa_collect_sr_names(const XtensaConfig *config)
112
113 if (*pname) {
114 if (strstr(*pname, name) == NULL) {
115 - char *new_name =
116 - malloc(strlen(*pname) + strlen(name) + 2);
117 -
118 - strcpy(new_name, *pname);
119 - strcat(new_name, "/");
120 - strcat(new_name, name);
121 - free(*pname);
115 + char *new_name = g_strdup_printf("%s/%s", *pname, name);
116 + g_free(*pname);
117 *pname = new_name;
118 }
119 } else {
125 - *pname = strdup(name);
120 + *pname = g_strdup(name);
121 }
122 }
123 }