D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3495 - Segfault(typinf.c) instantiating D variadic function with too few arguments
Summary: Segfault(typinf.c) instantiating D variadic function with too few arguments
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: Other Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: ice-on-invalid-code, patch
Depends on:
Blocks:
 
Reported: 2009-11-11 05:39 UTC by Don
Modified: 2014-04-18 09:12 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Don 2009-11-11 05:39:45 UTC
Segfaulting in createTypeInfoArray(): exps[i] is null.

Applies to DMD0.175 and later, including both D2.036 and D1.051.
---
void foo(int,...) {}

void bar(){
   foo();
}
---
arr.d(4): Error: function arr.foo (int _param_0,...) is not callable using argum
ent types ()
arr.d(4): Error: expected 1 function arguments, not 0
<segfault>

Doesn't happen with C-style variadics.
Comment 1 Don 2009-11-11 07:57:22 UTC
CAUSE: if not enough arguments, tries to create a negatively-sized type info array!

PATCH: expression.c, line 802 (DMD2 svn 241), at end of functionArguments():

---

    // If D linkage and variadic, add _arguments[] as first argument
-    if (tf->linkage == LINKd && tf->varargs == 1)
+    if (tf->linkage == LINKd && tf->varargs == 1 && arguments->dim >= nparams)
    {
	Expression *e;

	e = createTypeInfoArray(sc, (Expression **)&arguments->data[nparams],
		arguments->dim - nparams);
	arguments->insert(0, e);
Comment 2 Walter Bright 2009-12-06 00:47:06 UTC
Fixed dmd 1.053 and 2.037