Bug 800 – writefln() on an associative array fails hard

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P2
Component
phobos
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2007-01-06T14:06:00Z
Last change time
2014-02-15T13:12:42Z
Keywords
patch
Assigned to
bugzilla
Creator
matti.niemenmaa+dbugzilla
Depends on
761

Attachments

IDFilenameSummaryContent-TypeSize
90format_putAArray.patchPatch for std.format to dump contents of Associative Arraystext/plain1477
100bug_800_align.patchPatch to align the address of the valuetext/plain700

Comments

Comment #0 by matti.niemenmaa+dbugzilla — 2007-01-06T14:06:16Z
import std.stdio; void main() { int[int] foo; foo[1] = 2; writefln("%s", foo); } This outputs "[", some seemingly-random numbers including hundreds of zeroes, and dies in an Access Violation. It looks like it's reading memory in the completely wrong place, possibly treating the AA as a dynamic array.
Comment #1 by lio+bugzilla — 2007-01-07T01:09:09Z
Apparently, the type-info of an AA changed. std/format.d uses the character at index [9] to identify the type, and it used to be 'H' (HashTable?), but now it's 'A', same as normal arrays: int[] => TypeInfo_Ai int[int] => TypeInfo_AssociativeArray
Comment #2 by lio+bugzilla — 2007-01-07T02:00:58Z
Created attachment 90 Patch for std.format to dump contents of Associative Arrays This patch adds putAArray to std.format.doFormat. It prints the contents of an AA similar to python: {key:value,key2:value2} (D had no literal AA syntax, so I didn't know what to pick instead)
Comment #3 by lio+bugzilla — 2007-01-07T02:05:55Z
Important: if the doFormat patch from issue 652 or 761 is applied, putAArray should also call doFormat with the 'parse' parameter set to false! This prevents any "%" in either key or value strings from being interpreted (resulting in the bug from issue 761)
Comment #4 by bugzilla — 2007-02-03T00:51:06Z
*** Bug 801 has been marked as a duplicate of this bug. ***
Comment #5 by dvdfrdmn — 2007-02-10T11:41:21Z
Created attachment 100 Patch to align the address of the value
Comment #6 by dvdfrdmn — 2007-02-10T11:42:35Z
The patch in #2 does not take alignment of the value into account. The following prints "[a:50331648]" ---- import std.format; import std.string; void main() { int[char] m; m['a'] = 3; assert(find(format("%s",m), "a:3") != -1); } ---- Attached an example patch that fixes the problem, but I don't think copying from aaA.d is a good idea.
Comment #7 by bugzilla — 2007-02-12T03:37:36Z
Fixed DMD 1.005