From 48d331f144f24af56b465fc37540a5747e3b2b33 Mon Sep 17 00:00:00 2001 From: Travis Geiselbrecht Date: Sun, 5 Oct 2025 13:33:13 -0700 Subject: [PATCH] [clang] fix a few warnings Mostly dealing with comparing a pointer variable that is declared nonnull, which I find to be a dubious warning but is pretty safe in this case since the compiler will be more aggressive about the nullness of the arguments. --- kernel/vm/pmm.c | 2 +- kernel/vm/vmm.c | 4 ---- lib/fs/fs.c | 9 +-------- lib/libc/qsort.c | 4 ++++ 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/kernel/vm/pmm.c b/kernel/vm/pmm.c index 67eba84a..1afd3862 100644 --- a/kernel/vm/pmm.c +++ b/kernel/vm/pmm.c @@ -34,7 +34,7 @@ static mutex_t lock = MUTEX_INITIAL_VALUE(lock); #define ADDRESS_IN_ARENA(address, arena) \ ((address) >= (arena)->base && (address) <= (arena)->base + (arena)->size - 1) -struct list_node *get_arena_list() { return &arena_list; } +struct list_node *get_arena_list(void) { return &arena_list; } static inline bool page_is_free(const vm_page_t *page) { return !(page->flags & VM_PAGE_FLAG_NONFREE); diff --git a/kernel/vm/vmm.c b/kernel/vm/vmm.c index 876926e2..d018f6ca 100644 --- a/kernel/vm/vmm.c +++ b/kernel/vm/vmm.c @@ -298,8 +298,6 @@ status_t vmm_reserve_space(vmm_aspace_t *aspace, const char *name, size_t size, if (!name) name = ""; - if (!aspace) - return ERR_INVALID_ARGS; if (size == 0) return NO_ERROR; if (!IS_PAGE_ALIGNED(vaddr) || !IS_PAGE_ALIGNED(size)) @@ -339,8 +337,6 @@ status_t vmm_alloc_physical(vmm_aspace_t *aspace, const char *name, size_t size, if (!name) name = ""; - if (!aspace) - return ERR_INVALID_ARGS; if (size == 0) return NO_ERROR; if (!IS_PAGE_ALIGNED(paddr) || !IS_PAGE_ALIGNED(size)) diff --git a/lib/fs/fs.c b/lib/fs/fs.c index 256c244f..2a62b957 100644 --- a/lib/fs/fs.c +++ b/lib/fs/fs.c @@ -276,7 +276,7 @@ status_t fs_open_file(const char *path, filehandle **handle) { status_t fs_file_ioctl(filehandle *handle, int request, void *argp) { LTRACEF("filehandle %p, request %d, argp, %p\n", handle, request, argp); - if (unlikely(!handle || !handle->mount || + if (unlikely(!handle->mount || !handle->mount->api || !handle->mount->api->file_ioctl)) { return ERR_INVALID_ARGS; } @@ -322,9 +322,6 @@ status_t fs_create_file(const char *path, filehandle **handle, uint64_t len) { status_t fs_truncate_file(filehandle *handle, uint64_t len) { LTRACEF("filehandle %p, length %llu\n", handle, len); - if (unlikely(!handle)) - return ERR_INVALID_ARGS; - return handle->mount->api->truncate(handle->cookie, len); } @@ -461,10 +458,6 @@ status_t fs_close_dir(dirhandle *handle) { status_t fs_stat_fs(const char *mountpoint, struct fs_stat *stat) { LTRACEF("mountpoint %s stat %p\n", mountpoint, stat); - if (!stat) { - return ERR_INVALID_ARGS; - } - const char *newpath; struct fs_mount *mount = find_mount(mountpoint, &newpath); if (!mount) { diff --git a/lib/libc/qsort.c b/lib/libc/qsort.c index f8843f7f..876f7b11 100644 --- a/lib/libc/qsort.c +++ b/lib/libc/qsort.c @@ -50,6 +50,10 @@ static __inline void swapfunc(char *, char *, int, int); } while (--i > 0); \ } +#if defined(__clang__) +#pragma clang diagnostic ignored "-Wnull-pointer-subtraction" +#endif + #define SWAPINIT(a, es) swaptype = ((char *)a - (char *)0) % sizeof(long) || \ es % sizeof(long) ? 2 : es == sizeof(long)? 0 : 1;