1916 – segfault on invalid string concat

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1916 - segfault on invalid string concat
Summary: segfault on invalid string concat
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: Walter Bright
URL:
Keywords: ice-on-invalid-code, patch
Depends on:
Blocks:
Reported: 2008年03月12日 20:00 UTC by Stephan Dilly
Modified: 2015年06月09日 01:14 UTC (History)
2 users (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Stephan Dilly 2008年03月12日 20:00:16 UTC
this invalid piece of code crashes the dmd compiler.
[CODE]
void main() {
	string crash = 01 ~ " foo?";
}
[/CODE]
Comment 1 Gide Nwawudu 2008年04月17日 07:26:28 UTC
This looks similar to a BUG 1702 which did get fixed, a later release appears to have re-introduced it.
Comment 2 Don 2009年04月01日 07:57:45 UTC
Only segfaults on D2.
fog.d(2): Error: incompatible types for ((1) ~ (" foo?")): 'int' and 'immutable(
char)[]'
fog.d(2): Error: Can only concatenate arrays, not (int ~ immutable(char)[])
fog.d(2): Error: cannot implicitly convert expression ("\x01 foo?") of type int
to immutable(char)[]
[SEGFAULT]
Comment 3 Don 2009年04月14日 04:57:17 UTC
This is indeed the same as bug 1702. A patch to fix this one also fixed 1702.
*** This bug has been marked as a duplicate of 1702 ***
Comment 4 Don 2009年04月14日 06:59:31 UTC
Oops, 1702 seems to be already fixed. This isn't the same.
Here's a simple patch which prevents the segfault.
Index: optimize.c
===================================================================
--- optimize.c	(revision 23)
+++ optimize.c	(working copy)
@@ -456,6 +457,8 @@
 Expression *e1old = e1;
 e1 = e1->optimize(result);
 e1 = fromConstInitializer(result, e1);
+	
+	if (!type->toBasetype()->ty) return this; // Bugzilla 1916
 
 if (e1 == e1old &&
 	e1->op == TOKarrayliteral &&
Comment 5 Don 2009年05月14日 06:56:12 UTC
Fixed DMD2.030 and 1.045.


AltStyle によって変換されたページ (->オリジナル) /