void pointer and map (fwd)

Andrew Haley aph@redhat.com
Fri Dec 21 13:17:00 GMT 2007


Anitha Boyapati writes:
 > 
 >
 > Below is a minimisation of a larger program (that may explain why the 
 > objective of the progarm is not too clear). The essence is I am trying to 
 > do a map find with a structure as key and the significant aspect of the 
 > structure is - it has a void *. I expect the below progarm to print 
 > nothing as s2 is not there on the map at all! There are 2 findings 
 > however:
 > 
 >  1. "Address found" is getting printed
 >  2. Segmentation fault occurs.

You're passing an instance of Value to Map::value_type, which creates
a pair instance by copying both the key and the value.  Note that we
now have two instances of Value, both of which are pointing to the
same buf.  operator delete will be called on both of these instances.

Andrew.

-- 
Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SL4 1TE, UK
Registered in England and Wales No. 3798903



More information about the Gcc-help mailing list