Bug 17770 – Null pointer access in CTFE code

Status
NEW
Severity
critical
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2017-08-21T09:35:07Z
Last change time
2024-12-13T18:54:15Z
Keywords
CTFE, ice
Assigned to
No Owner
Creator
Sönke Ludwig
Moved to GitHub: dmd#19307 →

Comments

Comment #0 by sludwig — 2017-08-21T09:35:07Z
Compiling the following snippet with DMD 2.076.0-b1 yields: object.Error@(0): Access Violation ---------------- 0x0042FF45 Earlier compiler versions produce similar errors. --- struct S { T*[] nodes; } struct T { string name; } S foo(string text) { T*[] ret; while (text.length) { auto n = new T; n.name = text; text = text[1 .. $]; ret ~= n; } return S(ret); } string bar(in S doc) { foreach (n; doc.nodes) baz(n); return null; } void baz(in T* node) { switch (node.name) { default: case "|": break; } } static const n = foo("xx"); enum b = bar(n); ---
Comment #1 by ag0aep6g — 2017-08-21T10:00:49Z
Slightly more reduced, and including a variant that throws an AssertError instead of segfaulting: ---- struct S { T* t; } struct T { string name; } S foo(string name) { return S(new T(name[0 .. $])); } int bar(string name) { version (segfault) size_t len = name.length; // segfault else version (asserterror) string n = name; // AssertError@ddmd/ctfeexpr.d(1854) return 0; } const S s = foo(""); enum b = bar(s.t.name); ----
Comment #2 by bitter.taste — 2018-03-20T08:44:11Z
Comment #3 by robert.schadek — 2024-12-13T18:54:15Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19307 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB