3687 – Array operation "slice times scalar" tramples over memory

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3687 - Array operation "slice times scalar" tramples over memory
Summary: Array operation "slice times scalar" tramples over memory
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: druntime (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P2 major
Assignee: Sean Kelly
URL:
Keywords: patch, wrong-code
Depends on:
Blocks:
Reported: 2010年01月07日 13:16 UTC by Clemens
Modified: 2014年04月18日 09:17 UTC (History)
2 users (show)

See Also:


Attachments
patch against druntime to fix the problem (3.18 KB, patch)
2010年01月08日 06:53 UTC, Clemens
Details | Diff
Show Obsolete (1) 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 Clemens 2010年01月07日 13:16:38 UTC
The following code fails with an assertion failure when it clearly shouldn't:
====================================================
void main()
{
 float[64] array;
 int i = 42;
 auto slice = array[];
 slice[] *= 2f;
 assert(i == 42);
}
====================================================
Array bounds checking doesn't catch this. I presume that the code in the runtime to execute this array operation is buggy.
Comment 1 Clemens 2010年01月08日 06:53:11 UTC
Created attachment 548 [details] 
patch against druntime to fix the problem
Comment 2 Clemens 2010年01月08日 06:55:22 UTC
Yes, it is buggy. I've uploaded a patch to fix the routine which does float array times scalar multiplication, though probably it's a better idea to file it at druntime directly. I'll crosspost it there.
Comment 3 Clemens 2010年01月08日 09:20:06 UTC
I've realized that the other float array operations of the form "array op= scalar" suffer from the same problem. Please hold off with applying this patch, I'll provide a more general one. I hope string mixins are ok to use in druntime? There's quite a lot of code duplication in these array modules.
Comment 4 Clemens 2010年01月18日 01:41:19 UTC
I submitted the patch to Tango (since that's what I use currently), it was folded into their copy of the runtime. I would appreciate if someone merged the changes into druntime to keep them in lockstep. Patch and discussion are here:
http://www.dsource.org/projects/tango/ticket/1831 
Comment 5 Don 2010年01月20日 06:56:52 UTC
The original test case passes on D2, but here's a test case which fails on both D1 and D2.
------
void main()
{
 float[66] array;
 array[] = 0;
 array[64] = 42;
 array[65] = 43;
 array[0..64] *= 2f;
 assert(array[65] == 43);
 assert(array[64] == 42);
}
------
Comment 6 Don 2010年01月21日 04:00:30 UTC
Changes checked into druntime svn 234 and D1 phobos svn 1403.
Comment 7 Walter Bright 2010年01月30日 22:41:36 UTC
fixed dmd 1.056 and 2.040


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