From: Carles Pina i Estany <carles@pina.cat>
To: grub-devel@gnu.org
Subject: avoid possible overflow?
Date: Sun, 14 Feb 2010 00:05:10 +0000 [thread overview]
Message-ID: <20100214000510.GA10702@pina.cat> (raw)
[-- Attachment #1: Type: text/plain, Size: 640 bytes --]
Hello,
The common pattern when doing a search by bisection is something like:
+ current = min + (max - min) / 2;
Instead of the first natural idea:
- current = (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.
Else I would at least add a comment that we simplified because we
consider that will not happen.
Thanks,
--
Carles Pina i Estany
http://pinux.info
[-- Attachment #2: gettext_overflow.patch --]
[-- Type: text/x-diff, Size: 786 bytes --]
=== modified file 'ChangeLog'
--- ChangeLog 2010-02-13 15:48:22 +0000
+++ ChangeLog 2010-02-14 00:02:48 +0000
@@ -1,3 +1,8 @@
+2010-02-13 Carles Pina i Estany <carles@pina.cat>
+
+ * gettext/gettext.c (grub_gettext_translate): Avoids possible
+ overflow.
+
2010-02-13 Vladimir Serbinenko <phcoder@gmail.com>
Merge grub_ieee1275_map_physical into grub_map and rename to
=== modified file 'gettext/gettext.c'
--- gettext/gettext.c 2010-01-20 08:12:47 +0000
+++ gettext/gettext.c 2010-02-13 23:56:58 +0000
@@ -192,7 +192,7 @@ grub_gettext_translate (const char *orig
grub_free (current_string);
found = 1;
}
- current = (max + min) / 2;
+ current = min + (max - min) / 2;
}
ret = found ? grub_gettext_gettranslation_from_position (current) : orig;
next reply other threads:[~2010-02-14 0:05 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-14 0:05 Carles Pina i Estany [this message]
2010-02-16 12:46 ` avoid possible overflow? Vladimir 'φ-coder/phcoder' Serbinenko
2010-02-16 13:31 ` richardvoigt
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=20100214000510.GA10702@pina.cat \
--to=carles@pina.cat \
--cc=grub-devel@gnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.