Bug 653 – AAs are slightly broken

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2006-12-05T11:09:00Z
Last change time
2014-02-15T13:22:03Z
Assigned to
bugzilla
Creator
mslenc

Comments

Comment #0 by mslenc — 2006-12-05T11:09:47Z
import std.stdio; void main() { int[uint] aa; aa[1236448822] = 0; aa[2716102924] = 1; aa[ 315901071] = 2; aa.remove(1236448822); writefln(aa[2716102924]); } ======================== The reason it happens is in aaA.d: int c = key_hash - e.hash; //... if (c < 0) { e = e.left; } else { e = e.right; } If key_hash is bigger than e.hash + int.max, this will incorrectly determine that it is in fact smaller. The loop should be changed to something like while (e) { if (key_hash == e.hash) { int c = keyti.compare(pkey, e + 1); if (c) { e = c < 0 ? e.left : e.right; } else { return cast(void *)(e + 1) + keysize; } } else { e = key_hash < e.hash ? e.left : e.right; } }
Comment #1 by thomas-dloop — 2006-12-06T08:30:39Z
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 [email protected] schrieb am 2006-12-05: > http://d.puremagic.com/issues/show_bug.cgi?id=653 > import std.stdio; > > void main() > { > int[uint] aa; > > aa[1236448822] = 0; > aa[2716102924] = 1; > aa[ 315901071] = 2; > > aa.remove(1236448822); > writefln(aa[2716102924]); > } > >======================== > > The reason it happens is in aaA.d: <snip> Added to DStress as http://dstress.kuehne.cn/run/a/associative_array_20_A.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFFdrJSLK5blCcjpWoRAjQdAKCS9JQ83XzP4+sZauiiWoSh+AJLwACfdicv KCf6KvzSB+CXziDxqTaloJg= =4Zse -----END PGP SIGNATURE-----
Comment #2 by bugzilla — 2006-12-12T04:16:53Z
Fixed DMD 0.176