diff --git a/include/rapidjson/schema.h b/include/rapidjson/schema.h index 973e935f1..aae361462 100644 --- a/include/rapidjson/schema.h +++ b/include/rapidjson/schema.h @@ -357,7 +357,11 @@ class Hasher { } bool String(const Ch* str, SizeType len, bool) { - WriteBuffer(kStringType, str, len * sizeof(Ch)); + if (len == 0) { + WriteType(kStringType); + } else { + WriteBuffer(kStringType, str, len * sizeof(Ch)); + } return true; } @@ -401,18 +405,26 @@ class Hasher { double d; }; - bool WriteType(Type type) { return WriteBuffer(type, 0, 0); } + bool WriteType(Type type) { + uint64_t h = Hash(RAPIDJSON_UINT64_C2(0xcbf29ce4, 0x84222325), type); + *stack_.template Push() = h; + return true; + } bool WriteNumber(const Number& n) { return WriteBuffer(kNumberType, &n, sizeof(n)); } - + bool WriteBuffer(Type type, const void* data, size_t len) { // FNV-1a from http://isthe.com/chongo/tech/comp/fnv/ - uint64_t h = Hash(RAPIDJSON_UINT64_C2(0xcbf29ce4, 0x84222325), type); - const unsigned char* d = static_cast(data); - for (size_t i = 0; i < len; i++) - h = Hash(h, d[i]); - *stack_.template Push() = h; - return true; + if (data != NULL && len != 0) { + uint64_t h = Hash(RAPIDJSON_UINT64_C2(0xcbf29ce4, 0x84222325), type); + const unsigned char* d = static_cast(data); + for (size_t i = 0; i < len; i++) + h = Hash(h, d[i]); + *stack_.template Push() = h; + return true; + } else { + return false; + } } static uint64_t Hash(uint64_t h, uint64_t d) {