]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
iconv, localedef: avoid floating point rounding differences [BZ #24372]
authorDJ Delorie <dj@redhat.com>
Thu, 21 Mar 2019 03:56:59 +0000 (23:56 -0400)
committerDJ Delorie <dj@redhat.com>
Thu, 21 Mar 2019 17:47:14 +0000 (13:47 -0400)
Two cases of "int * 1.4" may result in imprecise results, which
in at least one case resulted in i686 and x86-64 producing
different locale files.  This replaced that floating point multiply
with integer operations.  While the hash table margin is increased
from 40% to 50%, testing shows only 2% increase in overall size
of the locale archive.

https://bugzilla.redhat.com/show_bug.cgi?id=1311954

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
ChangeLog
iconv/iconvconfig.c
locale/programs/ld-collate.c

index 8cd9d8ba7075f658df1faf226e00bef652636f0d..ba9b6151ed0c9a558aee28fcac16d92414efba71 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2019-03-21  DJ Delorie  <dj@redhat.com>
+
+       [BZ #24372]
+       * iconv/iconvconfig.c (write_output): Replace floating point math
+       with integer math to avoid imprecise results.
+       * locale/programs/ld-collate.c (collate_output): Likewise.
+
 2019-03-21  Stefan Liebler  <stli@linux.ibm.com>
 
        * sysdeps/s390/dl-procinfo.h (HWCAP_IMPORTANT):
index 02014507426c5c0a11f400b65fde80133bd40b77..1e6066cdf0ddff33a146b4ee83f0160509eb3ef3 100644 (file)
@@ -1079,9 +1079,9 @@ write_output (void)
 
   /* Create the hashing table.  We know how many strings we have.
      Creating a perfect hash table is not reasonable here.  Therefore
-     we use open hashing and a table size which is the next prime 40%
+     we use open hashing and a table size which is the next prime 50%
      larger than the number of strings.  */
-  hash_size = next_prime (nnames * 1.4);
+  hash_size = next_prime (nnames + nnames >> 1);
   hash_table = (struct hash_entry *) xcalloc (hash_size,
                                              sizeof (struct hash_entry));
   /* Fill the hash table.  */
index bb4e2c539d2b87e63024dd6e8642dc97df50b47c..19b23c2453860a9c2e970d177c6f31a2e4e35afc 100644 (file)
@@ -2401,8 +2401,8 @@ collate_output (struct localedef_t *locale, const struct charmap_t *charmap,
 
       runp = runp->next;
     }
-  /* Add 40% and find the next prime number.  */
-  elem_size = next_prime (elem_size * 1.4);
+  /* Add 50% and find the next prime number.  */
+  elem_size = next_prime (elem_size + elem_size >> 1);
 
   /* Allocate the table.  Each entry consists of two words: the hash
      value and an index in a secondary table which provides the index