This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: setlocale causing string comparison bug
- From: Ryan Arnold <ryan dot arnold at gmail dot com>
- To: Anthony Newnam <anthony at bnovc dot com>
- Cc: libc-help at sourceware dot org
- Date: Wed, 1 Jul 2009 16:10:19 -0500
- Subject: Re: setlocale causing string comparison bug
- References: <2cba86720906261127m3f6c1e72ucafbfeff302efd29@mail.gmail.com>
On Fri, Jun 26, 2009 at 1:27 PM, Anthony Newnam<anthony@bnovc.com> wrote:
> 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?
Hi Anthony, have you learned anything new since posting this?