From eb058b7de655251d88eee5ecce38de008e6eb90d Mon Sep 17 00:00:00 2001 From: Iain Buclaw Date: Sat, 16 May 2015 16:49:13 +0000 Subject: [PATCH] d-demangle.c (dlang_parse_string): Represent embedded whitespace or non-printable characters as hex or escape... libiberty/ChangeLog: 2015-05-16 Iain Buclaw * d-demangle.c (dlang_parse_string): Represent embedded whitespace or non-printable characters as hex or escape sequences. * testsuite/d-demangle-expected: Add test for templates with tabs and newlines embedded into the signature. From-SVN: r223240 --- libiberty/ChangeLog | 7 +++++ libiberty/d-demangle.c | 35 +++++++++++++++++++++++-- libiberty/testsuite/d-demangle-expected | 4 +++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog index 30da962795a..3d86a0edd3a 100644 --- a/libiberty/ChangeLog +++ b/libiberty/ChangeLog @@ -1,3 +1,10 @@ +2015-05-16 Iain Buclaw + + * d-demangle.c (dlang_parse_string): Represent embedded whitespace or + non-printable characters as hex or escape sequences. + * testsuite/d-demangle-expected: Add test for templates with tabs and + newlines embedded into the signature. + 2015-05-08 Joel Brobecker * mkstemps.c: #include if HAVE_TIME_H is defined diff --git a/libiberty/d-demangle.c b/libiberty/d-demangle.c index bb481c0998e..10585214a9f 100644 --- a/libiberty/d-demangle.c +++ b/libiberty/d-demangle.c @@ -1,5 +1,5 @@ /* Demangler for the D programming language - Copyright 2014 Free Software Foundation, Inc. + Copyright 2014, 2015 Free Software Foundation, Inc. Written by Iain Buclaw (ibuclaw@gdcproject.org) This file is part of the libiberty library. @@ -931,7 +931,38 @@ dlang_parse_string (string *decl, const char *mangled) char a = ascii2hex (mangled[0]); char b = ascii2hex (mangled[1]); char val = (a << 4) | b; - string_appendn (decl, &val, 1); + + /* Sanitize white and non-printable characters. */ + switch (val) + { + case ' ': + string_append (decl, " "); + break; + case '\t': + string_append (decl, "\\t"); + break; + case '\n': + string_append (decl, "\\n"); + break; + case '\r': + string_append (decl, "\\r"); + break; + case '\f': + string_append (decl, "\\f"); + break; + case '\v': + string_append (decl, "\\v"); + break; + + default: + if (ISPRINT (val)) + string_appendn (decl, &val, 1); + else + { + string_append (decl, "\\x"); + string_appendn (decl, mangled, 2); + } + } } else return NULL; diff --git a/libiberty/testsuite/d-demangle-expected b/libiberty/testsuite/d-demangle-expected index 2aeacb8389f..b023f6d5d79 100644 --- a/libiberty/testsuite/d-demangle-expected +++ b/libiberty/testsuite/d-demangle-expected @@ -934,3 +934,7 @@ serenity.persister.Sqlite.SqlitePersister!(serenity.persister.Sqlite.__unittest6 --format=dlang _D4test4mainFZv5localMFZi test.main().local() +# +--format=dlang +_D3std6socket12InternetHost221__T13getHostNoSyncVAyaa96_0a09202020206175746f2078203d2068746f6e6c28706172616d293b0a09202020206175746f206865203d20676574686f73746279616464722826782c20342c206361737428696e74294164647265737346616d696c792e494e4554293b0a09TkZ13getHostNoSyncMFkZb +std.socket.InternetHost.getHostNoSync!("\n\t auto x = htonl(param);\n\t auto he = gethostbyaddr(&x, 4, cast(int)AddressFamily.INET);\n\t", uint).getHostNoSync(uint) -- 2.30.2