]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - locale/weight.h
Add 'codepoint_collation' support for LC_COLLATE.
[thirdparty/glibc.git] / locale / weight.h
index d67e9d9c2423e6cab7cb7cb946479ca77fbe88ea..076529c0ba114a3a41a3471cb0f7fd8e826c643b 100644 (file)
@@ -1,6 +1,5 @@
-/* Copyright (C) 1996,1997,1998,1999,2000,2003 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2021 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
-   Written by Ulrich Drepper, <drepper@cygnus.com>.
 
    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    Lesser General Public License for more details.
 
    You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#ifndef _WEIGHT_H_
+#define _WEIGHT_H_     1
+
+#include <libc-diag.h>
 
 /* Find index of weight.  */
-static inline int32_t
-__attribute ((always_inline))
-findidx (const unsigned char **cpp)
+static inline int32_t __attribute__ ((always_inline))
+findidx (const int32_t *table,
+        const int32_t *indirect,
+        const unsigned char *extra,
+        const unsigned char **cpp, size_t len)
 {
   int_fast32_t i = table[*(*cpp)++];
   const unsigned char *cp;
@@ -34,6 +39,7 @@ findidx (const unsigned char **cpp)
      Search for the correct one.  */
   cp = &extra[-i];
   usrc = *cpp;
+  --len;
   while (1)
     {
       size_t nhere;
@@ -56,9 +62,17 @@ findidx (const unsigned char **cpp)
             already.  */
          size_t cnt;
 
-         for (cnt = 0; cnt < nhere; ++cnt)
+         /* With GCC 5.3 when compiling with -Os the compiler warns
+            that seq2.back_us, which becomes usrc, might be used
+            uninitialized.  This can't be true because we pass a length
+            of -1 for len at the same time which means that this loop
+            never executes.  */
+         DIAG_PUSH_NEEDS_COMMENT;
+         DIAG_IGNORE_Os_NEEDS_COMMENT (5, "-Wmaybe-uninitialized");
+         for (cnt = 0; cnt < nhere && cnt < len; ++cnt)
            if (cp[cnt] != usrc[cnt])
              break;
+         DIAG_POP_NEEDS_COMMENT;
 
          if (cnt == nhere)
            {
@@ -69,8 +83,8 @@ findidx (const unsigned char **cpp)
 
          /* Up to the next entry.  */
          cp += nhere;
-         if ((1 + nhere) % __alignof__ (int32_t) != 0)
-           cp += __alignof__ (int32_t) - (1 + nhere) % __alignof__ (int32_t);
+         if (!LOCFILE_ALIGNED_P (1 + nhere))
+           cp += LOCFILE_ALIGN - (1 + nhere) % LOCFILE_ALIGN;
        }
       else
        {
@@ -79,19 +93,19 @@ findidx (const unsigned char **cpp)
          size_t cnt;
          size_t offset = 0;
 
-         for (cnt = 0; cnt < nhere; ++cnt)
+         for (cnt = 0; cnt < nhere && cnt < len; ++cnt)
            if (cp[cnt] != usrc[cnt])
              break;
 
          if (cnt != nhere)
            {
-             if (cp[cnt] > usrc[cnt])
+             if (cnt == len || cp[cnt] > usrc[cnt])
                {
                  /* Cannot be in this range.  */
                  cp += 2 * nhere;
-                 if ((1 + 2 * nhere) % __alignof__ (int32_t) != 0)
-                   cp += (__alignof__ (int32_t)
-                          - (1 + 2 * nhere) % __alignof__ (int32_t));
+                 if (!LOCFILE_ALIGNED_P (1 + 2 * nhere))
+                   cp += (LOCFILE_ALIGN
+                          - (1 + 2 * nhere) % LOCFILE_ALIGN);
                  continue;
                }
 
@@ -104,9 +118,9 @@ findidx (const unsigned char **cpp)
                {
                  /* Cannot be in this range.  */
                  cp += 2 * nhere;
-                 if ((1 + 2 * nhere) % __alignof__ (int32_t) != 0)
-                   cp += (__alignof__ (int32_t)
-                          - (1 + 2 * nhere) % __alignof__ (int32_t));
+                 if (!LOCFILE_ALIGNED_P (1 + 2 * nhere))
+                   cp += (LOCFILE_ALIGN
+                          - (1 + 2 * nhere) % LOCFILE_ALIGN);
                  continue;
                }
 
@@ -117,7 +131,15 @@ findidx (const unsigned char **cpp)
              do
                {
                  offset <<= 8;
+                 /* With GCC 7 when compiling with -Os the compiler
+                    warns that seq1.back_us and seq2.back_us, which
+                    become usrc, might be used uninitialized.  This
+                    is impossible for the same reason as described
+                    above.  */
+                 DIAG_PUSH_NEEDS_COMMENT;
+                 DIAG_IGNORE_Os_NEEDS_COMMENT (7, "-Wmaybe-uninitialized");
                  offset += usrc[cnt] - cp[cnt];
+                 DIAG_POP_NEEDS_COMMENT;
                }
              while (++cnt < nhere);
            }
@@ -130,3 +152,5 @@ findidx (const unsigned char **cpp)
   /* NOTREACHED */
   return 0x43219876;
 }
+
+#endif /* weight.h */