Re: [PATCH 1/4] Fix const correctness

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

 



On 07/15/2014 06:38 AM, Michal Privoznik wrote:
> In many places we define a variable as a 'const char *' when in fact
> we modify it just a few lines below. Or even free it. We should not do
> that.
> 
> There's one exception though, in xenSessionFree() xenapi_utils.c. We
> are freeing the xen_session structure which is defined in
> xen/api/xen_common.h public header. The structure contains session_id
> which is type of 'const char *' when in fact it should have been just
> 'char *'. So I'm leaving this unmodified, just noticing the fact in
> comment.
> 
> Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
> ---
>  src/locking/lock_driver_lockd.c      | 2 +-
>  src/qemu/qemu_capabilities.c         | 2 +-
>  src/remote/remote_driver.c           | 2 +-
>  src/xenapi/xenapi_utils.c            | 1 +
>  tools/virsh-domain.c                 | 4 ++--
>  tools/wireshark/src/packet-libvirt.c | 6 +++---
>  tools/wireshark/src/packet-libvirt.h | 4 ++--
>  7 files changed, 11 insertions(+), 10 deletions(-)
> 

ACK; safe to apply this one even while waiting for me to propose a v2
for the rest of the series.

> +++ b/src/xenapi/xenapi_utils.c
> @@ -49,6 +49,7 @@ xenSessionFree(xen_session *session)
>              VIR_FREE(session->error_description[i]);
>          VIR_FREE(session->error_description);
>      }
> +    /* The session_id member is type of 'const char *'. Sigh. */
>      VIR_FREE(session->session_id);
>      VIR_FREE(session);

By the way, once VIR_FREE is fixed, we can work around this instance by
use of a temporary variable:

/* cast away bogus const from xen header */
char *tmp = (char *)session->session_id;
VIR_FREE(tmp);
VIR_FREE(session);

> +++ b/tools/wireshark/src/packet-libvirt.c
> @@ -105,7 +105,7 @@ dissect_xdr_string(tvbuff_t *tvb, proto_tree *tree, XDR *xdrs, int hf,
>      }
>  }
>  
> -static gchar *
> +static const gchar *

Side note - gchar is a pointless type.  But not our fault that wireshark
is using it instead of plain char.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

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