summaryrefslogtreecommitdiff
path: root/oss-fuzz/fuzzing/datasource/id.hpp
diff options
context:
space:
mode:
authorErik de Castro Lopo <erikd@mega-nerd.com>2019-11-17 16:08:07 +1100
committerErik de Castro Lopo <erikd@mega-nerd.com>2019-11-18 06:29:10 +1100
commitb19f3a6114c8d6d98905c3ae8ae51eda84680918 (patch)
tree98b00a70241c4a0926fb43da7f128fe8e694aac8 /oss-fuzz/fuzzing/datasource/id.hpp
parent888ea869a7b0f8e1123480837c0b19ff9537120f (diff)
downloadflac-b19f3a6114c8d6d98905c3ae8ae51eda84680918.tar.gz
oss-fuzz: Add fuzzing headers
These includes header files were taken from: https://github.com/guidovranken/fuzzing-headers.git with some minor changes required to make them compile cleanly with the extra compiler warning flags used by the FLAC build system.
Diffstat (limited to 'oss-fuzz/fuzzing/datasource/id.hpp')
-rw-r--r--oss-fuzz/fuzzing/datasource/id.hpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/oss-fuzz/fuzzing/datasource/id.hpp b/oss-fuzz/fuzzing/datasource/id.hpp
new file mode 100644
index 00000000..3ba38d71
--- /dev/null
+++ b/oss-fuzz/fuzzing/datasource/id.hpp
@@ -0,0 +1,52 @@
+#pragma once
+
+#include <stdio.h>
+#include <stdint.h>
+#include <utility>
+#include <map>
+
+namespace fuzzing {
+namespace datasource {
+
+/* From: https://gist.github.com/underscorediscovery/81308642d0325fd386237cfa3b44785c */
+inline uint64_t hash_64_fnv1a(const void* key, const uint64_t len) {
+
+ const char* data = (char*)key;
+ uint64_t hash = 0xcbf29ce484222325;
+ uint64_t prime = 0x100000001b3;
+
+ for(uint64_t i = 0; i < len; ++i) {
+ uint8_t value = data[i];
+ hash = hash ^ value;
+ hash *= prime;
+ }
+
+ return hash;
+
+} //hash_64_fnv1a
+
+// FNV1a c++11 constexpr compile time hash functions, 32 and 64 bit
+// str should be a null terminated string literal, value should be left out
+// e.g hash_32_fnv1a_const("example")
+// code license: public domain or equivalent
+// post: https://notes.underscorediscovery.com/constexpr-fnv1a/
+
+constexpr uint32_t val_32_const = 0x811c9dc5;
+constexpr uint32_t prime_32_const = 0x1000193;
+constexpr uint64_t val_64_const = 0xcbf29ce484222325;
+constexpr uint64_t prime_64_const = 0x100000001b3;
+
+
+inline constexpr uint64_t ID(const char* const str, const uint64_t value = val_64_const) noexcept {
+ auto ret = (str[0] == '\0') ? value : ID(&str[1], (value ^ uint64_t(str[0])) * prime_64_const);
+ return ret;
+}
+
+inline constexpr std::pair<const char*, uint64_t> IDPair(const char* const str, const uint64_t value = val_64_const) noexcept {
+ return {str, ID(str, value)};
+}
+
+using IDMap = std::map<const char*, uint64_t>;
+
+} /* namespace datasource */
+} /* namespace fuzzing */