mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-21 10:50:24 +03:00
util: fix the VIR_STRDUP when src is NULL
When src is NULL, VIR_STRDUP will return 0 directly. This patch will set dest to NULL before VIR_STRDUP return. Example: [root@yds-pc libvirt]# virsh Welcome to virsh, the virtualization interactive terminal. Type: 'help' for help with commands 'quit' to quit virsh # connect error: Failed to connect to the hypervisor error: internal error Unable to parse URI �N�* Signed-off-by: yangdongsheng <yangds.fnst@cn.fujitsu.com> Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
c6f2523fb1
commit
2da3bc646e
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2012 Red Hat, Inc.
|
||||
* Copyright (C) 2012-2013 Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@ -540,6 +540,7 @@ virStrdup(char **dest,
|
||||
const char *funcname,
|
||||
size_t linenr)
|
||||
{
|
||||
*dest = NULL;
|
||||
if (!src)
|
||||
return 0;
|
||||
if (!(*dest = strdup(src))) {
|
||||
@ -583,6 +584,7 @@ virStrndup(char **dest,
|
||||
const char *funcname,
|
||||
size_t linenr)
|
||||
{
|
||||
*dest = NULL;
|
||||
if (!src)
|
||||
return 0;
|
||||
if (n < 0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user