From f0750f4f3556b9634930fe66ed6408b84812dddc Mon Sep 17 00:00:00 2001
From: zesstra <zesstra@zesstra.de>
Date: Wed, 6 May 2009 21:52:14 +0200
Subject: [PATCH 5/5] Changed restore_svalue() to recognize "inf" and "nan".

C99 specifies to represent 'infinity' and 'NaN' by "[-]inf" or "[-]infinity"
and a string starting with "nan". If restore_svalue() stumbles upon
such data (e.g. "inf=ffff:59995fd0") it tries to restore exponent and
mantissa and ignores "inf"/"infinity"/"nan".

Signed-off-by: zesstra <zesstra@zesstra.de>
---
 src/object.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/object.c b/src/object.c
index 59068f4..5420173 100644
--- a/src/object.c
+++ b/src/object.c
@@ -8359,6 +8359,7 @@ restore_svalue (svalue_t *svp, char **pt, char delimiter)
     case '-':  /* A number */
     case '0': case '1': case '2': case '3': case '4':
     case '5': case '6': case '7': case '8': case '9':
+    case 'i': case 'n':    // for infinity and NaN (C99).
       {
         char c, *numstart = cp;
         int nega = 0;
@@ -8371,7 +8372,8 @@ restore_svalue (svalue_t *svp, char **pt, char delimiter)
         }
 
         while(lexdigit(c = *cp++)) l = (((l << 2) + l) << 1) + (c - '0');
-        if (c != '.')
+        if (c != '.'
+            && c != 'i' && c != 'n')    // for infinity/NaN in floats
         {
             put_number(svp, nega ? -l : l);
             *pt = cp;
@@ -8381,9 +8383,15 @@ restore_svalue (svalue_t *svp, char **pt, char delimiter)
         /* If a float was written by the same host type as we are using,
          * restore the internal representation.
          * Otherwise, parse the float normally.
+         * C99 specifies to write "[-]infinity" or "[-]inf" for infinity and
+         * a string starting with 'nan' for NaN. We should restore such values
+         * the most meaningful way possible (use mantissa + exponent in any case).
          */
         svp->type = T_FLOAT;
-        if ( NULL != (cp = strchr(cp, '=')) &&  restore_ctx->restored_host == CURRENT_HOST)
+        if ( NULL != (cp = strchr(cp, '=')) &&  
+            (restore_ctx->restored_host == CURRENT_HOST
+             || strstr(numstart, "inf") != NULL
+             || strstr(numstart, "nan") != NULL) )
         {
             cp++;
             int32_t mantissa;
-- 
1.6.1

