From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:51498) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UFsZP-0002n1-8Q for qemu-devel@nongnu.org; Wed, 13 Mar 2013 16:46:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UFsZL-000390-33 for qemu-devel@nongnu.org; Wed, 13 Mar 2013 16:46:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:16568) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UFsZK-00038f-R4 for qemu-devel@nongnu.org; Wed, 13 Mar 2013 16:46:39 -0400 Message-ID: <5140E5AA.3000904@redhat.com> Date: Wed, 13 Mar 2013 14:46:34 -0600 From: Eric Blake MIME-Version: 1.0 References: <1363144182-1016-1-git-send-email-jschopp@linux.vnet.ibm.com> <1363144182-1016-7-git-send-email-jschopp@linux.vnet.ibm.com> In-Reply-To: <1363144182-1016-7-git-send-email-jschopp@linux.vnet.ibm.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="----enig2JGGGHCFGDJGIIWIBOTFN" Subject: Re: [Qemu-devel] [PATCH 6/9] asn1_output-visitor.diff List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Joel Schopp Cc: Michael Tsirkin , qemu-devel@nongnu.org, Stefan Berger This is an OpenPGP/MIME signed message (RFC 4880 and 3156) ------enig2JGGGHCFGDJGIIWIBOTFN Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 03/12/2013 09:09 PM, Joel Schopp wrote: > Implement an output visitor for ASN.1 BER encoding. >=20 > Cc: Michael Tsirkin > Signed-off-by: Stefan Berger > Signed-off-by: Joel Schopp > --- > +++ b/include/qapi/ber-output-visitor.h > @@ -0,0 +1,28 @@ > +/* > + * BER Output Visitor header > + * > + * Copyright IBM, Corp. 2011 It's 2013. > +static unsigned int ber_encode_len(uint8_t *buffer, uint32_t buflen, > + uint64_t len, Error **errp) > +{ > + uint64_t mask =3D 0xFF00000000000000ULL; > + int shift =3D 64 - 8; > + int c =3D 0; > + > + if (len <=3D 0x7f && buflen >=3D 1) { > + buffer[0] =3D len; > + return 1; > + } > + > + while (mask && (mask & len) =3D=3D 0) { > + mask >>=3D 8; > + shift -=3D 8; > + } > + > + while (shift >=3D 0) { > + if (1 + c + 1 > buflen) { > + error_set(errp, QERR_BUFFER_OVERRUN); > + return 0; > + } > + buffer[1+c] =3D (len >> shift); Space around binary operators. > + > + if (maxnumbytes > 1) { > + exp_zeros =3D ((mask & val) =3D=3D 0) ? true : false; I'm not a fan of 'bool expr ? true : false', when just 'bool expr' will d= o. > + while (mask !=3D 0xFF) { > + if (exp_zeros) { > + if ((mask & val) !=3D 0) { > + break; > + } > + } else { > + if ((mask & val) !=3D mask) { > + break; > + } > + } > + shift -=3D 8; > + mask >>=3D 8; > + } > + } > + > + while (shift >=3D 0) { > + buf[2+c] =3D (val >> shift); Another case of spaces around binary operator (I didn't look closely, so you may want to scrub the entire patch for more instances than what I saw on a casual quick read) --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org ------enig2JGGGHCFGDJGIIWIBOTFN 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.4.13 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJRQOWqAAoJEKeha0olJ0NqvX0H/3iafIILNx4OUYnOxttWqqMW FgssU1jr+e6HhV9F7BwzBiwR2i72bQU36mfzcYMZCLAPIsdwuMeiFvqFT57GWfk8 cdlO+dwxb1wn0DVjauKwl6Ax1UikTIxJCnytqTpDUcnxpMuYaaHuPpqPZ8S+r0AS CszQkMXU7VXWxuf+42/2sx78dr/jRJJim/lFbVlFpNUKNN673pzVGV14m/nLufBY fG++kbWzfdUM3c8tWndQbJ5oiSIt5LzmpCvUVed8iSYpFzyVkPttRcvOIK0yE8Ka ypkSnS2Wcg/ZkBxoEzFoPBgiZk6EdiGrCI75O2ce7sjoPbTt7kDAPLaozO2obuE= =1Lmy -----END PGP SIGNATURE----- ------enig2JGGGHCFGDJGIIWIBOTFN--