[Shapelib] possible bug when reading the boundaries ?

Frank Warmerdam warmerdam at pobox.com
Wed May 19 12:41:46 EDT 2004

Stephane Routelous wrote:
> Hi,
> I'm investigating using ShapeLib instead of our own library because of
> performace issues.
> I think I found a bug in the code for reading the bounds of a shape file in
> SHPOpen
> at line 448, you have :
>     fread( pabyBuf, 100, 1, psSHP->fpSHX );
> meaning that you are reading informations from the shx file.
> But after, you are reading the bounds with :
>     if( bBigEndian ) SwapWord( 8, pabyBuf+36 ); //line 480
>     memcpy( &dValue, pabyBuf+36, 8 );
>     psSHP->adBoundsMin[0] = dValue;
> it means that the bounds are read from the SHX file, but according to the
> specifications, the bounds are in the SHP file.
> So, I think you should move the reading of the boundaries before the line
> 448.


Generally speaking the first 100 byte header of the SHP and SHX files are
the same.  One could argue about which should be consider "more authoritative"
if they differ but I haven't really run into a problem with this so I am not
inclined to change it for hypothetical reasons.

Have you actually encountered a problem with this code?

Best regards,
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent

More information about the Shapelib mailing list