diff --git a/include/simdjson/common_defs.h b/include/simdjson/common_defs.h index a485e28b5..44fcef7b0 100644 --- a/include/simdjson/common_defs.h +++ b/include/simdjson/common_defs.h @@ -31,8 +31,6 @@ #define ISALIGNED_N(ptr, n) (((uintptr_t)(ptr) & ((n)-1)) == 0) #ifdef _MSC_VER -// Visual Studio won't allow it: -//#define ALLOW_SAME_PAGE_BUFFER_OVERRUN #define really_inline inline #define never_inline __declspec(noinline) @@ -48,10 +46,11 @@ #else -// for non-Visual Studio compilers, we assume that same-page buffer overrun is fine: -#ifndef ALLOW_SAME_PAGE_BUFFER_OVERRUN -#define ALLOW_SAME_PAGE_BUFFER_OVERRUN -#endif +// For non-Visual Studio compilers, we may assume that same-page buffer overrun is fine. +// However, it will make it difficult to be "valgrind clean". +//#ifndef ALLOW_SAME_PAGE_BUFFER_OVERRUN +//#define ALLOW_SAME_PAGE_BUFFER_OVERRUN +//#endif // The following is likely unnecessarily complex. #ifdef __SANITIZE_ADDRESS__ diff --git a/src/parsedjson.cpp b/src/parsedjson.cpp index b18b5b7d1..c5707c7d2 100644 --- a/src/parsedjson.cpp +++ b/src/parsedjson.cpp @@ -74,7 +74,13 @@ bool ParsedJson::allocateCapacity(size_t len, size_t maxdepth) { return false; } - + /* + // We do not need to initialize this content for parsing, though we could + // need to initialize it for safety. + memset(string_buf, 0 , localstringcapacity); + memset(structural_indexes, 0, max_structures * sizeof(uint32_t)); + memset(tape, 0, localtapecapacity * sizeof(uint64_t)); + */ bytecapacity = len; depthcapacity = maxdepth; tapecapacity = localtapecapacity; diff --git a/src/stage2_build_tape.cpp b/src/stage2_build_tape.cpp index f3bf15b66..3b3b1a458 100644 --- a/src/stage2_build_tape.cpp +++ b/src/stage2_build_tape.cpp @@ -72,6 +72,9 @@ really_inline bool is_valid_null_atom(const uint8_t *loc) { ***********/ WARN_UNUSED ALLOW_SAME_PAGE_BUFFER_OVERRUN_QUALIFIER LENIENT_MEM_SANITIZER int unified_machine(const uint8_t *buf, size_t len, ParsedJson &pj) { +#ifndef ALLOW_SAME_PAGE_BUFFER_OVERRUN + memset((uint8_t*)buf + len, 0, SIMDJSON_PADDING); // to please valgrind +#endif uint32_t i = 0; // index of the structural character (0,1,2,3...) uint32_t idx; // location of the structural character in the input (buf) uint8_t c; // used to track the (structural) character we are looking at, updated