* [PATCH 1/7] [D] libiberty: Correctly decode white or non-printable characters
@ 2015-05-13 8:51 Iain Buclaw
2015-05-14 12:54 ` Jeff Law
0 siblings, 1 reply; 2+ messages in thread
From: Iain Buclaw @ 2015-05-13 8:51 UTC (permalink / raw)
To: gcc-patches, Ian Lance Taylor
[-- Attachment #1: Type: text/plain, Size: 999 bytes --]
Hi,
Started these as separate patches, but as more came out of what I was
originally trying to achieve (see Patch 6/7), I thought it better to
have it as a running series.
These set out to update d-demangle.c for new ABI additions, general
bug fixes, and improved template support.
---
D templates can have string literals encoded inside them, which can
also include tabs, newlines, and other whitespace characters. For
example:
return getHost!q{
auto he = gethostbyname(toStringz(param));
}(name);
In this case, rather than decoding and writing out every character
directly, whitespace or other non-printable characters should be
represented as escape sequences.
---
libiberty/ChangeLog:
2015-05-13 Iain Buclaw <ibuclaw@gdcproject.org>
* 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.
[-- Attachment #2: 0001-D-demangle-Correctly-decode-white-or-non-printable-c.patch --]
[-- Type: text/x-diff, Size: 2354 bytes --]
From f6d6383994f0537f3e9b527419232ae69e2ceb4a Mon Sep 17 00:00:00 2001
From: Iain Buclaw <ibuclaw@gdcproject.org>
Date: Mon, 11 May 2015 09:20:29 +0200
Subject: [PATCH 1/7] D demangle: Correctly decode white or non-printable
characters
---
libiberty/d-demangle.c | 33 ++++++++++++++++++++++++++++++++-
libiberty/testsuite/d-demangle-expected | 4 ++++
2 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/libiberty/d-demangle.c b/libiberty/d-demangle.c
index bb481c0..fa01767 100644
--- a/libiberty/d-demangle.c
+++ b/libiberty/d-demangle.c
@@ -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 2aeacb8..b023f6d 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.1.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH 1/7] [D] libiberty: Correctly decode white or non-printable characters
2015-05-13 8:51 [PATCH 1/7] [D] libiberty: Correctly decode white or non-printable characters Iain Buclaw
@ 2015-05-14 12:54 ` Jeff Law
0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2015-05-14 12:54 UTC (permalink / raw)
To: Iain Buclaw, gcc-patches, Ian Lance Taylor
On 05/13/2015 02:51 AM, Iain Buclaw wrote:
> Hi,
>
> Started these as separate patches, but as more came out of what I was
> originally trying to achieve (see Patch 6/7), I thought it better to
> have it as a running series.
>
> These set out to update d-demangle.c for new ABI additions, general
> bug fixes, and improved template support.
> ---
>
> D templates can have string literals encoded inside them, which can
> also include tabs, newlines, and other whitespace characters. For
> example:
>
> return getHost!q{
> auto he = gethostbyname(toStringz(param));
> }(name);
>
>
> In this case, rather than decoding and writing out every character
> directly, whitespace or other non-printable characters should be
> represented as escape sequences.
>
> ---
> libiberty/ChangeLog:
>
> 2015-05-13 Iain Buclaw <ibuclaw@gdcproject.org>
>
> * 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.
OK.
jeff
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-05-14 12:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-13 8:51 [PATCH 1/7] [D] libiberty: Correctly decode white or non-printable characters Iain Buclaw
2015-05-14 12:54 ` Jeff Law
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).