diff --git a/Makefile b/Makefile index 7857110..18a14e7 100644 --- a/Makefile +++ b/Makefile @@ -2,21 +2,25 @@ CC = g++ CFLAGS_DEFAULT = -march=native -std=c++23 -CFLAGS_DEBUG = -Wall -Werror -Wno-uninitialized -O0 -fanalyzer -ggdb -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -CFLAGS_RELEASE = -static-libgcc -static-libstdc++ -static -Ofast -fdevirtualize-speculatively -fdata-sections -ffunction-sections -Wl,-gc-sections -Wl,-strip-all -Wl,-strip-discarded -flto -s -D_FORTIFY_SOURCE=2 +CFLAGS_DEBUG = -Wall -Werror -Wno-uninitialized -Wno-analyzer-use-of-uninitialized-value -fanalyzer -ggdb +CFLAGS_DEBUG_S = -O0 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow +CFLAGS_DEBUG_F = -O1 -D_FORTIFY_SOURCE=3 +CFLAGS_RELEASE = -static-libgcc -static-libstdc++ -static -Ofast -fdevirtualize-speculatively -fdata-sections -ffunction-sections -Wl,-gc-sections -Wl,-strip-all -Wl,-strip-discarded -flto -s -D_FORTIFY_SOURCE=3 SOURCES = src/stadium.hpp src/stadium.cpp src/kldr.hpp SOURCES_TEST = src/test.cpp #LINKED_LIBS = -l OUTPUT_LIB = libstadium.so -OUTPUT_TEST_BIN = libstadiumtest +OUTPUT_TEST_BIN_S = libstadiumtest_sanitizer +OUTPUT_TEST_BIN_F = libstadiumtest_fortified default: clean release_test debug_test: $(SOURCES) $(SOURCES_TEST) - $(CC) $(CFLAGS_DEFAULT) $(CFLAGS_DEBUG) $(SOURCES) $(SOURCES_TEST) -o $(OUTPUT_TEST_BIN) + $(CC) $(CFLAGS_DEFAULT) $(CFLAGS_DEBUG) $(CFLAGS_DEBUG_S) $(SOURCES) $(SOURCES_TEST) -o $(OUTPUT_TEST_BIN_S) + $(CC) $(CFLAGS_DEFAULT) $(CFLAGS_DEBUG) $(CFLAGS_DEBUG_F) $(SOURCES) $(SOURCES_TEST) -o $(OUTPUT_TEST_BIN_F) #$(LINKED_LIBS) debug: $(SOURCES) @@ -30,5 +34,4 @@ release: $(SOURCES) clean: - rm -f $(OUTPUT_LIB) - rm -f $(OUTPUT_TEST_BIN) \ No newline at end of file + rm -f $(OUTPUT_LIB) $(OUTPUT_TEST_BIN_S) $(OUTPUT_TEST_BIN_F) \ No newline at end of file diff --git a/libstadiumtest b/libstadiumtest deleted file mode 100755 index 2361656..0000000 Binary files a/libstadiumtest and /dev/null differ diff --git a/src/kldr.hpp b/src/kldr.hpp index 921aaa6..2dd0242 100644 --- a/src/kldr.hpp +++ b/src/kldr.hpp @@ -166,22 +166,20 @@ class KLDRArray { return false; } - // Add new cell to array, fast version without keys check + // Add new cell to array, fast version without key checks void AddF (KeyT key, LengthT length, void* data) { this->Keys.push_back(key); this->Lengths.push_back(length); void* newData = operator new(length); // Yes, allocating memory for void pointer really looks like this - std::copy((uint8_t*)data, (uint8_t*)data + length, (uint8_t*)newData); // Dirty hacks, YES! + std::copy((char*)data, (char*)data + length, (char*)newData); // Dirty hacks, YES! this->Values.push_back(newData); // NOTICE: there is `std::is_pod()`, so may be we can use one more template to make this a little more safe (may be) } + // Add new cell to array, but only if key is unique void Add (KeyT key, LengthT length, void* data) { - for (size_t i = 0; i < this->CellsAmount(); i++) { - if (this->Keys[i] == key) { + if (this->KeyExists(key)) throw std::invalid_argument("supplied key already exist"); - } - } this->AddF(key, length, data); }