qemu-trivial.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@gmail.com>
To: Alberto Garcia <agarcia@igalia.com>
Cc: qemu-trivial@nongnu.org, Orit Wasserman <owasserm@redhat.com>
Subject: Re: [Qemu-trivial] [PATCH] savevm: fix compiler warning
Date: Wed, 15 Aug 2012 14:30:02 +0100	[thread overview]
Message-ID: <20120815133002.GA10742@stefanha-thinkpad.localdomain> (raw)
In-Reply-To: <1344975512-15542-1-git-send-email-agarcia@igalia.com>

On Tue, Aug 14, 2012 at 11:18:32PM +0300, Alberto Garcia wrote:
> If we have a 32-bit long then the truncation of a 64-bit value will
> produce a compiler warning unless we make an explicit cast.
> ---
>  savevm.c |    2 +-
>  1 ficheiro modificado, 1 adição(+), 1 eliminado(-)
> 
> diff --git a/savevm.c b/savevm.c
> index 0ea10c9..c89fc4e 100644
> --- a/savevm.c
> +++ b/savevm.c
> @@ -2473,7 +2473,7 @@ int xbzrle_encode_buffer(uint8_t *old_buf, uint8_t *new_buf, int slen,
>          /* word at a time for speed, use of 32-bit long okay */
>          if (!res) {
>              /* truncation to 32-bit long okay */
> -            long mask = 0x0101010101010101ULL;
> +            long mask = (long) 0x0101010101010101ULL;

C99 6.3.1.3 Signed and unsigned integers, paragraph 3:

"Otherwise, the new type is signed and the value cannot be represented
in it; either the result is implementation-defined or an
implementation-defined signal is raised."

The safe way of doing this is by casting to (unsigned long) instead:

"Otherwise, if the new type is unsigned, the value is converted by
repeatedly adding or subtracting one more than the maximum value that
can be represented in the new type until the value is in the range of
the new type."

Stefan


      reply	other threads:[~2012-08-15 13:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-14 20:18 [Qemu-trivial] [PATCH] savevm: fix compiler warning Alberto Garcia
2012-08-15 13:30 ` Stefan Hajnoczi [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120815133002.GA10742@stefanha-thinkpad.localdomain \
    --to=stefanha@gmail.com \
    --cc=agarcia@igalia.com \
    --cc=owasserm@redhat.com \
    --cc=qemu-trivial@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).