basmith / sparsehash

Automatically exported from code.google.com/p/sparsehash
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

problem while searching value in dense_hash_map #85

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.i have create  by google::dense_hash_map<char*, char*> dmap; golbally
2.call insert keys &values by using dmap[key]=value;
3.use dmap.find(key)in another function but getting garbage value

What is the expected output? What do you see instead?

 want the value of correspoing key
What version of the product are you using? On what operating system?
on linunx redhat

Please provide any additional information below.

attached code below

Original issue reported on code.google.com by praj.cha...@gmail.com on 28 Jun 2012 at 1:14

Attachments:

GoogleCodeExporter commented 9 years ago
You need to manage the string storage on your own; dense_hash_map doesn't do 
that for you. (Nor does STL hash_map or similar.) For example, this code has a 
"dangling pointer" bug:

hash_map<char*, char*> m;
{
  char tmp[10];
  tmp[0] = 'a';
  tmp[1] = '\0';
  m[tmp] = tmp;
}
puts(m["a"]);

By the way, tools such as valgrind and purify can find most bugs like these.

Original comment by gp...@google.com on 28 Jun 2012 at 3:44

GoogleCodeExporter commented 9 years ago
Hi,
But Keys & values are inserted properly into the map but problem is
their in retrieving it

Original comment by praj.cha...@gmail.com on 29 Jun 2012 at 4:35