BUG #2192: misbehaving IRIX strtod() subverts parsing of "infinity" - Mailing list pgsql-bugs

From John Jorgensen
Subject BUG #2192: misbehaving IRIX strtod() subverts parsing of "infinity"
Date
Msg-id 20060120191403.433CDF0B02@svr2.postgresql.org
Whole thread Raw
Responses Re: BUG #2192: misbehaving IRIX strtod() subverts parsing of
List pgsql-bugs
The following bug has been logged online:

Bug reference:      2192
Logged by:          John Jorgensen
Email address:      John.Jorgensen@uregina.ca
PostgreSQL version: 8.1.1
Operating system:   IRIX 6.5.22f
Description:        misbehaving IRIX strtod() subverts parsing of "infinity"
Details:

When I ran "gmake check", the float4 and float8 tests failed because syntax
errors were reported for "infinity" and "-infinity". I was able to make the
test pass by applying the appended patch, made on the model of the existing
patch for Solaris's strtod() (I understand that IRIX is probably becoming
rare enough that you might not want to clutter your source tree with the
patch).


diff -ur /nobackup/src/postgresql-8.1.1/./src/backend/utils/adt/float.c
./src/backend/utils/adt/float.c
--- /nobackup/src/postgresql-8.1.1/./src/backend/utils/adt/float.c
2005-10-14 20:49:28.000000000 -0600
+++ ./src/backend/utils/adt/float.c     2006-01-20 10:44:25.000000000 -0600
@@ -326,6 +326,32 @@
                if (endptr != num && endptr[-1] == '\0')
                        endptr--;
        }
+#else
+#ifdef HAVE_BUGGY_IRIX_STRTOD
+       else
+       {
+               /* The IRIX strtod() accepts "infinity" or
+                * "-infinity", but it leaves endptr pointing at
+                * "inity" and seems to ignore the negative sign. */
+               if (isinf(val))
+               {
+                       if (endptr == (num + 3)
+                           && (! strncasecmp(endptr, "inity",
sizeof("inity") - 1)))
+                       {
+                               endptr += sizeof("inity") - 1;
+                       }
+                       if (endptr == (num + 4) && *num == '-'
+                           && (! strncasecmp(endptr, "inity",
sizeof("inity") - 1)))
+                       {
+                               if (is_infinite(val) == 1)
+                               {
+                                       val = -val;
+                               }
+                               endptr += sizeof("inity") - 1;
+                       }
+               }
+       }
+#endif   /* HAVE_BUGGY_IRIX_STRTOD */
 #endif   /* HAVE_BUGGY_SOLARIS_STRTOD */

        /* skip trailing whitespace */
@@ -493,6 +519,32 @@
                if (endptr != num && endptr[-1] == '\0')
                        endptr--;
        }
+#else
+#ifdef HAVE_BUGGY_IRIX_STRTOD
+       else
+       {
+               /* The IRIX strtod() accepts "infinity" or
+                * "-infinity", but it leaves endptr pointing at
+                * "inity" and seems to ignore the negative sign. */
+               if (isinf(val))
+               {
+                       if (endptr == (num + 3)
+                           && (! strncasecmp(endptr, "inity",
sizeof("inity") - 1)))
+                       {
+                               endptr += sizeof("inity") - 1;
+                       }
+                       if (endptr == (num + 4) && *num == '-'
+                           && (! strncasecmp(endptr, "inity",
sizeof("inity") - 1)))
+                       {
+                               if (is_infinite(val) == 1)
+                               {
+                                       val = -val;
+                               }
+                               endptr += sizeof("inity") - 1;
+                       }
+               }
+       }
+#endif   /* HAVE_BUGGY_IRIX_STRTOD */
 #endif   /* HAVE_BUGGY_SOLARIS_STRTOD */

        /* skip trailing whitespace */
diff -ur /nobackup/src/postgresql-8.1.1/./src/include/port/irix.h
./src/include/port/irix.h
--- /nobackup/src/postgresql-8.1.1/./src/include/port/irix.h    2006-01-19
14:10:38.000000000 -0600
+++ ./src/include/port/irix.h   2006-01-19 17:10:44.000000000 -0600
@@ -1 +1,5 @@
-
+/*
+ * IRIX 6.5.26f and 6.5.22f (at least) have a strtod() that accepts
+ * "infinity", but leaves endptr pointing to "inity".
+ */
+#define HAVE_BUGGY_IRIX_STRTOD

pgsql-bugs by date:

Previous
From: Steven Mooij
Date:
Subject: Re: BUG #2168: 45.000.000 records too much?
Next
From: Helmar Spangenberg
Date:
Subject: Bug concerning regular expressions and UTF-8