Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
fix infinite loop in (cast()super).toString
Browse files Browse the repository at this point in the history
- the compiler doesn't recognize this as super call
  and will use dynamic dispatch leading to an infinite loop
  • Loading branch information
MartinNowak committed Mar 4, 2016
1 parent ff4faa4 commit 2db5144
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/core/exception.d
Expand Up @@ -227,7 +227,13 @@ class OutOfMemoryError : Error

override string toString() const @trusted
{
return msg.length ? (cast()super).toString() : "Memory allocation failed";
return msg.length ? (cast()this).superToString() : "Memory allocation failed";
}

// kludge to call non-const super.toString
private string superToString() @trusted
{
return super.toString();
}
}

Expand All @@ -239,6 +245,7 @@ unittest
assert(oome.line == __LINE__ - 2);
assert(oome.next is null);
assert(oome.msg == "Memory allocation failed");
assert(oome.toString.length);
}

{
Expand Down Expand Up @@ -269,7 +276,13 @@ class InvalidMemoryOperationError : Error

override string toString() const @trusted
{
return msg.length ? (cast()super).toString() : "Invalid memory operation";
return msg.length ? (cast()this).superToString() : "Invalid memory operation";
}

// kludge to call non-const super.toString
private string superToString() @trusted
{
return super.toString();
}
}

Expand All @@ -281,6 +294,7 @@ unittest
assert(oome.line == __LINE__ - 2);
assert(oome.next is null);
assert(oome.msg == "Invalid memory operation");
assert(oome.toString.length);
}

{
Expand Down

0 comments on commit 2db5144

Please sign in to comment.