Bug 13276 – No overlap or length equality test in compiler generated array operations
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-08-10T11:28:00Z
Last change time
2014-08-10T12:54:09Z
Keywords
wrong-code
Assigned to
nobody
Creator
verylonglogin.reg
Comments
Comment #0 by verylonglogin.reg — 2014-08-10T11:28:36Z
Compiler generated array operations truncates second (and third if any) slice length to the first slice length and has no overlap check.
This code should NOT run fine:
---
void main()
{
alias T = short;
T[] a2 = new T[2];
T[] a3 = (new T[3])[] = 1;
T[] b2 = new T[2];
T[] b3 = new T[3];
// a2[] += a3[]; // ok, throws as runtime function called
// a3[] -= a2[]; // ok, throws
// b3[] = a2[] - a3[]; // ok, throws
// b3[] = a3[] - a2[]; // ok, throws
// Should throw:
// (same for '*', '/', '^', '&', and '|')
a2[] -= a3[];
a2[] -= a2[];
b2[] = a2[] - a3[];
b2[] = a3[] - a2[];
}
---
Comment #1 by verylonglogin.reg — 2014-08-10T11:30:41Z
Small correction:
'*' array operation uses runtime function if type is an integer except 'byte'/'ubyte'.
Comment #2 by yebblies — 2014-08-10T11:58:29Z
bug 2547?
Comment #3 by verylonglogin.reg — 2014-08-10T12:54:09Z
(In reply to yebblies from comment #2)
> bug 2547?
Yep.
*** This issue has been marked as a duplicate of issue 2547 ***