Re: [PATCH 2/2] Adapt to new VIR_STRNDUP behavior

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

 



On 24.05.2013 11:53, Michal Privoznik wrote:
> With previous patch, we accept negative value as length of string to
> duplicate. So there is no need to pass strlen(src) in case we want to do
> duplicate the whole string.
> ---
>  src/conf/domain_conf.c  |  6 ++----
>  src/qemu/qemu_command.c | 14 ++++++--------
>  src/util/virsexpr.c     |  2 +-
>  src/xenxs/xen_sxpr.c    |  4 ++--
>  4 files changed, 11 insertions(+), 15 deletions(-)
> 

> diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
> index 434f5a7..0373626 100644
> --- a/src/qemu/qemu_command.c
> +++ b/src/qemu/qemu_command.c
> @@ -8674,7 +8674,7 @@ static int qemuStringToArgvEnv(const char *args,
>          if (!next)
>              next = strchr(curr, '\n');
>  
> -        if (VIR_STRNDUP(arg, curr, next ? next - curr : strlen(curr)) < 0)
> +        if (VIR_STRNDUP(arg, curr, next ? next - curr : -1) < 0)

Or we can even go with 'VIR_STRNDUP(arg, curr, next - curr) < 0' but
that's not so easy to read. The rationale behind is: I intentionally
made VIR_STRNDUP to accept *any* negative value, not just -1. Because if
strrchr(cur, '\n') just a few lines above fails, next is just NULL.
Deducting from NULL will get a negative value. Which will make
VIR_STRNDUP duplicate the while string. But I worry that it would be an
ugly code, wouldn't it?

Michal

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[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]