From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42686) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WTJSX-000259-0x for qemu-devel@nongnu.org; Thu, 27 Mar 2014 19:11:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WTJSS-0000bA-4N for qemu-devel@nongnu.org; Thu, 27 Mar 2014 19:11:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37967) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WTJSR-0000ak-T8 for qemu-devel@nongnu.org; Thu, 27 Mar 2014 19:11:36 -0400 Message-ID: <5334B023.5060602@redhat.com> Date: Thu, 27 Mar 2014 17:11:31 -0600 From: Eric Blake MIME-Version: 1.0 References: <1395907390-18812-1-git-send-email-wenchaoqemu@gmail.com> <1395907390-18812-3-git-send-email-wenchaoqemu@gmail.com> In-Reply-To: <1395907390-18812-3-git-send-email-wenchaoqemu@gmail.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="fNSP1tR60ckLdbpg8TL16d4jqw84CAnrx" Subject: Re: [Qemu-devel] [RFC PATCH V4 2/5] qapi: add event helper functions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Wenchao Xia , qemu-devel@nongnu.org Cc: mdroth@linux.vnet.ibm.com, armbru@redhat.com, lcapitulino@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --fNSP1tR60ckLdbpg8TL16d4jqw84CAnrx Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 03/27/2014 02:03 AM, Wenchao Xia wrote: > This file holds some functions that do not need to be generated. >=20 > Signed-off-by: Wenchao Xia > --- > include/qapi/qmp-event.h | 27 +++++++++++++++++ > qapi/Makefile.objs | 1 + > qapi/qmp-event.c | 70 ++++++++++++++++++++++++++++++++++++++= ++++++++ > 3 files changed, 98 insertions(+), 0 deletions(-) > create mode 100644 include/qapi/qmp-event.h > create mode 100644 qapi/qmp-event.c >=20 > + err =3D qemu_gettimeofday(&tv); > + if (err < 0) { > + /* Put -1 to indicate failure of getting host time */ > + tv.tv_sec =3D -1; > + tv.tv_usec =3D -1; You fixed the problem with C promotion here, but... > + } > + > + obj =3D qobject_from_jsonf("{ 'seconds': %" PRId64 ", " > + "'microseconds': %" PRId64 " }", > + (int64_t) tv.tv_sec, (int64_t) tv.tv_usec= ); =2E..here, C promotion rules bite once again :( If tv_usec is uint32_t, then it zero-extends rather than sign-extends into int64_t, and you may end up with 0xffffffff instead of the intended -1. When doing potentially widening casts, it is only safe if you know the signedness of the pre-cast value; but with struct timeval, POSIX doesn't make that easy. Maybe it's easier to just rewrite things with known types: int64_t sec; int usec; qemu_timval tv; err =3D qemu_gettimeofday(&tv); if (err < 0) { sec =3D -1; usec =3D -1; } else { sec =3D tv.tv_sec; usec =3D tv.tv_usec; } qobject_from_jsonf("... %"PRId64 ", ...%d", sec, usec) since 'int' is guaranteed to be large enough for all the usec values we care about on all platforms we compile on (that is, we require 32-bit int, even if C allows for a 16-bit int implementation). --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --fNSP1tR60ckLdbpg8TL16d4jqw84CAnrx Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJTNLAjAAoJEKeha0olJ0Nq44AH/jR1ex7GxUPf1aMvdNDi7z3c EluPck761eDq8nyhN3qrlO/HPhMcc/Uz21N1rdyPsns7rn9IJCYZMb6G+iQgN4mE f7MWfy/XTq9LEq8ehup3LIUNxU+bIIB6UL5z26scY/BICGbHSJstQkbu54BimX0N aLk6AFImsDjwjkNE3yqrDjJYS3ChKwV/00gUQKIdxYdKf/nm0pSmj2Rjg+H21oUh 0pCcdPtc5jn3jYJxsOOm5rh02pwvhqvoW5WHeqX21RzuNmqKMRIy/wBI3/aDWaAz ON1qmhMk5csYhhkp609uyuhtxvTC9qmt1NeZ7oJQ44UC7JpN63hCs6k0UkfT36Y= =X/KR -----END PGP SIGNATURE----- --fNSP1tR60ckLdbpg8TL16d4jqw84CAnrx--