[geos-devel] Re: [GEOS] #202: Undefined behavior in Coordinate::hashCode

GEOS geos-trac at osgeo.org
Fri Aug 29 17:00:48 EDT 2008


#202: Undefined behavior in Coordinate::hashCode
------------------------------------+---------------------------------------
 Reporter:  mloskot                 |        Owner:  geos-devel at lists.osgeo.org
     Type:  defect                  |       Status:  new                       
 Priority:  major                   |    Milestone:                            
Component:  Core                    |      Version:  svn-trunk                 
 Severity:  Significant             |   Resolution:                            
 Keywords:  coordinate hash double  |  
------------------------------------+---------------------------------------
Comment (by mloskot):

 Ben,

 The doc is C++ ISO/IEC 14882:2003 (6.10 lvalues and rvalues, paragraph
 15). Also, chapter 6.5 and paragraph 7 of ISO 9899:1999 defines aliasing
 rules for C language.

 Shortly, the rule is as simple as:

  ''Pointers of different types (say int* and float*) can’t point to the
 same object''

 It was very well explained in presentation by Andrey Bokhanko and
 Alexander Isaev from Intel Labs
 ([http://www.ice.gelato.org/oct07/pres_pdf/gelato_ICE07oct_aliasing_isaev_intel.pdf
 PDF])

 If standards are too heavy, then Wikipedia is handy, see
 [http://en.wikipedia.org/wiki/Type_punning#Floating-point_example Type
 punning] article and floating-point example based on your suggestion and
 commented this way:

  ''this kind of type punning is more dangerous than most''

 Just to give an example of how dangerous this kind of hack can be, here is
 [http://trac.osgeo.org/gdal/ticket/2521 my story of finding root of a very
 strange bug] in GDAL that took me hours :-)

-- 
Ticket URL: <http://trac.osgeo.org/geos/ticket/202#comment:3>
GEOS <http://geos.refractions.net/>
GEOS (Geometry Engine - Open Source) is a C++ port of the Java Topology Suite (JTS).


More information about the geos-devel mailing list