Bug 7762 – Possible bug in std.algorithm.sort(ubyte[])

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2012-03-24T09:39:00Z
Last change time
2015-06-09T05:14:51Z
Keywords
rejects-valid
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2012-03-24T09:39:41Z
This program causes a segfault about 30-50% of the times it is run, on Windows 32 bit dmd 2.059head: Compile with: dmd -property -g -wi test.d import std.stdio, std.algorithm, std.random; void main() { immutable digits = "0123456789"; enum nLoops = 5_000_000; enum maxLen = 20; char[maxLen] items; auto rnd = Xorshift(); rnd.seed(0); foreach (i; 0 .. nLoops) { immutable len = uniform(0, maxLen, rnd); foreach (j; 0 .. len) items[j] = digits[uniform(0, digits.length, rnd)]; string ns = items[0 .. len].idup; ns = cast(string)(cast(ubyte[])ns.dup).sort().release(); } } The stack trace: object.Error: Access Violation ---------------- ...\dmd2\src\phobos\std\algorithm.d(7283): bool std.algorithm.__T8isSortedS593std10functional31__T9binaryFunVAyaa5_61203c2062Z9binaryFunTAhZ.isSorted(ubyte[]) ...\dmd2\src\phobos\std\algorithm.d(6744): D3std9algorithm60__T4sortVAyaa5_61203cÙ62VE€Ž«12SwapStrategy0TAhZ€…¹F€ƒ‰S€„«5range37€ƒÒ11S€ƒšedR€„’€ƒª€‘ÝZ€¢ ...\test.d(14): _Dmain ---------------- The bug disappears if you remove ".sort().release()". Maybe it doesn't crash wi ldc2 linux 64, dmd-front-end 2.058 (I don't know what compilation switches).
Comment #1 by andy — 2015-01-27T02:47:05Z
I ran the test code using dmd 2.066.1 on linux x64 and windows x64 (neither was the reported hardware, so not closing) I ran it 10 times in a row and got no crash. Can anyone try it on windows x86?
Comment #2 by zeljko.grk — 2015-01-27T03:28:12Z
2.66.1 win7 dmd -property -g -wi test.d everything ok master dmd -property -g -wi test.d can not compile dmd -g -wi test.d everything ok
Comment #3 by bearophile_hugs — 2015-01-27T12:11:13Z
I can't detect this problem any more, closed issue.