Skip site navigation (1) Skip section navigation (2)

BUG #2192: misbehaving IRIX strtod() subverts parsing of "infinity"

From: "John Jorgensen" <John(dot)Jorgensen(at)uregina(dot)ca>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #2192: misbehaving IRIX strtod() subverts parsing of "infinity"
Date: 2006-01-20 19:14:03
Message-ID: 20060120191403.433CDF0B02@svr2.postgresql.org (view raw or flat)
Thread:
Lists: pgsql-bugs
The following bug has been logged online:

Bug reference:      2192
Logged by:          John Jorgensen
Email address:      John(dot)Jorgensen(at)uregina(dot)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

Responses

pgsql-bugs by date

Next:From: Stephen FrostDate: 2006-01-20 20:13:44
Subject: [PATCH] pg_restore COPY error handling
Previous:From: Helmar SpangenbergDate: 2006-01-20 17:03:17
Subject: Bug concerning regular expressions and UTF-8

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group