bug-glibc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

glibc 2.2.2 strxfrm empty string bug: returns 1 (should be 0)


From: Paul Eggert
Subject: glibc 2.2.2 strxfrm empty string bug: returns 1 (should be 0)
Date: Mon, 19 Mar 2001 01:24:36 -0800 (PST)

In nontrivial locales, glibc strxfrm returns 1 for an empty string; it
should return 0.  Here's a test program illustrating the bug; it
should output nothing, but with glibc it outputs "strxfrm returned 1,
strlen returned 0".

  #include <string.h>
  #include <stdio.h>
  #include <locale.h>
  #include <stdlib.h>

  char const string[] = "";

  int main ()
  {
    size_t bufsize;
    char *buf;
    size_t r, l;
    if (! setlocale (LC_COLLATE, "en_US"))
      {
        perror ("setlocale");
        return 1;
      }
    bufsize = strxfrm (NULL, string, 0) + 1;
    buf = malloc (bufsize);
    if (! buf)
      {
        perror ("malloc");
        return 1;
      }
    r = strxfrm (buf, string, bufsize);
    l = strlen (buf);
    if (r != l)
      {
         fprintf (stderr, "strxfrm returned %lu, strlen returned %lu\n",
                 (unsigned long) r, (unsigned long) l);
         return 1;
      }
    return 0;
  }


Here is a patch.

2001-03-19  Paul Eggert  <address@hidden>

        * string/strxfrm.c (strxfrm): strxfrm should return 0, not 1,
        when given the empty string in nontrivial locales.

===================================================================
RCS file: strxfrm.c,v
retrieving revision 1.28
retrieving revision 1.28.0.1
diff -pu -r1.28 -r1.28.0.1
--- strxfrm.c   2001/01/26 13:42:33     1.28
+++ strxfrm.c   2001/03/19 09:06:39     1.28.0.1
@@ -162,7 +162,7 @@ STRXFRM (STRING_TYPE *dest, const STRING
     {
       if (n != 0)
         *dest = L('\0');
-      return 1;
+      return 0;
     }
 
   /* We need the elements of the string as unsigned values since they



reply via email to

[Prev in Thread] Current Thread [Next in Thread]