[libvirt] [PATCH 1/4] Fix const correctness

Eric Blake eblake at redhat.com
Tue Jul 15 19:26:23 UTC 2014


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 at redhat.com>
> ---
>  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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 604 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20140715/98fbac02/attachment-0001.sig>


More information about the libvir-list mailing list