Bug 1933 – Delimited string constants can cause segfault
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2008-03-20T02:12:00Z
Last change time
2015-06-09T01:14:21Z
Keywords
ice-on-invalid-code
Assigned to
bugzilla
Creator
bugs-d
Comments
Comment #0 by bugs-d — 2008-03-20T02:12:57Z
The documentation (which is somewhat unclear) seems to indicate that the following is incorrect:
q"
EOS
...
EOS"
If you try this, it will cause a segfault. The reason is that once we leave the switch in delimitedStringConstant(), c is '\n' (because of the break.) This ends up meaning delimleft and delimright are '\n', as best I can reason (haven't spent time debugging code yet.)
Simple solution to me seems like either adding an if inside |if (delimleft == 0)| to check that c is not whitespace, or adding a branch before it to ignore whitespace (depending on which is the correct interpretation of the spec.)
Also would be nice if the spec were clearer (e.g. "the delimiter, whether a character or identifier, must immediately follow the " without any whitespace. If the delimiter is an identifier, it must similarly immediately proceed the terminating ".)
I realize my D version is a bit outdated, but this diff shows the problem can't have been fixed yet for 2.012:
http://www.dsource.org/projects/dsss/changeset?new=branches%2Fdmdfe-2.0%2Flexer.c%40883&old=branches%2Fdmdfe-2.0%2Flexer.c%40838
Not sure if you care for my patches, but if I have time I'll try to look into this more and attach a patch (since I'm fairly confident the whitespace isn't supposed to be allowed.)
Thanks. I noticed this because I was writing my own lexer, not because I was actually using the heredocs... I have to say token and delimited strings complicated my lexer more than I expected...
Comment #1 by Joseph.Gauterin — 2008-07-16T17:06:56Z
This can be reproduced using a file containing only the following:
q"
X
"
and it's still a problem in D 2.014