[prev in list] [next in list] [prev in thread] [next in thread] 

List:       icu4c-support
Subject:    RE: ucnv_getDefaultName() stomps on stack?!?!!
From:       "Zartaj T. Majeed" <zmajeed () adobe ! com>
Date:       2002-10-18 19:49:34
[Download RAW message or body]

> FYI here is a closer look at the man page for setlocale().  I have a hard 
> time understanding what it's really trying to say, but it may shed some 
> light on the problem.
> 
> RETURN VALUE
>        A  successful call to setlocale() returns an opaque string
>        that corresponds to the locale set.  This  string  may  be
>        allocated  in static storage.  The string returned is such
>        that a subsequent call with that string and its associated
>        category  will  restore that part of the process's locale.
>        The return value is NULL if the request cannot be honored.
> 

This says two things:
1. The string returned by setlocale is opaque, meaning its contents
are implementation-dependent and may not be meaningful except
as an argument to a later setlocale call.
2. The pointer returned may be (and likely is) pointing to static
storage that can be overwritten by another setlocale call. So the
only correct way to use setlocale is to immediately copy the
string returned by it into memory allocated by the caller.
E.g. the following probably will not work:
printf("Locale is %s: " setlocale(LC_CTYPE, NULL));

Zartaj

> George Rhoten
> IBM Globalization Center of Competency/ICU  San Jose, CA, USA
> 

_______________________________________________
icu4c-support@oss.software.ibm.com - icu4c-support mailing list
To Un/Subscribe:
http://oss.software.ibm.com/developerworks/oss/mailman/listinfo/icu4c-support
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic