]> granicus.if.org Git - python/commitdiff
Bug #920575: Add a workaround for GNU libc nl_langinfo()'s returning NULL.
authorHye-Shik Chang <hyeshik@gmail.com>
Sun, 21 Mar 2004 19:34:30 +0000 (19:34 +0000)
committerHye-Shik Chang <hyeshik@gmail.com>
Sun, 21 Mar 2004 19:34:30 +0000 (19:34 +0000)
(Reported by Matthias Klose)

Misc/NEWS
Modules/_localemodule.c

index c0e2afe6ee3c3ce1402a35b77ed56537baf4d2cc..dfb64322f80221b17a8fea08c0c3f4f3bc134f1f 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -193,6 +193,9 @@ Core and builtins
 Extension modules
 -----------------
 
+- Bug #920575: A problem that _locale module segfaults on
+  nl_langinfo(ERA) caused by GNU libc's illegal NULL return is fixed.
+
 - array objects now support the copy module.  Also, their resizing
   scheme has been updated the same as for list objects.  The improves
   the performance (speed and memory usage) of append() operations.
index 2cfda880f2c27e22750b5df1ff09884e9e4cf474..5edb7f378de887c7a98d7468e0cba22981a36c50 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;
 }