This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

setlocale causing string comparison bug


I am having problems with string comparisons when using setlocale. I
am running this on two devices (phones) that have very similar
software and one exhibits this problem and the other doesn't. One is a
"release build" (e.g. stripped symbols and a couple other things) and
one is a "debug build" (opposite). The release does not work and the
dev does. They have a locale directory at /usr/share/i18n/locales and
it is identical on both. Their environment variables are also
identical.
Here is a program that shows the problem:

#include <glibmm/ustring.h>
#include <stdio.h>

int main()
{
    Glib::ustring str1("a1");
    Glib::ustring str2("a2");
    printf("Result: %i\n", (str1 == str2));
    setlocale(LC_ALL, "");
    printf("Result: %i\n", (str1 == str2));
    return 0;
}

The first result is 0 and the second is 1.

I have been trying to debug glib/glibc/glibmm to determine what is
happening differently with little success so far. The chain of events
is that == is overloaded to call compare() which calls g_utf8_collate
which translates the strings to wchar_t's and then calls wcscoll which
is in string/strcoll_l.c in glibc. STRCOLL has a locales array which
is different between the two devices, but I don't know. It changes
when setlocale(LC_ALL, "") is called.

Does anyone know what could cause this?

Thank you


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]