Bug 16654 – hashOf returns different hashes for the same string value

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2016-11-01T18:08:00Z
Last change time
2017-01-16T23:24:38Z
Assigned to
nobody
Creator
dev

Comments

Comment #0 by dev — 2016-11-01T18:08:00Z
The following assert fails: import std.stdio; import std.conv; void main(string[] args) { auto x = 1; assert(hashOf(x.to!(string)) == hashOf(x.to!(string))); } This is because numeric values of the pointers to the strings are being included in the hash calculation. Discussion: http://forum.dlang.org/post/[email protected]
Comment #1 by schveiguy — 2016-11-03T13:55:23Z
As I determined in that thread, note that core.internal.hash.hashOf does not do the same thing as object.hashOf. It hashes only the bits of the given type. I can't think of a single valid reason for hashing the pointer and length of an array instead of the contents of the array. I don't know the right answer here, but at the very least hashOf isn't documented or understood properly.
Comment #2 by schveiguy — 2016-11-03T13:56:06Z
(In reply to Steven Schveighoffer from comment #1) > As I determined in that thread, note that core.internal.hash.hashOf does not > do the same thing as object.hashOf. It hashes only the bits of the given > type. It being object.hashOf. core.internal.hash.hashOf does a more reasonable thing.
Comment #3 by github-bugzilla — 2016-12-04T16:51:45Z
Commit pushed to stable at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/5c187e05ff87404ebf4884cfc548324c2c3ed0fc Revert object.hashOf changes from "use array interface to hashOf()" fixes issues 16654 & 16764.
Comment #4 by github-bugzilla — 2016-12-09T00:27:13Z
Commit pushed to master at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/5c187e05ff87404ebf4884cfc548324c2c3ed0fc Revert object.hashOf changes from "use array interface to hashOf()"
Comment #5 by github-bugzilla — 2016-12-27T13:11:11Z
Commit pushed to scope at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/5c187e05ff87404ebf4884cfc548324c2c3ed0fc Revert object.hashOf changes from "use array interface to hashOf()"
Comment #6 by github-bugzilla — 2017-01-07T03:02:11Z
Commit pushed to stable at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/5c187e05ff87404ebf4884cfc548324c2c3ed0fc Revert object.hashOf changes from "use array interface to hashOf()"
Comment #7 by github-bugzilla — 2017-01-16T23:24:38Z
Commit pushed to newCTFE at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/5c187e05ff87404ebf4884cfc548324c2c3ed0fc Revert object.hashOf changes from "use array interface to hashOf()" fixes issues 16654 & 16764.