Skip to content

Commit 0339d98

Browse files
committed
Fix for fuzzing
1 parent 18f5b1b commit 0339d98

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

flatbush.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ SOFTWARE.
7676

7777
#if defined(FLATBUSH_USE_SIMD)
7878
#pragma message("Using SIMD intrinsics")
79+
#ifdef _MSC_VER
80+
#include <intrin.h>
81+
#endif
7982
#endif
8083

8184
namespace flatbush {

fuzz_from.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,16 @@ std::vector<size_t> calculateNumNodesPerLevel(uint32_t iNumItems, uint32_t iNode
5555
}
5656

5757
template <typename ArrayType>
58-
int from(const uint8_t *iData, size_t iSize) {
58+
int from(const uint8_t* iData, size_t iSize) {
5959
if (iSize < flatbush::gHeaderByteSize) return 0;
6060
if (iData[0] != flatbush::gValidityFlag) return 0;
6161
if ((iData[1] >> 4) != flatbush::gVersion) return 0;
6262
if ((iData[1] & 0x0f) != flatbush::detail::arrayTypeIndex<ArrayType>()) return 0;
63-
const auto wNodeSize = *flatbush::detail::bit_cast<uint16_t *>(&iData[2]);
63+
const auto wNodeSize = *flatbush::detail::bit_cast<uint16_t*>(&iData[2]);
6464
if (wNodeSize < 2) return 0;
6565

66-
const auto wNumItems = *flatbush::detail::bit_cast<uint32_t *>(&iData[4]);
67-
const auto &wLevelBounds = calculateNumNodesPerLevel(wNumItems, wNodeSize);
66+
const auto wNumItems = *flatbush::detail::bit_cast<uint32_t*>(&iData[4]);
67+
const auto& wLevelBounds = calculateNumNodesPerLevel(wNumItems, wNodeSize);
6868
const auto wNumNodes = wLevelBounds.empty() ? wNumItems : wLevelBounds.back();
6969
const auto wIndicesByteSize =
7070
wNumNodes * ((wNumNodes > flatbush::gMaxNumNodes) ? sizeof(uint32_t) : sizeof(uint16_t));
@@ -82,7 +82,7 @@ int from(const uint8_t *iData, size_t iSize) {
8282
return 0;
8383
}
8484

85-
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *iData, size_t iSize) {
85+
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* iData, size_t iSize) {
8686
from<int8_t>(iData, iSize);
8787
from<uint8_t>(iData, iSize);
8888
from<int16_t>(iData, iSize);

fuzz_neighbors.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ SOFTWARE.
2323
*/
2424

2525
#include <cassert>
26+
#include <iostream>
2627

2728
#include "flatbush.h"
2829

fuzz_search.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ flatbush::Flatbush<double> createIndex() {
3535
return wIndex;
3636
}
3737

38-
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *iData, size_t iSize) {
38+
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* iData, size_t iSize) {
3939
static auto sIndex = createIndex();
4040

4141
if (iSize == 32) {
42-
const auto wMinX = *flatbush::detail::bit_cast<const double *>(&iData[0]);
43-
const auto wMinY = *flatbush::detail::bit_cast<const double *>(&iData[8]);
44-
const auto wMaxX = *flatbush::detail::bit_cast<const double *>(&iData[16]);
45-
const auto wMaxY = *flatbush::detail::bit_cast<const double *>(&iData[24]);
42+
const auto wMinX = *flatbush::detail::bit_cast<const double*>(&iData[0]);
43+
const auto wMinY = *flatbush::detail::bit_cast<const double*>(&iData[8]);
44+
const auto wMaxX = *flatbush::detail::bit_cast<const double*>(&iData[16]);
45+
const auto wMaxY = *flatbush::detail::bit_cast<const double*>(&iData[24]);
4646

4747
auto wResult = sIndex.search({wMinX, wMinY, wMaxX, wMaxY});
4848

0 commit comments

Comments
 (0)