Patch for locale/programs/3level.h

Andreas Jaeger aj@suse.de
Mon Aug 6 06:05:00 GMT 2001


We noticed a problem with ~0 nesting in 3level.h.  The following looks
more sane to me.

Ok to commit?

I don't have a testcase, just noticed this while code reading.

Andreas

2001-08-06  Andreas Jaeger  <aj@suse.de>,
            Andreas Schwab <schwab@suse.de>

	* locale/programs/3level.h (_get): Properly nest ~0.
	(_add): Likewise.
	(_finalize): Likewise.

============================================================
Index: locale/programs/3level.h
--- locale/programs/3level.h	2001/07/06 04:55:33	1.3
+++ locale/programs/3level.h	2001/08/06 12:15:23
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 Free Software Foundation, Inc.
+/* Copyright (C) 2000, 2001 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Bruno Haible <haible@clisp.cons.org>, 2000.
 
@@ -82,12 +82,12 @@ CONCAT(TABLE,_get) (struct TABLE *t, uin
   if (index1 < t->level1_size)
     {
       uint32_t lookup1 = t->level1[index1];
-      if (lookup1 != ~((uint32_t) 0))
+      if (lookup1 != (uint32_t) ~0)
 	{
 	  uint32_t index2 = ((wc >> t->p) & ((1 << t->q) - 1))
 			    + (lookup1 << t->q);
 	  uint32_t lookup2 = t->level2[index2];
-	  if (lookup2 != ~((uint32_t) 0))
+	  if (lookup2 != (uint32_t) ~0)
 	    {
 	      uint32_t index3 = (wc & ((1 << t->p) - 1))
 				+ (lookup2 << t->p);
@@ -124,10 +124,10 @@ CONCAT(TABLE,_add) (struct TABLE *t, uin
 	  t->level1_alloc = alloc;
 	}
       while (index1 >= t->level1_size)
-	t->level1[t->level1_size++] = ~((uint32_t) 0);
+	t->level1[t->level1_size++] = (uint32_t) ~0;
     }
 
-  if (t->level1[index1] == ~((uint32_t) 0))
+  if (t->level1[index1] == (uint32_t) ~0)
     {
       if (t->level2_size == t->level2_alloc)
 	{
@@ -139,13 +139,13 @@ CONCAT(TABLE,_add) (struct TABLE *t, uin
       i1 = t->level2_size << t->q;
       i2 = (t->level2_size + 1) << t->q;
       for (i = i1; i < i2; i++)
-	t->level2[i] = ~((uint32_t) 0);
+	t->level2[i] = (uint32_t) ~0;
       t->level1[index1] = t->level2_size++;
     }
 
   index2 += t->level1[index1] << t->q;
 
-  if (t->level2[index2] == ~((uint32_t) 0))
+  if (t->level2[index2] == (uint32_t) ~0)
     {
       if (t->level3_size == t->level3_alloc)
 	{
@@ -176,14 +176,14 @@ CONCAT(TABLE,_iterate) (struct TABLE *t,
   for (index1 = 0; index1 < t->level1_size; index1++)
     {
       uint32_t lookup1 = t->level1[index1];
-      if (lookup1 != ~((uint32_t) 0))
+      if (lookup1 != (uint32_t) ~0)
 	{
 	  uint32_t lookup1_shifted = lookup1 << t->q;
 	  uint32_t index2;
 	  for (index2 = 0; index2 < (1 << t->q); index2++)
 	    {
 	      uint32_t lookup2 = t->level2[index2 + lookup1_shifted];
-	      if (lookup2 != ~((uint32_t) 0))
+	      if (lookup2 != (uint32_t) ~0)
 		{
 		  uint32_t lookup2_shifted = lookup2 << t->p;
 		  uint32_t index3;
@@ -232,7 +232,7 @@ CONCAT(TABLE,_finalize) (struct TABLE *t
   t->level3_size = k;
 
   for (i = 0; i < (t->level2_size << t->q); i++)
-    if (t->level2[i] != ~((uint32_t) 0))
+    if (t->level2[i] != (uint32_t) ~0)
       t->level2[i] = reorder3[t->level2[i]];
 
   /* Uniquify level2 blocks.  */
@@ -256,7 +256,7 @@ CONCAT(TABLE,_finalize) (struct TABLE *t
   t->level2_size = k;
 
   for (i = 0; i < t->level1_size; i++)
-    if (t->level1[i] != ~((uint32_t) 0))
+    if (t->level1[i] != (uint32_t) ~0)
       t->level1[i] = reorder2[t->level1[i]];
 
   /* Create and fill the resulting compressed representation.  */
@@ -286,13 +286,13 @@ CONCAT(TABLE,_finalize) (struct TABLE *t
 
   for (i = 0; i < t->level1_size; i++)
     ((uint32_t *) (t->result + level1_offset))[i] =
-      (t->level1[i] == ~((uint32_t) 0)
+      (t->level1[i] == ((uint32_t) ~0)
        ? 0
        : (t->level1[i] << t->q) * sizeof (uint32_t) + level2_offset);
 
   for (i = 0; i < (t->level2_size << t->q); i++)
     ((uint32_t *) (t->result + level2_offset))[i] =
-      (t->level2[i] == ~((uint32_t) 0)
+      (t->level2[i] == ((uint32_t) ~0)
        ? 0
        : (t->level2[i] << t->p) * sizeof (ELEMENT) + level3_offset);
 

-- 
 Andreas Jaeger
  SuSE Labs aj@suse.de
   private aj@arthur.inka.de
    http://www.suse.de/~aj



More information about the Libc-hacker mailing list