This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: invalid use of setlocale
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.0, Python 3.1, Python 2.7, Python 2.6
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: loewis Nosy List: akitada, brett.cannon, georg.brandl, loewis, sbrabec
Priority: normal Keywords: patch

Created on 2003-09-11 15:46 by sbrabec, last changed 2022-04-10 16:11 by admin. This issue is now closed.

File name Uploaded Description Edit
Python-2.3-setlocale.patch sbrabec, 2003-09-11 15:46 Python-2.3-setlocale.patch
Messages (6)
msg44605 - (view) Author: Stanislav Brabec (sbrabec) Date: 2003-09-11 15:46
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:

       ... 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.
msg44606 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2003-09-29 01:46
Logged In: YES 

'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.
msg44607 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2003-09-29 02:19
Logged In: YES 

OK, I found that we have our own definition of strdup() that has used if it is not defined by the C library, so that 
issue is clear.
msg44608 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2003-11-13 07:44
Logged In: YES 

The patch was slightly outdated, so I have updated it, and
committed it as

readline.c 2.66
pythonrun.c 2.199
msg82850 - (view) Author: Akira Kitada (akitada) * Date: 2009-02-27 17:26
If I'm not mistaken, this bug seems to be fre-introduced in
It could be fixed in just as it was before.
msg82855 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-02-27 17:54
Fixed in r70029, merged to 3.0 in r70030.
Date User Action Args
2022-04-10 16:11:07adminsetgithub: 39217
2009-02-27 17:54:20georg.brandlsetstatus: open -> closed
nosy: + georg.brandl
resolution: fixed
messages: + msg82855
2009-02-27 17:50:28georg.brandlsetstatus: closed -> open
resolution: accepted -> (no value)
2009-02-27 17:26:24akitadasetnosy: + akitada
type: behavior
messages: + msg82850
components: + Interpreter Core, - None
versions: + Python 2.6, Python 3.0, Python 3.1, Python 2.7
2003-09-11 15:46:23sbrabeccreate