![]() |
||||
|
|
||||
[Shapelib] DBFCloneEmtpy bug and resolutionshapelib@lists.maptools.org shapelib@lists.maptools.orgTue, 16 Mar 2004 11:59:57 -0500
|
||||
This is a multipart message in MIME format.
--=_alternative 005D61D885256E59_=
Content-Type: text/plain; charset="US-ASCII"
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
--=_alternative 005D61D885256E59_=
Content-Type: text/html; charset="US-ASCII"
<br><font size=2 face="sans-serif">Frank, et al.:</font>
<br>
<br><font size=2 face="sans-serif">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:</font>
<br>
<br><font size=2 face="sans-serif"> newDBF->nHeaderLength
= 32 * (psDBF->nFields+1); // incorrect</font>
<br><font size=2 face="sans-serif"> </font>
<br><font size=2 face="sans-serif">When a new dbf is created with DBFCreate,
nHeaderLength is given an initial value of:</font>
<br>
<br><font size=2 face="sans-serif"> psDBF->nHeaderLength
= 33;</font>
<br><font size=2 face="sans-serif"> </font>
<br><font size=2 face="sans-serif">Subsequent calls to DBFAddField increment
nHeaderLength by 32, as</font>
<br>
<br><font size=2 face="sans-serif"> psDBF->nHeaderLength
+= 32;</font>
<br><font size=2 face="sans-serif"> </font>
<br><font size=2 face="sans-serif">Therefore, the correct assignment of
nHeaderLength in DBFCloneEmpty is:</font>
<br>
<br><font size=2 face="sans-serif"> newDBF->nHeaderLength
= 33 + 32 * (psDBF->nFields); // correct</font>
<br><font size=2 face="sans-serif"> </font>
<br>
<br><font size=2 face="sans-serif">After this modification, cloded dbf
files are written correctly.</font>
<br>
<br><font size=2 face="sans-serif">Best regards,</font>
<br>
<br><font size=2 face="sans-serif">David Gancarz</font>
<br>
<br>
<br>
<br>
--=_alternative 005D61D885256E59_=--
This archive was generated by Pipermail. |
MapTools.org -- Hosted by DM Solutions Group |