Re: [libvirt] [PATCH] Convert one use of strncpy + strcat to snprintf in test driver.

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

 



On Fri, Aug 07, 2009 at 11:06:26AM +0200, Chris Lalancette wrote:
> Signed-off-by: Chris Lalancette <clalance@xxxxxxxxxx>
> ---
>  src/test.c |    5 ++---
>  1 files changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/src/test.c b/src/test.c
> index 470816b..ab6cfdf 100644
> --- a/src/test.c
> +++ b/src/test.c
> @@ -417,9 +417,8 @@ static char *testBuildFilename(const char *relativeTo,
>          char *absFile;
>          if (VIR_ALLOC_N(absFile, baseLen + strlen(filename) + 1) < 0)
>              return NULL;
> -        strncpy(absFile, relativeTo, baseLen);
> -        absFile[baseLen] = '\0';
> -        strcat(absFile, filename);
> +        snprintf(absFile, baseLen + strlen(filename) + 1, "%s%s",
> +                 relativeTo, filename);
>          return absFile;
>      } else {
>          return strdup(filename);

Since you're returning an allocated buffer, kill the VIR_ALLOC_N too
and use virAsprintf.

Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

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