From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37679) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YXsd8-0006gw-Sd for qemu-devel@nongnu.org; Tue, 17 Mar 2015 10:38:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YXsd5-0001Y4-0Q for qemu-devel@nongnu.org; Tue, 17 Mar 2015 10:38:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47465) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YXsd4-0001Xh-S7 for qemu-devel@nongnu.org; Tue, 17 Mar 2015 10:37:58 -0400 Message-ID: <55083C44.2010805@redhat.com> Date: Tue, 17 Mar 2015 08:37:56 -0600 From: Eric Blake MIME-Version: 1.0 References: <1426593410-21405-1-git-send-email-stefanha@redhat.com> <1426593410-21405-2-git-send-email-stefanha@redhat.com> In-Reply-To: <1426593410-21405-2-git-send-email-stefanha@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="mbUDq9MAHG8Q0C5mvosa3pNkndb5rG1lQ" Subject: Re: [Qemu-devel] [PATCH 1/7] bt-sdp: fix broken uuids power-of-2 calculation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi , qemu-devel@nongnu.org Cc: Peter Maydell , Andrzej Zaborowski , Markus Armbruster This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --mbUDq9MAHG8Q0C5mvosa3pNkndb5rG1lQ Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 03/17/2015 05:56 AM, Stefan Hajnoczi wrote: > The binary search in sdp_uuid_match() only works when the number of > elements to search is a power of two. >=20 > lo =3D record->uuid; > hi =3D record->uuids; > while (hi >>=3D 1) > if (lo[hi] <=3D val) > lo +=3D hi; >=20 > return *lo =3D=3D val; >=20 > I noticed that the record->uuids calculation in > sdp_service_record_build() was suspect: >=20 > record->uuids =3D 1 << ffs(record->uuids - 1); >=20 > Unlike most ffs(val) - 1 users, the expression is ffs(val - 1)! Indeed, quite likely to be quite wrong. >=20 > Actually ffs() is the wrong function to use for power-of-2. Use > pow2ceil() to achieve the correct effect. Now the record->uuid[] array= > is sized correctly and the binary search in sdp_uuid_match() should > work. >=20 > I'm not sure how to run/test this code. Me neither. But I can still analyze the code for sanity. Counts as a bug fix, so I'd put this in 2.3, even if the rest of the series is deferred to 2.4 as being a style cleanup rather than bug fix. >=20 > Cc: Andrzej Zaborowski > Signed-off-by: Stefan Hajnoczi > --- > hw/bt/sdp.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) Reviewed-by: Eric Blake --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --mbUDq9MAHG8Q0C5mvosa3pNkndb5rG1lQ 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/ iQEcBAEBCAAGBQJVCDxEAAoJEKeha0olJ0Nq5fsIAJzMU150TQXNTslaPWikZmt5 ikvORNi1yrhAL7s9RmBkTKKqyGVSCxp3ZG/IJjYBuFvG+e6b8c5mUwsFkDvBzhNc Fwev8WR6c3bXeMOwbzvylxSTLjb1sWg2P2OjWo/JQVHyFznBSPKWj0XhaxxUWXfZ 3OdkbR4+ciD3ZlDmgi1L0VoOOasR4Wy8KQQTbTnOajZRny6bLD93pOexxh12cg3M VvONrVeTsyvwME0wKjmCjLGEyE/4yLjStxTJIriDUJghZMEQOKXth90oQ8H5Bg0i 3ilVghrbqC0q5G4znm49b7coVEcmt2vph9rw7mlfJtx8NM9+qz9/OBsrn64sZsM= =sZDi -----END PGP SIGNATURE----- --mbUDq9MAHG8Q0C5mvosa3pNkndb5rG1lQ--