D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 95 - foreach() over uninitalized AA yields Access Violation
Summary: foreach() over uninitalized AA yields Access Violation
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P2 normal
Assignee: Walter Bright
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2006-04-08 16:04 UTC by Eric Anderton (aka Pragma)
Modified: 2021-05-27 12:58 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Eric Anderton (aka Pragma) 2006-04-08 16:04:56 UTC
Under Windows, using foreach to iterate over an uninitalized AA generates an Access Violation.

//////////////////////////
import std.stdio;

void main(){
	uint[char[]] foobar;
	foreach(value; foobar){} // fails on foreach
}
Comment 1 Thomas Kühne 2006-04-09 02:00:27 UTC
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

d-bugmail@puremagic.com schrieb am 2006-04-08:
> http://d.puremagic.com/bugzilla/show_bug.cgi?id=95
> Under Windows, using foreach to iterate over an uninitalized AA generates an
> Access Violation.
>
> //////////////////////////
> import std.stdio;
>
> void main(){
>         uint[char[]] foobar;
>         foreach(value; foobar){} // fails on foreach
> }

Added to DStress as
http://dstress.kuehne.cn/run/f/foreach_35_A.d
http://dstress.kuehne.cn/run/f/foreach_35_B.d
http://dstress.kuehne.cn/run/f/foreach_35_C.d

Thomas


-----BEGIN PGP SIGNATURE-----

iD8DBQFEOLO93w+/yD4P9tIRAne3AKCXwPswPGm1bsXzgT7M1nyWFEerBACfQew2
mr8hcIW+GAmLszLrEW5kwDM=
=p/7L
-----END PGP SIGNATURE-----

Comment 2 Stewart Gordon 2006-04-09 06:52:36 UTC
I experimented with this a bit after it broke a bit of SDWF.  It happens only if the AA is actually uninitialised - if you've added something to the AA and then deleted it then it behaves correctly.
Comment 3 Thomas Kühne 2006-04-09 15:00:18 UTC
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

d-bugmail@puremagic.com schrieb am 2006-04-09:
> http://d.puremagic.com/bugzilla/show_bug.cgi?id=95
> ------- Comment #2 from smjg@iname.com  2006-04-09 06:52 -------
> I experimented with this a bit after it broke a bit of SDWF.  It happens only
> if the AA is actually uninitialised - if you've added something to the AA and
> then deleted it then it behaves correctly.

Added to DStress as
http://dstress.kuehne.cn/run/f/foreach_35_D.d

Thomas


-----BEGIN PGP SIGNATURE-----

iD8DBQFEOWOQ3w+/yD4P9tIRAo6BAJ9QRbbynIICx23H8UY++fHYCrAhbwCdF7Px
AegIgXpNCy/EssV8sNYqRVc=
=43pG
-----END PGP SIGNATURE-----

Comment 4 Walter Bright 2006-04-11 01:34:57 UTC
Fixed 0.153
Comment 5 Dlang Bot 2021-05-27 12:58:15 UTC
dlang/dlang-bot pull request #271 "Fixes so far" was merged into master:

- 284d4c4740655425ef1a98e29a7dd916dbd6f930 by Vladimir Panteleev:
  Tag Enhancement and Bug in the same pull request
  
  Fixes #95.

https://github.com/dlang/dlang-bot/pull/271