CHORE: Bugfixing
This commit is contained in:
@@ -7,6 +7,9 @@ LLVM_PROFDATA := $(LLVM_DIR)/llvm-profdata
|
||||
LLVM_COV := $(LLVM_DIR)/llvm-cov
|
||||
CPPCHECK := cppcheck
|
||||
|
||||
# libstr is populated by CMake's FetchContent (run `cmake -B build` once)
|
||||
LIBSTR_DIR := build/_deps/libstr-src
|
||||
|
||||
# ==============================================================================
|
||||
# Flags & Directories
|
||||
# ==============================================================================
|
||||
@@ -35,6 +38,9 @@ SRCS := src/lib/int/int.c src/lib/utils/utils.c
|
||||
TEST_SRC := tests/test_learn.c
|
||||
FUZZ_SRC := tests/fuzz_char.c
|
||||
|
||||
STRING_SRCS := src/string.c src/utils.c $(LIBSTR_DIR)/src/string.c
|
||||
TEST_STRING_SRC := tests/test_string.c
|
||||
|
||||
BIN_DIR := tests/bin
|
||||
CACHE_DIR := tests/cache
|
||||
|
||||
@@ -42,11 +48,12 @@ TEST_BIN := $(BIN_DIR)/test_learn_runner
|
||||
TSAN_BIN := $(BIN_DIR)/test_tsan_runner
|
||||
FUZZ_BIN := $(BIN_DIR)/fuzz_char_runner
|
||||
COV_BIN := $(BIN_DIR)/test_cov_runner
|
||||
TEST_STRING_BIN := $(BIN_DIR)/test_string_runner
|
||||
|
||||
# ==============================================================================
|
||||
# Targets & Workflow Rules
|
||||
# ==============================================================================
|
||||
.PHONY: all test sanitize check check-sources analyze cppcheck fuzz cov-build cov clean
|
||||
.PHONY: all test test-string sanitize check check-sources analyze cppcheck fuzz cov-build cov clean
|
||||
|
||||
all: test
|
||||
|
||||
@@ -58,6 +65,9 @@ $(BIN_DIR) $(CACHE_DIR):
|
||||
$(TEST_BIN): $(SRCS) $(TEST_SRC) | $(BIN_DIR)
|
||||
$(CC) $(CFLAGS) $(SAN_FLAGS) $(INCLUDES) $^ -o $@
|
||||
|
||||
$(TEST_STRING_BIN): $(STRING_SRCS) $(TEST_STRING_SRC) | $(BIN_DIR)
|
||||
$(CC) $(CFLAGS) $(SAN_FLAGS) $(INCLUDES) -I$(LIBSTR_DIR)/include $^ -o $@
|
||||
|
||||
$(TSAN_BIN): $(SRCS) $(TEST_SRC) | $(BIN_DIR)
|
||||
$(CC) $(CFLAGS) -fsanitize=thread $(INCLUDES) $^ -o $@
|
||||
|
||||
@@ -70,6 +80,10 @@ test: $(TEST_BIN)
|
||||
@echo "=== Running Unit Tests (ASan + UBSan) ==="
|
||||
@$(ASAN_ENV) ./$(TEST_BIN)
|
||||
|
||||
test-string: $(TEST_STRING_BIN)
|
||||
@echo "=== Running vec_string Unit Tests (ASan + UBSan) ==="
|
||||
@$(ASAN_ENV) ./$(TEST_STRING_BIN)
|
||||
|
||||
sanitize: $(TEST_BIN) $(TSAN_BIN)
|
||||
@echo "\n=== [1/2] Running Address + UndefinedBehavior Sanitizers ==="
|
||||
@$(ASAN_ENV) ./$(TEST_BIN)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef CHAR_H
|
||||
#define CHAR_H
|
||||
#ifndef LIBVEC_CHAR_H
|
||||
#define LIBVEC_CHAR_H
|
||||
|
||||
#include <libvec/utils.h>
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef CHAR_H
|
||||
#define CHAR_H
|
||||
#ifndef LIBVEC_FLOAT_H
|
||||
#define LIBVEC_FLOAT_H
|
||||
|
||||
#include <libvec/utils.h>
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef INT_H
|
||||
#define INT_H
|
||||
#ifndef LIBVEC_INT_H
|
||||
#define LIBVEC_INT_H
|
||||
|
||||
#include <libvec/utils.h>
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef CHAR_H
|
||||
#define CHAR_H
|
||||
#ifndef LIBVEC_STRING_H
|
||||
#define LIBVEC_STRING_H
|
||||
|
||||
#include <libstr/string.h>
|
||||
#include <libvec/utils.h>
|
||||
@@ -24,7 +24,7 @@ void
|
||||
vec_string_print_vec(const vec_string* ptr, err_t* err);
|
||||
|
||||
vec_string
|
||||
vec_string_cpy(const char* src, const size_t src_size, err_t* err);
|
||||
vec_string_cpy(const String* src, const size_t src_size, err_t* err);
|
||||
|
||||
void
|
||||
vec_string_push_back(vec_string* ptr, const String val, err_t* err);
|
||||
|
||||
+26
-7
@@ -27,6 +27,24 @@ __null_check(const vec_string* ptr, err_t* status)
|
||||
return status->flags;
|
||||
}
|
||||
|
||||
__attribute__((overloadable)) size_t
|
||||
__null_check(const String* ptr, err_t* status)
|
||||
{
|
||||
if (status == nullptr)
|
||||
{
|
||||
return ERR_ERR_T_NULL;
|
||||
}
|
||||
if (ptr == nullptr)
|
||||
{
|
||||
status->flags |= ERR_STR_NULL;
|
||||
}
|
||||
if (ptr->data == nullptr)
|
||||
{
|
||||
status->flags |= ERR_BUF_NULL;
|
||||
}
|
||||
return status->flags;
|
||||
}
|
||||
|
||||
void
|
||||
vec_string_print_vec(const vec_string* ptr, err_t* err)
|
||||
{
|
||||
@@ -42,7 +60,7 @@ vec_string_print_vec(const vec_string* ptr, err_t* err)
|
||||
}
|
||||
|
||||
vec_string
|
||||
vec_string_cpy(const char* src, const size_t src_size, err_t* err)
|
||||
vec_string_cpy(const String* src, const size_t src_size, err_t* err)
|
||||
{
|
||||
vec_string self = VEC_INIT;
|
||||
err_t status = ERR_T_INIT;
|
||||
@@ -328,7 +346,7 @@ vec_string_clear(vec_string* ptr, err_t* err)
|
||||
}
|
||||
if (ptr->size > 0)
|
||||
{
|
||||
memset(ptr->array, 0, ptr->size);
|
||||
memset(ptr->array, 0, ptr->size * (sizeof(String)));
|
||||
ptr->size = 0;
|
||||
}
|
||||
}
|
||||
@@ -433,9 +451,9 @@ vec_string_empty(const vec_string* ptr, err_t* err)
|
||||
}
|
||||
if (ptr->size == 0)
|
||||
{
|
||||
return ptr->size;
|
||||
return 1;
|
||||
}
|
||||
return status.flags;
|
||||
return 0;
|
||||
}
|
||||
|
||||
__attribute__((overloadable)) void
|
||||
@@ -450,6 +468,8 @@ vec_string_erase(vec_string* ptr, const size_t iter, err_t* err)
|
||||
}
|
||||
if (iter >= ptr->size)
|
||||
{
|
||||
__origin_override(err, "ERASE");
|
||||
err->flags |= ERR_OUT_OF_BOUNDS;
|
||||
return;
|
||||
}
|
||||
memmove(&ptr->array[iter], &ptr->array[iter + 1],
|
||||
@@ -697,8 +717,7 @@ vec_string_assign(vec_string* ptr, const vec_string* iterator,
|
||||
err->flags |= ERR_OUT_OF_BOUNDS;
|
||||
return;
|
||||
}
|
||||
vec_string_erase(ptr, vec_string_begin(ptr, &status),
|
||||
vec_string_end(ptr, &status) + 1, &status);
|
||||
vec_string_erase(ptr, 0, ptr->size, &status);
|
||||
if (status.flags != 0)
|
||||
{
|
||||
__origin_override(err, "ASSIGN");
|
||||
@@ -839,7 +858,7 @@ vec_string_insert(vec_string* ptr, const size_t iter, const size_t amount,
|
||||
{
|
||||
err_t status = ERR_T_INIT;
|
||||
__null_check(ptr, &status);
|
||||
if ((status.flags & (ERR_VEC_NULL | ERR_BUF_NULL)) != 0)
|
||||
if ((status.flags & ERR_VEC_NULL) != 0)
|
||||
{
|
||||
__origin_override(err, "INSERT");
|
||||
err->flags |= status.flags;
|
||||
|
||||
+1
-1
@@ -78,7 +78,7 @@ __origin_override(err_t* status, char* str)
|
||||
}
|
||||
|
||||
__attribute__((overloadable)) size_t
|
||||
__null_check(const float* ptr, err_t* status)
|
||||
__null_check(const char* ptr, err_t* status)
|
||||
{
|
||||
if (status == nullptr)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user