From 028a1b1a3cab75837456a083fa9317faa9152650 Mon Sep 17 00:00:00 2001 From: apio Date: Fri, 7 Oct 2022 18:19:06 +0200 Subject: [PATCH] libc: Enable even more warnings --- kernel/Makefile | 2 +- kernel/src/memory/liballoc/liballoc.c | 2 +- libs/libc/Makefile | 4 ++-- libs/libc/include/luna/syscall.h | 12 ++++++------ libs/libc/src/bits/bindings.c | 2 +- libs/libc/src/bits/liballoc.c | 12 +++++++++--- libs/libc/src/luna.cpp | 2 +- libs/libc/src/luna/syscall.c | 12 ++++++------ libs/libc/src/printf.cpp | 8 ++++---- libs/libc/src/stdio.cpp | 2 +- libs/libc/src/string.cpp | 6 +++--- 11 files changed, 35 insertions(+), 29 deletions(-) diff --git a/kernel/Makefile b/kernel/Makefile index c1f25d5e..23f2ad44 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -4,7 +4,7 @@ MOON_OBJ := $(MOON_DIR)/lib MOON_BIN := $(MOON_DIR)/bin CFLAGS := -pedantic -Wall -Wextra -Werror -Wfloat-equal -Wdisabled-optimization -Wformat=2 -Winit-self -Wmissing-include-dirs -Wswitch-default -Wcast-qual -Wundef -Wcast-align -Wwrite-strings -Wlogical-op -Wredundant-decls -Wshadow -Wconversion -Os -ffreestanding -fstack-protector-all -fno-omit-frame-pointer -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -fshort-wchar -mcmodel=kernel -I$(MOON_DIR)/include -isystem $(MOON_DIR)/include/std -CXXFLAGS := -fno-rtti -fno-exceptions -Wsign-promo -Wstrict-null-sentinel -Wctor-dtor-privacy +CXXFLAGS := -fno-rtti -fno-exceptions -Wsign-promo -Wstrict-null-sentinel -Wctor-dtor-privacy ASMFLAGS := -felf64 LDFLAGS := -T$(MOON_DIR)/moon.ld -nostdlib -lgcc -Wl,--build-id=none -z max-page-size=0x1000 diff --git a/kernel/src/memory/liballoc/liballoc.c b/kernel/src/memory/liballoc/liballoc.c index 65ca1e5f..e80c16cf 100644 --- a/kernel/src/memory/liballoc/liballoc.c +++ b/kernel/src/memory/liballoc/liballoc.c @@ -4,7 +4,7 @@ #pragma GCC push_options #pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" +#pragma GCC diagnostic ignored "-Wsign-conversion" // FIXME: Actually solve these warnings. /** Durand's Amazing Super Duper Memory functions. */ diff --git a/libs/libc/Makefile b/libs/libc/Makefile index e770a79e..10a87ac1 100644 --- a/libs/libc/Makefile +++ b/libs/libc/Makefile @@ -5,8 +5,8 @@ LIBC_BIN := $(LIBC_DIR)/bin DESTDIR ?= $(LUNA_BASE)/usr/lib -CFLAGS := -Wall -Wextra -Werror -Os -nostdlib -fno-omit-frame-pointer -pedantic -Wfloat-equal -Wundef -Wcast-align -Wwrite-strings -Wlogical-op -Wredundant-decls -Wshadow -CXXFLAGS := -fno-rtti -fno-exceptions +CFLAGS := -Os -nostdlib -fno-omit-frame-pointer -pedantic -Wall -Wextra -Werror -Wfloat-equal -Wdisabled-optimization -Wformat=2 -Winit-self -Wmissing-include-dirs -Wswitch-default -Wcast-qual -Wundef -Wcast-align -Wwrite-strings -Wlogical-op -Wredundant-decls -Wshadow -Wconversion +CXXFLAGS := -fno-rtti -fno-exceptions -Wsign-promo -Wstrict-null-sentinel -Wctor-dtor-privacy ASMFLAGS := -felf64 rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d)) diff --git a/libs/libc/include/luna/syscall.h b/libs/libc/include/luna/syscall.h index 241b0156..d11a83a2 100644 --- a/libs/libc/include/luna/syscall.h +++ b/libs/libc/include/luna/syscall.h @@ -18,13 +18,13 @@ extern "C" { #endif - long int __luna_syscall0(int sys_num); - long int __luna_syscall1(int sys_num, unsigned long int arg0); - long int __luna_syscall2(int sys_num, unsigned long int arg0, unsigned long int arg1); - long int __luna_syscall3(int sys_num, unsigned long int arg0, unsigned long int arg1, unsigned long int arg2); - long int __luna_syscall4(int sys_num, unsigned long int arg0, unsigned long int arg1, unsigned long int arg2, + long int __luna_syscall0(long int sys_num); + long int __luna_syscall1(long int sys_num, unsigned long int arg0); + long int __luna_syscall2(long int sys_num, unsigned long int arg0, unsigned long int arg1); + long int __luna_syscall3(long int sys_num, unsigned long int arg0, unsigned long int arg1, unsigned long int arg2); + long int __luna_syscall4(long int sys_num, unsigned long int arg0, unsigned long int arg1, unsigned long int arg2, unsigned long int arg3); - long int __luna_syscall5(int sys_num, unsigned long int arg0, unsigned long int arg1, unsigned long int arg2, + long int __luna_syscall5(long int sys_num, unsigned long int arg0, unsigned long int arg1, unsigned long int arg2, unsigned long int arg3, unsigned long int arg4); #ifdef __cplusplus diff --git a/libs/libc/src/bits/bindings.c b/libs/libc/src/bits/bindings.c index 7794fcde..f8601d34 100644 --- a/libs/libc/src/bits/bindings.c +++ b/libs/libc/src/bits/bindings.c @@ -20,7 +20,7 @@ void* liballoc_alloc(size_t size) int liballoc_free(void* address, size_t size) { - int result = syscall(SYS_munmap, address, size * 4096); + int result = (int)syscall(SYS_munmap, address, size * 4096); if (result < 0) return 1; else return 0; diff --git a/libs/libc/src/bits/liballoc.c b/libs/libc/src/bits/liballoc.c index 48d48631..e5bdabef 100644 --- a/libs/libc/src/bits/liballoc.c +++ b/libs/libc/src/bits/liballoc.c @@ -1,5 +1,9 @@ #include +#pragma GCC push_options +#pragma GCC diagnostic ignored "-Wconversion" +#pragma GCC diagnostic ignored "-Wsign-conversion" // FIXME: Actually solve these warnings. + #include #include @@ -105,9 +109,9 @@ static void* liballoc_memset(void* s, int c, size_t n) static void* liballoc_memcpy(void* s1, const void* s2, size_t n) { char* cdest; - char* csrc; + const char* csrc; unsigned int* ldest = (unsigned int*)s1; - unsigned int* lsrc = (unsigned int*)s2; + const unsigned int* lsrc = (const unsigned int*)s2; while (n >= sizeof(unsigned int)) { @@ -116,7 +120,7 @@ static void* liballoc_memcpy(void* s1, const void* s2, size_t n) } cdest = (char*)ldest; - csrc = (char*)lsrc; + csrc = (const char*)lsrc; while (n > 0) { @@ -740,3 +744,5 @@ void* PREFIX(realloc)(void* p, size_t size) return ptr; } + +#pragma GCC pop_options diff --git a/libs/libc/src/luna.cpp b/libs/libc/src/luna.cpp index b1001242..abef73a9 100644 --- a/libs/libc/src/luna.cpp +++ b/libs/libc/src/luna.cpp @@ -14,7 +14,7 @@ extern "C" unsigned int msleep(unsigned int ms) { - return syscall(SYS_sleep, ms); + return (unsigned int)syscall(SYS_sleep, ms); } noreturn void __luna_abort(const char* message) diff --git a/libs/libc/src/luna/syscall.c b/libs/libc/src/luna/syscall.c index b4d15fcf..a1c1499b 100644 --- a/libs/libc/src/luna/syscall.c +++ b/libs/libc/src/luna/syscall.c @@ -1,34 +1,34 @@ #include -long int __luna_syscall0(int sys_num) +long int __luna_syscall0(long int sys_num) { long int result; asm volatile("int $0x42" : "=a"(result) : "a"(sys_num)); return result; } -long int __luna_syscall1(int sys_num, unsigned long int arg0) +long int __luna_syscall1(long int sys_num, unsigned long int arg0) { long int result; asm volatile("int $0x42" : "=a"(result) : "a"(sys_num), "D"(arg0)); return result; } -long int __luna_syscall2(int sys_num, unsigned long int arg0, unsigned long int arg1) +long int __luna_syscall2(long int sys_num, unsigned long int arg0, unsigned long int arg1) { long int result; asm volatile("int $0x42" : "=a"(result) : "a"(sys_num), "D"(arg0), "S"(arg1)); return result; } -long int __luna_syscall3(int sys_num, unsigned long int arg0, unsigned long int arg1, unsigned long int arg2) +long int __luna_syscall3(long int sys_num, unsigned long int arg0, unsigned long int arg1, unsigned long int arg2) { long int result; asm volatile("int $0x42" : "=a"(result) : "a"(sys_num), "D"(arg0), "S"(arg1), "d"(arg2)); return result; } -long int __luna_syscall4(int sys_num, unsigned long int arg0, unsigned long int arg1, unsigned long int arg2, +long int __luna_syscall4(long int sys_num, unsigned long int arg0, unsigned long int arg1, unsigned long int arg2, unsigned long int arg3) { long int result; @@ -37,7 +37,7 @@ long int __luna_syscall4(int sys_num, unsigned long int arg0, unsigned long int return result; } -long int __luna_syscall5(int sys_num, unsigned long int arg0, unsigned long int arg1, unsigned long int arg2, +long int __luna_syscall5(long int sys_num, unsigned long int arg0, unsigned long int arg1, unsigned long int arg2, unsigned long int arg3, unsigned long int arg4) { long int result; diff --git a/libs/libc/src/printf.cpp b/libs/libc/src/printf.cpp index 771ba910..9d2efbb3 100644 --- a/libs/libc/src/printf.cpp +++ b/libs/libc/src/printf.cpp @@ -36,7 +36,7 @@ template static char* __unsignedtoa(IntegerType number, c while (number != 0) { IntegerType r = number % (IntegerType)base; - arr[i] = (r > 9) ? (r - 10) + 'a' : r + '0'; + arr[i] = (char)((r > 9) ? (r - 10) + 'a' : r + '0'); i++; number /= base; } @@ -68,7 +68,7 @@ template static char* __signedtoa(IntegerType number, cha while (number != 0) { IntegerType r = number % base; - arr[i] = (r > 9) ? (r - 10) + 'a' : r + '0'; + arr[i] = (char)((r > 9) ? (r - 10) + 'a' : r + '0'); i++; number /= base; } @@ -147,7 +147,7 @@ static int internal_printf(const char* format, PutString put_string_callback, ss switch (current_char) { case 'c': { - buffer[buffer_insert_index++] = va_arg(ap, int); + buffer[buffer_insert_index++] = (char)va_arg(ap, int); if (buffer_insert_index == 1024) flush_buffer(); break; } @@ -272,7 +272,7 @@ static int internal_printf(const char* format, PutString put_string_callback, ss } if (buffer_insert_index > 0) flush_buffer(); - return written; + return (int)written; } #pragma GCC pop_options diff --git a/libs/libc/src/stdio.cpp b/libs/libc/src/stdio.cpp index cbab3974..d2da8940 100644 --- a/libs/libc/src/stdio.cpp +++ b/libs/libc/src/stdio.cpp @@ -51,7 +51,7 @@ extern "C" { long nwritten = syscall(SYS_write, s, strlen(s)); nwritten += syscall(SYS_write, "\n", 1); - return nwritten; + return (int)nwritten; } int snprintf(char* str, size_t max, const char* format, ...) { diff --git a/libs/libc/src/string.cpp b/libs/libc/src/string.cpp index 15fcd42b..16fcb8d7 100644 --- a/libs/libc/src/string.cpp +++ b/libs/libc/src/string.cpp @@ -5,7 +5,7 @@ extern "C" { void* memcpy(void* dest, const void* src, size_t n) { - for (size_t i = 0; i < n; ++i) { *((char*)dest + i) = *((char*)src + i); } + for (size_t i = 0; i < n; ++i) { *((char*)dest + i) = *((const char*)src + i); } return dest; } @@ -41,7 +41,7 @@ extern "C" size_t dest_len = strlen(dest); size_t i; - for (i = 0; *(src + i); i++) *(char*)(dest + dest_len + i) = *(char*)(src + i); + for (i = 0; *(src + i); i++) *(char*)(dest + dest_len + i) = *(const char*)(src + i); *(char*)(dest + dest_len + i) = '\0'; @@ -53,7 +53,7 @@ extern "C" size_t dest_len = strlen(dest); size_t i; - for (i = 0; i < n && *(src + i); i++) *(char*)(dest + dest_len + i) = *(char*)(src + i); + for (i = 0; i < n && *(src + i); i++) *(char*)(dest + dest_len + i) = *(const char*)(src + i); *(char*)(dest + dest_len + i) = '\0';