From 1a122a71eeb0671f92037ccdf5d2dc0b307af620 Mon Sep 17 00:00:00 2001 From: Iain Buclaw Date: Sat, 27 May 2017 11:29:38 +0000 Subject: [PATCH] d-demangle.c (dlang_parse_real): Remove stack buffer, write the demangled hexadecimal directly to string. libiberty/ChangeLog: * d-demangle.c (dlang_parse_real): Remove stack buffer, write the demangled hexadecimal directly to string. * testsuite/d-demangle-expected: Add tests. From-SVN: r248537 --- libiberty/ChangeLog | 6 ++++++ libiberty/d-demangle.c | 25 ++++++++----------------- libiberty/testsuite/d-demangle-expected | 4 ++++ 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog index c779928934a..83f6d215ccc 100644 --- a/libiberty/ChangeLog +++ b/libiberty/ChangeLog @@ -1,3 +1,9 @@ +2017-05-27 Iain Buclaw + + * d-demangle.c (dlang_parse_real): Remove stack buffer, write + the demangled hexadecimal directly to string. + * testsuite/d-demangle-expected: Add tests. + 2017-05-24 Eli Zaretskii * waitpid.c (wait) [__MINGW32__]: Define as a macro diff --git a/libiberty/d-demangle.c b/libiberty/d-demangle.c index ec5508e2777..030cab3333f 100644 --- a/libiberty/d-demangle.c +++ b/libiberty/d-demangle.c @@ -1025,9 +1025,6 @@ dlang_parse_integer (string *decl, const char *mangled, char type) static const char * dlang_parse_real (string *decl, const char *mangled) { - char buffer[64]; - int len = 0; - /* Handle NAN and +-INF. */ if (strncmp (mangled, "NAN", 3) == 0) { @@ -1051,23 +1048,22 @@ dlang_parse_real (string *decl, const char *mangled) /* Hexadecimal prefix and leading bit. */ if (*mangled == 'N') { - buffer[len++] = '-'; + string_append (decl, "-"); mangled++; } if (!ISXDIGIT (*mangled)) return NULL; - buffer[len++] = '0'; - buffer[len++] = 'x'; - buffer[len++] = *mangled; - buffer[len++] = '.'; + string_append (decl, "0x"); + string_appendn (decl, mangled, 1); + string_append (decl, "."); mangled++; /* Significand. */ while (ISXDIGIT (*mangled)) { - buffer[len++] = *mangled; + string_appendn (decl, mangled, 1); mangled++; } @@ -1075,26 +1071,21 @@ dlang_parse_real (string *decl, const char *mangled) if (*mangled != 'P') return NULL; - buffer[len++] = 'p'; + string_append (decl, "p"); mangled++; if (*mangled == 'N') { - buffer[len++] = '-'; + string_append (decl, "-"); mangled++; } while (ISDIGIT (*mangled)) { - buffer[len++] = *mangled; + string_appendn (decl, mangled, 1); mangled++; } - /* Write out the demangled hexadecimal, rather than trying to - convert the buffer into a floating-point value. */ - buffer[len] = '\0'; - len = strlen (buffer); - string_appendn (decl, buffer, len); return mangled; } diff --git a/libiberty/testsuite/d-demangle-expected b/libiberty/testsuite/d-demangle-expected index 626d7c2d980..950d4955d8f 100644 --- a/libiberty/testsuite/d-demangle-expected +++ b/libiberty/testsuite/d-demangle-expected @@ -838,6 +838,10 @@ _D8demangle52__T4testVrcN0C4CCCCCCCCCCCCCDP4c0B666666666666666P6Zv demangle.test!(-0x0.C4CCCCCCCCCCCCCDp4+0x0.B666666666666666p6i) # --format=dlang +_D8demangle91__T4testVde000111222333444555666777888999AAABBBCCCDDDEEEFFFP000111222333444555666777888999Zv +demangle.test!(0x0.00111222333444555666777888999AAABBBCCCDDDEEEFFFp000111222333444555666777888999) +# +--format=dlang _D8demangle22__T4testVG3ua3_616263Zv demangle.test!("abc") # -- 2.30.2