[Shapelib] DBFCloneEmtpy bug and resolution

shapelib-admin at lists.maptools.org shapelib-admin at lists.maptools.org
Tue Mar 16 08:59:57 PST 2004


Frank, et al.:

I believe I have found and resolved a bug in shapelib's DBFCloneEmpty 
function.  I was finding that dbf files created with this function were 
improperly created and could not be opened, because the "cloned" files 
were missing a 0x0d-valued byte at the end of the header section.  As it 
turns out, the culprit was the assignment of nHeaderLength in 
DBFCloneEmpty:

        newDBF->nHeaderLength = 32 * (psDBF->nFields+1);  // incorrect
 
When a new dbf is created with DBFCreate, nHeaderLength is given an 
initial value of:

        psDBF->nHeaderLength = 33;
 
Subsequent calls to DBFAddField increment nHeaderLength by 32, as

        psDBF->nHeaderLength += 32;
 
Therefore, the correct assignment of nHeaderLength in DBFCloneEmpty is:

        newDBF->nHeaderLength = 33 + 32 * (psDBF->nFields);  // correct
 

After this modification, cloded dbf files are written correctly.

Best regards,

David Gancarz



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/shapelib/attachments/20040316/70686d88/attachment.html>


More information about the Shapelib mailing list