CHORE: Bugfixing

This commit is contained in:
2026-10-14 13:20:58 -04:00
parent 1654b86640
commit 0e7c2cafaa
7 changed files with 51 additions and 18 deletions
+15 -1
View File
@@ -7,6 +7,9 @@ LLVM_PROFDATA := $(LLVM_DIR)/llvm-profdata
LLVM_COV := $(LLVM_DIR)/llvm-cov LLVM_COV := $(LLVM_DIR)/llvm-cov
CPPCHECK := cppcheck CPPCHECK := cppcheck
# libstr is populated by CMake's FetchContent (run `cmake -B build` once)
LIBSTR_DIR := build/_deps/libstr-src
# ============================================================================== # ==============================================================================
# Flags & Directories # Flags & Directories
# ============================================================================== # ==============================================================================
@@ -35,6 +38,9 @@ SRCS := src/lib/int/int.c src/lib/utils/utils.c
TEST_SRC := tests/test_learn.c TEST_SRC := tests/test_learn.c
FUZZ_SRC := tests/fuzz_char.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 BIN_DIR := tests/bin
CACHE_DIR := tests/cache CACHE_DIR := tests/cache
@@ -42,11 +48,12 @@ TEST_BIN := $(BIN_DIR)/test_learn_runner
TSAN_BIN := $(BIN_DIR)/test_tsan_runner TSAN_BIN := $(BIN_DIR)/test_tsan_runner
FUZZ_BIN := $(BIN_DIR)/fuzz_char_runner FUZZ_BIN := $(BIN_DIR)/fuzz_char_runner
COV_BIN := $(BIN_DIR)/test_cov_runner COV_BIN := $(BIN_DIR)/test_cov_runner
TEST_STRING_BIN := $(BIN_DIR)/test_string_runner
# ============================================================================== # ==============================================================================
# Targets & Workflow Rules # 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 all: test
@@ -58,6 +65,9 @@ $(BIN_DIR) $(CACHE_DIR):
$(TEST_BIN): $(SRCS) $(TEST_SRC) | $(BIN_DIR) $(TEST_BIN): $(SRCS) $(TEST_SRC) | $(BIN_DIR)
$(CC) $(CFLAGS) $(SAN_FLAGS) $(INCLUDES) $^ -o $@ $(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) $(TSAN_BIN): $(SRCS) $(TEST_SRC) | $(BIN_DIR)
$(CC) $(CFLAGS) -fsanitize=thread $(INCLUDES) $^ -o $@ $(CC) $(CFLAGS) -fsanitize=thread $(INCLUDES) $^ -o $@
@@ -70,6 +80,10 @@ test: $(TEST_BIN)
@echo "=== Running Unit Tests (ASan + UBSan) ===" @echo "=== Running Unit Tests (ASan + UBSan) ==="
@$(ASAN_ENV) ./$(TEST_BIN) @$(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) sanitize: $(TEST_BIN) $(TSAN_BIN)
@echo "\n=== [1/2] Running Address + UndefinedBehavior Sanitizers ===" @echo "\n=== [1/2] Running Address + UndefinedBehavior Sanitizers ==="
@$(ASAN_ENV) ./$(TEST_BIN) @$(ASAN_ENV) ./$(TEST_BIN)
+2 -2
View File
@@ -1,5 +1,5 @@
#ifndef CHAR_H #ifndef LIBVEC_CHAR_H
#define CHAR_H #define LIBVEC_CHAR_H
#include <libvec/utils.h> #include <libvec/utils.h>
+2 -2
View File
@@ -1,5 +1,5 @@
#ifndef CHAR_H #ifndef LIBVEC_FLOAT_H
#define CHAR_H #define LIBVEC_FLOAT_H
#include <libvec/utils.h> #include <libvec/utils.h>
+2 -2
View File
@@ -1,5 +1,5 @@
#ifndef INT_H #ifndef LIBVEC_INT_H
#define INT_H #define LIBVEC_INT_H
#include <libvec/utils.h> #include <libvec/utils.h>
+3 -3
View File
@@ -1,5 +1,5 @@
#ifndef CHAR_H #ifndef LIBVEC_STRING_H
#define CHAR_H #define LIBVEC_STRING_H
#include <libstr/string.h> #include <libstr/string.h>
#include <libvec/utils.h> #include <libvec/utils.h>
@@ -24,7 +24,7 @@ void
vec_string_print_vec(const vec_string* ptr, err_t* err); vec_string_print_vec(const vec_string* ptr, err_t* err);
vec_string 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 void
vec_string_push_back(vec_string* ptr, const String val, err_t* err); vec_string_push_back(vec_string* ptr, const String val, err_t* err);
+26 -7
View File
@@ -27,6 +27,24 @@ __null_check(const vec_string* ptr, err_t* status)
return status->flags; 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 void
vec_string_print_vec(const vec_string* ptr, err_t* err) 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
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; vec_string self = VEC_INIT;
err_t status = ERR_T_INIT; err_t status = ERR_T_INIT;
@@ -328,7 +346,7 @@ vec_string_clear(vec_string* ptr, err_t* err)
} }
if (ptr->size > 0) if (ptr->size > 0)
{ {
memset(ptr->array, 0, ptr->size); memset(ptr->array, 0, ptr->size * (sizeof(String)));
ptr->size = 0; ptr->size = 0;
} }
} }
@@ -433,9 +451,9 @@ vec_string_empty(const vec_string* ptr, err_t* err)
} }
if (ptr->size == 0) if (ptr->size == 0)
{ {
return ptr->size; return 1;
} }
return status.flags; return 0;
} }
__attribute__((overloadable)) void __attribute__((overloadable)) void
@@ -450,6 +468,8 @@ vec_string_erase(vec_string* ptr, const size_t iter, err_t* err)
} }
if (iter >= ptr->size) if (iter >= ptr->size)
{ {
__origin_override(err, "ERASE");
err->flags |= ERR_OUT_OF_BOUNDS;
return; return;
} }
memmove(&ptr->array[iter], &ptr->array[iter + 1], 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; err->flags |= ERR_OUT_OF_BOUNDS;
return; return;
} }
vec_string_erase(ptr, vec_string_begin(ptr, &status), vec_string_erase(ptr, 0, ptr->size, &status);
vec_string_end(ptr, &status) + 1, &status);
if (status.flags != 0) if (status.flags != 0)
{ {
__origin_override(err, "ASSIGN"); __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; err_t status = ERR_T_INIT;
__null_check(ptr, &status); __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"); __origin_override(err, "INSERT");
err->flags |= status.flags; err->flags |= status.flags;
+1 -1
View File
@@ -78,7 +78,7 @@ __origin_override(err_t* status, char* str)
} }
__attribute__((overloadable)) size_t __attribute__((overloadable)) size_t
__null_check(const float* ptr, err_t* status) __null_check(const char* ptr, err_t* status)
{ {
if (status == nullptr) if (status == nullptr)
{ {