Re: [PATCH v2 1/4] util: Introduce virStringListRemoveDuplicates

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Oct 23, 2024 at 16:54:50 +0200, Jiri Denemark wrote:
> Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx>
> ---
> 
> Notes:
>     Version 2:
>     - new patch
> 
>  src/libvirt_private.syms |  1 +
>  src/util/virstring.c     | 29 +++++++++++++++++++++++++++++
>  src/util/virstring.h     |  2 ++
>  3 files changed, 32 insertions(+)
> 
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index c1542847f4..89cd20eece 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -3438,6 +3438,7 @@ virStringHasControlChars;
>  virStringHasSuffix;
>  virStringIsEmpty;
>  virStringIsPrintable;
> +virStringListRemoveDuplicates;
>  virStringMatch;
>  virStringMatchesNameSuffix;
>  virStringParsePort;
> diff --git a/src/util/virstring.c b/src/util/virstring.c
> index 81c9aff304..bc9b6cd40e 100644
> --- a/src/util/virstring.c
> +++ b/src/util/virstring.c
> @@ -1065,3 +1065,32 @@ virStringParseVersion(unsigned long long *version,
>  
>      return 0;
>  }
> +
> +
> +/**
> + * virStringListRemoveDuplicates:
> + * @list: pointer to a sorted NULL-terminated string list
> + *
> + * Replace the list pointed to by @list with a new list without duplicate
> + * strings. The original list has to be sorted.
> + */
> +void
> +virStringListRemoveDuplicates(char ***list)
> +{
> +    size_t len = g_strv_length(*list);
> +    char **unique;
> +    size_t n = 0;
> +    size_t i;
> +
> +    unique = g_malloc0_n(len + 1, sizeof(char *));

Please use g_new0(char *, len + 1) instead.



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux