summaryrefslogtreecommitdiff
path: root/Python
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2009-05-03 22:33:34 +0000
committerMark Dickinson <dickinsm@gmail.com>2009-05-03 22:33:34 +0000
commitd41638e5998b3cb7f4736e628a660a5a0b366cdd (patch)
treee0ee5e90dbdd36f0339bc6c09932abb8a9bc7367 /Python
parent0ea74d3dd1be202b06dd67db151889fa8a53e4cd (diff)
downloadcpython-d41638e5998b3cb7f4736e628a660a5a0b366cdd.tar.gz
Don't use PyOS_strnicmp for NaN and Inf detection: it's locale-aware.
Diffstat (limited to 'Python')
-rw-r--r--Python/pystrtod.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/Python/pystrtod.c b/Python/pystrtod.c
index 9aeef2805f..2be383442d 100644
--- a/Python/pystrtod.c
+++ b/Python/pystrtod.c
@@ -40,6 +40,19 @@
correctly rounded results.
*/
+/* Case-insensitive string match used for nan and inf detection; t should be
+ lower-case. Returns 1 for a successful match, 0 otherwise. */
+
+static int
+case_insensitive_match(const char *s, const char *t)
+{
+ while(*t && Py_TOLOWER(*s) == *t) {
+ s++;
+ t++;
+ }
+ return *t ? 0 : 1;
+}
+
double
PyOS_ascii_strtod(const char *nptr, char **endptr)
{
@@ -89,9 +102,9 @@ PyOS_ascii_strtod(const char *nptr, char **endptr)
/* Parse infinities and nans */
if (*p == 'i' || *p == 'I') {
- if (PyOS_strnicmp(p, "inf", 3) == 0) {
+ if (case_insensitive_match(p+1, "nf")) {
val = Py_HUGE_VAL;
- if (PyOS_strnicmp(p+3, "inity", 5) == 0)
+ if (case_insensitive_match(p+3, "inity"))
fail_pos = (char *)p+8;
else
fail_pos = (char *)p+3;
@@ -102,7 +115,7 @@ PyOS_ascii_strtod(const char *nptr, char **endptr)
}
#ifdef Py_NAN
if (*p == 'n' || *p == 'N') {
- if (PyOS_strnicmp(p, "nan", 3) == 0) {
+ if (case_insensitive_match(p+1, "an")) {
val = Py_NAN;
fail_pos = (char *)p+3;
goto got_val;