Use strtod instead of strtold in libiberty/d-demangle.c
authorJoel Brobecker <brobecker@adacore.com>
Tue, 14 Oct 2014 16:47:43 +0000 (12:47 -0400)
committerJoel Brobecker <brobecker@adacore.com>
Thu, 16 Oct 2014 21:52:17 +0000 (14:52 -0700)
strtold is currently used to decode templates which have a floating-point
value encoded inside; but this routine is not available on some systems,
such as Solaris 2.9 for instance.

This patch fixes the issue by replace the use of strtold by strtod.
It reduces a bit the precision, but it should still remain acceptable
in most cases.

libiberty/ChangeLog:

        * d-demangle.c: Replace strtold with strtod in global comment.
        (strtold): Remove declaration.
        (strtod): New declaration.
        (dlang_parse_real): Declare value as double instead of long
        double.  Replace call to strtold by call to strtod.
        Update format in call to snprintf.

libiberty/ChangeLog
libiberty/d-demangle.c

index 829f684d393540aa99c1c3cd7f253d4e8a567419..9e91cce251e85837d1d5904e1ed89bcebd90905e 100644 (file)
@@ -1,3 +1,12 @@
+2014-10-16  Joel Brobecker  <brobecker@adacore.com>
+
+       * d-demangle.c: Replace strtold with strtod in global comment.
+       (strtold): Remove declaration.
+       (strtod): New declaration.
+       (dlang_parse_real): Declare value as double instead of long
+       double.  Replace call to strtold by call to strtod.
+       Update format in call to snprintf.
+
 2014-09-26  Jason Merrill  <jason@redhat.com>
 
        * cp-demangle.c (d_substitution): Handle abi tags on abbreviation.
index d31bf9423780ca68ea18c71fe9f9ee55f90add37..bb481c0998e851b6c3fe6ad7610e00c92a0ea658 100644 (file)
@@ -28,7 +28,7 @@ If not, see <http://www.gnu.org/licenses/>.  */
 
 /* This file exports one function; dlang_demangle.
 
-   This file imports strtol and strtold for decoding mangled literals.  */
+   This file imports strtol and strtod for decoding mangled literals.  */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -44,7 +44,7 @@ If not, see <http://www.gnu.org/licenses/>.  */
 #include <stdlib.h>
 #else
 extern long strtol (const char *nptr, char **endptr, int base);
-extern long double strtold (const char *nptr, char **endptr);
+extern double strtod (const char *nptr, char **endptr);
 #endif
 
 #include <demangle.h>
@@ -810,7 +810,7 @@ dlang_parse_real (string *decl, const char *mangled)
 {
   char buffer[64];
   int len = 0;
-  long double value;
+  double value;
   char *endptr;
 
   /* Handle NAN and +-INF.  */
@@ -877,12 +877,12 @@ dlang_parse_real (string *decl, const char *mangled)
 
   /* Convert buffer from hexadecimal to floating-point.  */
   buffer[len] = '\0';
-  value = strtold (buffer, &endptr);
+  value = strtod (buffer, &endptr);
 
   if (endptr == NULL || endptr != (buffer + len))
     return NULL;
 
-  len = snprintf (buffer, sizeof(buffer), "%#Lg", value);
+  len = snprintf (buffer, sizeof(buffer), "%#g", value);
   string_appendn (decl, buffer, len);
   return mangled;
 }
This page took 0.03268 seconds and 4 git commands to generate.