[Patches] [ python-Patches-804543 ] invalid use of setlocale

SourceForge.net noreply at sourceforge.net
Sun Sep 28 21:46:38 EDT 2003


Patches item #804543, was opened at 2003-09-11 08:46
Message generated for change (Comment added) made by bcannon
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=804543&group_id=5470

>Category: None
>Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Stanislav Brabec (sbrabec)
Assigned to: Nobody/Anonymous (nobody)
Summary: invalid use of setlocale

Initial Comment:
char *oldloc=setlocale(LC_CTYPE,NULL);

setlocale(LC_CTYPE, "C");

setlocale(LC_CTYPE, oldloc);



can cause strange problems.



The glibc documentation clearly states, that you must

make your own copy of the string.



>From glibc docs:

setlocale()



RETURN VALUE

       ... This  string  may  be allocated  in static

storage. ...



It means, that subsequent call of setlocale can

overwrite this string. And since glibc-2.3 it does.



There is a fix.



----------------------------------------------------------------------

>Comment By: Brett Cannon (bcannon)
Date: 2003-09-28 18:46

Message:
Logged In: YES 
user_id=357491

'C: A Reference Manual' also suggests copying the string in fear of 

possible mucking with the string that is pointed to by the 

setlocale() call.



Since this has a patch already I am changing this to a patch.



And as for the patch, it does use strdup() which is not ANSI C.  I 

know that there a couple of places that do use strdup(), but I am 

not sure if that is really proper.  Requires asking python-dev.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=804543&group_id=5470



More information about the Patches mailing list