Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1NhNWa-00076D-Kj for mharc-grub-devel@gnu.org; Tue, 16 Feb 2010 08:31:36 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NhNWZ-00075k-GU for grub-devel@gnu.org; Tue, 16 Feb 2010 08:31:35 -0500 Received: from [140.186.70.92] (port=51398 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NhNWY-00075W-V7 for grub-devel@gnu.org; Tue, 16 Feb 2010 08:31:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NhNWV-0002fh-P9 for grub-devel@gnu.org; Tue, 16 Feb 2010 08:31:34 -0500 Received: from mail-fx0-f215.google.com ([209.85.220.215]:45578) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NhNWV-0002fN-4o for grub-devel@gnu.org; Tue, 16 Feb 2010 08:31:31 -0500 Received: by fxm7 with SMTP id 7so6306687fxm.8 for ; Tue, 16 Feb 2010 05:31:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=KSvwsCGxzQHtTbmiTGTRonoz81F+9dExW19i54T8aiU=; b=ZNSi8dqZmXHg6xeArbXu8+UQTWLvjreGMgr62z6daVk55pXuwRxidcGgkYAdOtNXA3 FNBRA7kwwndW66ACeboQYiqJAuy+emKbzKk8/5+FEEZQoazPE+hcaMJ8RVGnhYlYtCqR NY3D3ojja8AsEdeP2eY/tIcbcQhLgg8Rrh3Eo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=fPRHsVTHevT9/T/2YfMOt/IgbYhoHsAzSZHzPZlqdF/6TIXvHmTqLAuaVqK3vc5rjw vXixW/lAdddAMD3OgYYj+rQMZ5PQYmcxz4QS+y5wUg0GqkACp9vTf3wAxvK+3lSmgl+h Ebqh+e1HpgZ7gRanPupVIti0UP8UxBjIRg9m4= MIME-Version: 1.0 Received: by 10.239.149.8 with SMTP id h8mr696384hbb.10.1266327084777; Tue, 16 Feb 2010 05:31:24 -0800 (PST) In-Reply-To: <4B7A93BD.9010607@gmail.com> References: <20100214000510.GA10702@pina.cat> <4B7A93BD.9010607@gmail.com> Date: Tue, 16 Feb 2010 07:31:24 -0600 Message-ID: <2e59e6971002160531k43d67b71rc26d2a2f83c5da24@mail.gmail.com> From: "richardvoigt@gmail.com" To: The development of GNU GRUB Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: Re: avoid possible overflow? X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Feb 2010 13:31:35 -0000 2010/2/16 Vladimir '=CF=86-coder/phcoder' Serbinenko : > Carles Pina i Estany wrote: >> Hello, >> >> The common pattern when doing a search by bisection is something like: >> + =C2=A0 =C2=A0 =C2=A0current =3D min + (max - min) / 2; >> >> Instead of the first natural idea: >> - =C2=A0 =C2=A0 =C2=A0current =3D (max + min) / 2; >> >> To avoid overflows. >> >> In gettext/gettext.c it's used in the "incorrect" way. It's not a big >> problem since would happen only with .mo files with lot of strings, like >> number that int represents in that architecture divided by 2 (aprox >> aprox.). >> >> See the attached file for a patch if we want to patch. >> > You forgot to make the same change before the loop. But actually it > doesn't matter because overflow in this statement: > =C2=A0internal_position =3D offsettranslation + position * 8; > is reached well before the overflow in bisecting. Anyway this > mattersonly for >4GiB files and unless we put videos in .po I don't see > how this limit would be reached. So I prefer readability and would > reject this patch. There's a very readable way to express the "better" code that's immune to the overflow: int const range =3D max - min; /* or unsigned int, if min and max are declared that way */ current =3D min + range / 2; >> Else I would at least add a comment that we simplified because we >> consider that will not happen. >> >> Thanks, >> >> >> ------------------------------------------------------------------------ >> >> _______________________________________________ >> Grub-devel mailing list >> Grub-devel@gnu.org >> http://lists.gnu.org/mailman/listinfo/grub-devel > > > -- > Regards > Vladimir '=CF=86-coder/phcoder' Serbinenko > > > > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > http://lists.gnu.org/mailman/listinfo/grub-devel > >