enable warnings and cleanup

This commit is contained in:
2025-03-27 01:33:58 +02:00
parent 2015894068
commit 08c3587643
4 changed files with 18 additions and 15 deletions

View File

@@ -51,6 +51,10 @@ add_library(hiload SHARED
src/logger/sc_log.c
)
target_compile_options(hiload PRIVATE
$<$<C_COMPILER_ID:GNU>:-Wall -Wextra>
$<$<C_COMPILER_ID:Clang>:-Weverything>
)
target_link_libraries(hiload dl)
@@ -86,6 +90,11 @@ add_library(auditor-x86_64 SHARED
src/auditor/auditor-x86_64.c
)
target_compile_options(hiload PRIVATE
$<$<C_COMPILER_ID:GNU>:-Wall -Wextra>
$<$<C_COMPILER_ID:Clang>:-Weverything>
)
install(TARGETS auditor-x86_64
EXPORT auditor-x86_64Targets
ARCHIVE DESTINATION lib

View File

@@ -4,7 +4,7 @@
#include "logger/logger.h"
const char *hi_file_to_str_dyn(const char *filename) {
size_t n = 0;
const char *s = hi_string_from_file_dyn(filename, 0, 0);
if (!s) {
sc_log_error("Failed to read file: %s\n", filename);

View File

@@ -9,6 +9,7 @@
#include <time.h>
#include <unistd.h>
#include "types.h"
#include "array/array.h"
#include "common.h"
#include "logger/logger.h"
@@ -66,14 +67,6 @@ static hiFileEvent create_file_event(const struct inotify_event *event) {
return hievent;
}
static hiFileEvent copy_file_event(const hiFileEvent *event) {
hiFileEvent cpy = *event;
// Copy the file string, so this can be destroyed without destroying the
// original
cpy.file = strdup(event->file);
return cpy;
}
void hi_file_event_free(hiFileEvent *event) {
if (event) {
free((void *)event->file);
@@ -108,7 +101,7 @@ static HiloadResult file_events_init(hiFileEvents *events) {
static void file_events_destroy(hiFileEvents *events) {
if (events) {
for (int i = 0; i < sc_array_size(&events->events); ++i) {
for (size_t i = 0; i < sc_array_size(&events->events); ++i) {
hi_file_event_free(&sc_array_at(&events->events, i));
}
sc_array_term(&events->events);
@@ -170,7 +163,7 @@ static HiloadResult watch_path_remove(hiWatchPaths *paths, const char *path) {
bool found = false;
{
for (int i = 0; i < sc_array_size(&paths->watches); ++i) {
for (size_t i = 0; i < sc_array_size(&paths->watches); ++i) {
WatchPath *wp = &sc_array_at(&paths->watches, i);
if (strcmp(wp->path, path) == 0) {
watch_path_destroy(paths->fd, wp);
@@ -196,7 +189,7 @@ static HiloadResult watch_paths_init(hiWatchPaths *paths) {
static void watch_paths_destroy(hiWatchPaths *paths) {
if (paths) {
for (int i = 0; i < sc_array_size(&paths->watches); i++) {
for (size_t i = 0; i < sc_array_size(&paths->watches); i++) {
WatchPath *wp = &sc_array_at(&paths->watches, i);
watch_path_destroy(paths->fd, wp);
}

View File

@@ -10,6 +10,7 @@
#include "types.h"
#include <assert.h>
#include <stddef.h>
#include <dlfcn.h>
#include <libdwarf/libdwarf.h>
#include <libelf.h>
@@ -62,7 +63,7 @@ static int gather_module_infos_callback(struct dl_phdr_info *info, size_t size,
// Store the module name
const char *modname = info->dlpi_name;
sc_array_add(&infos->names, strdup(modname));
for (int i = 0; i < sc_array_size(&context.enabled_modules); i++) {
for (size_t i = 0; i < sc_array_size(&context.enabled_modules); i++) {
if (hi_path_has_filename(modname,
sc_array_at(&context.enabled_modules, i))) {
@@ -225,7 +226,7 @@ void hi_print_module_infos() {
sc_log_debug(" address: %p\n", sc_array_at(&modules->addresses, i));
const SymbolInfos *symbols = &sc_array_at(&modules->symbols, i);
for (int j = 0; j < sc_array_size(&symbols->names); j++) {
for (size_t j = 0; j < sc_array_size(&symbols->names); j++) {
const void *addr = sc_array_at(&symbols->addresses, j);
const char *name = sc_array_at(&symbols->names, j);
sc_log_debug(" %p: %s\n", addr, name);
@@ -235,7 +236,7 @@ void hi_print_module_infos() {
}
}
int hi_init(unsigned n, const char *enabled_modules[n]) {
int hi_init(unsigned n, const char **enabled_modules) {
assert(!module_infos);
if (sc_log_init() != 0) {