]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport checkin:
authorHye-Shik Chang <hyeshik@gmail.com>
Sun, 21 Mar 2004 19:53:59 +0000 (19:53 +0000)
committerHye-Shik Chang <hyeshik@gmail.com>
Sun, 21 Mar 2004 19:53:59 +0000 (19:53 +0000)
[Bug #920575] Add a workaround for GNU libc nl_langinfo()'s returning NULL.

Misc/NEWS
Modules/_localemodule.c

index 448e6c8775db24eec43f2a7b77bf6d9198f84f6d..1cbfda33b194339c0cb27ecce1d74a045f571142 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -38,6 +38,9 @@ Core and builtins
 Library
 -------
 
+- Bug #920575: A problem that _locale module segfaults on
+  nl_langinfo(ERA) caused by GNU libc's illegal NULL return is fixed.
+
 - Bug #883604: Fix Lib/test/test_strftime.py to escape characters from locale
   time values that might be mistaken as regex syntax.
 
index 5862c1e59b192d42bf870f9527b0a02295408cca..363a823f3df15e1d4ba4589cc24384b1ba43d846 100644 (file)
@@ -592,8 +592,12 @@ PyLocale_nl_langinfo(PyObject* self, PyObject* args)
     }
 #endif
     for (i = 0; langinfo_constants[i].name; i++)
-           if (langinfo_constants[i].value == item)
-                   return PyString_FromString(nl_langinfo(item));
+        if (langinfo_constants[i].value == item) {
+            /* Check NULL as a workaround for GNU libc's returning NULL
+               instead of an empty string for nl_langinfo(ERA).  */
+            const char *result = nl_langinfo(item);
+            return PyString_FromString(result != NULL ? result : "");
+        }
     PyErr_SetString(PyExc_ValueError, "unsupported langinfo constant");
     return NULL;
 }