On Tue, Jul 29, 2025 at 4:12 AM Dmitry Frolov wrote:
>
> malloc() return value is used without a check.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Signed-off-by: Dmitry Frolov
> ---
> target/xtensa/translate.c | 9 ++---
> 1 file changed, 2 insertions(+), 7 deletions(-)
>
> diff --git a/target/xtensa/translate.c b/target/xtensa/translate.c
> index 34ae2f4e16..42ef8d3eb9 100644
> --- a/target/xtensa/translate.c
> +++ b/target/xtensa/translate.c
> @@ -112,13 +112,8 @@ 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 {
I believe that
*pname = strdup(name);
in the `else` clause should also be changed to
*pname = g_strdup(name);
to maintain coupling between allocation and deallocation functions.
--
Thanks.
-- Max