summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2009-05-03 22:36:01 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2009-05-03 22:36:01 (GMT)
commit129ab1d8090f54b308b1d4ddaf4fd241ba312a95 (patch)
tree3bdfd5e415e86d66ef0d4adc7df98b10e6db53e3 /Python
parentaa77d26009456a447dc95f748533d64cb6a1b50a (diff)
downloadcpython-129ab1d8090f54b308b1d4ddaf4fd241ba312a95.zip
cpython-129ab1d8090f54b308b1d4ddaf4fd241ba312a95.tar.gz
cpython-129ab1d8090f54b308b1d4ddaf4fd241ba312a95.tar.bz2
Merged revisions 72257 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r72257 | mark.dickinson | 2009-05-03 23:33:34 +0100 (Sun, 03 May 2009) | 2 lines 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 66242d8..a50d360 100644
--- a/Python/pystrtod.c
+++ b/Python/pystrtod.c
@@ -63,6 +63,19 @@ _PyOS_ascii_strtod(const char *nptr, char **endptr)
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)
{
@@ -107,9 +120,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;
@@ -120,7 +133,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;