[dpdk-dev] [PATCH 0/3] Rework CTF event description storage

David Marchand david.marchand at redhat.com
Wed Oct 28 16:59:01 CET 2020


On Wed, Oct 28, 2020 at 4:17 PM David Marchand
<david.marchand at redhat.com> wrote:
> This fixes it:
> @@ -37,11 +37,12 @@ meta_copy(char **meta, int *offset, char *str, int rc)
>         if (rc < 0)
>                 return rc;
>
> -       ptr = realloc(ptr, count + rc);
> +       ptr = realloc(ptr, count + rc + 1);
>         if (ptr == NULL)
>                 goto free_str;
>
>         memcpy(RTE_PTR_ADD(ptr, count), str, rc);
> +       ptr[count + rc] = '\0';
>         count += rc;
>         free(str);
>

The other alternative is to prefer libc string formatting functions
rather than plain memory alloc + copy + manual null termination:
https://github.com/david-marchand/dpdk/commit/traces


-- 
David Marchand



More information about the dev mailing list