Skip to content

Commit

Permalink
Must not swap double type
Browse files Browse the repository at this point in the history
  • Loading branch information
thbeu committed Jan 29, 2024
1 parent 2fe90cd commit 0a78a05
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
14 changes: 7 additions & 7 deletions sbnsearch.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,18 @@ SBNSearchHandle SBNOpenDiskTree(const char *pszSBNFilename,
/* Read shapes bounding box. */
/* -------------------------------------------------------------------- */

#if !defined(SHP_BIG_ENDIAN)
SHP_SWAP64(abyHeader + 32);
SHP_SWAP64(abyHeader + 40);
SHP_SWAP64(abyHeader + 48);
SHP_SWAP64(abyHeader + 56);
#endif

memcpy(&hSBN->dfMinX, abyHeader + 32, 8);
memcpy(&hSBN->dfMinY, abyHeader + 40, 8);
memcpy(&hSBN->dfMaxX, abyHeader + 48, 8);
memcpy(&hSBN->dfMaxY, abyHeader + 56, 8);

#if !defined(SHP_BIG_ENDIAN)
SHP_SWAP64(&hSBN->dfMinX);
SHP_SWAP64(&hSBN->dfMinY);
SHP_SWAP64(&hSBN->dfMaxX);
SHP_SWAP64(&hSBN->dfMaxY);
#endif

if (hSBN->dfMinX > hSBN->dfMaxX || hSBN->dfMinY > hSBN->dfMaxY)
{
hSBN->sHooks.Error("Invalid extent in .sbn file.");
Expand Down
26 changes: 15 additions & 11 deletions shptree.c
Original file line number Diff line number Diff line change
Expand Up @@ -734,18 +734,22 @@ static bool SHPSearchDiskTreeNode(SHPTreeDiskHandle hDiskTree,
if (bNeedSwap)
SHP_SWAP32(&offset);

nFReadAcc += STATIC_CAST(int, hDiskTree->sHooks.FRead(adfNodeBoundsMin,
sizeof(double), 2,
hDiskTree->fpQIX));
nFReadAcc += STATIC_CAST(int, hDiskTree->sHooks.FRead(adfNodeBoundsMax,
sizeof(double), 2,
hDiskTree->fpQIX));
if (bNeedSwap)
{
SHP_SWAP64(adfNodeBoundsMin + 0);
SHP_SWAP64(adfNodeBoundsMin + 1);
SHP_SWAP64(adfNodeBoundsMax + 0);
SHP_SWAP64(adfNodeBoundsMax + 1);
uint64_t tempVal[4];
nFReadAcc += STATIC_CAST(
int, hDiskTree->sHooks.FRead(adfNodeBoundsMin, sizeof(uint64_t), 4,
hDiskTree->fpQIX));
if (bNeedSwap)
{
SHP_SWAP64(tempVal + 0);
SHP_SWAP64(tempVal + 1);
SHP_SWAP64(tempVal + 2);
SHP_SWAP64(tempVal + 3);
}
memcpy(adfNodeBoundsMin + 0, tempVal + 0, 8);
memcpy(adfNodeBoundsMin + 1, tempVal + 1, 8);
memcpy(adfNodeBoundsMax + 0, tempVal + 2, 8);
memcpy(adfNodeBoundsMax + 1, tempVal + 3, 8);
}

nFReadAcc += STATIC_CAST(
Expand Down

0 comments on commit 0a78a05

Please sign in to comment.