From beab3454b5e741cbd5b7ac7f5d5ab2ebc85efaef Mon Sep 17 00:00:00 2001 From: apio Date: Wed, 7 Dec 2022 11:47:46 +0100 Subject: [PATCH] kernel: Enable -Wsign-conversion and -Wcast-align --- luna/CMakeLists.txt | 2 +- luna/include/luna/Bitmap.h | 2 +- luna/src/Bitmap.cpp | 10 +++++----- luna/src/Format.cpp | 10 +++++----- luna/src/NumberParsing.cpp | 2 +- luna/src/String.cpp | 4 ++-- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/luna/CMakeLists.txt b/luna/CMakeLists.txt index 8cb8b56b..b8e43f9e 100644 --- a/luna/CMakeLists.txt +++ b/luna/CMakeLists.txt @@ -17,7 +17,7 @@ set(SOURCES add_library(luna-freestanding ${FREESTANDING_SOURCES}) target_compile_definitions(luna-freestanding PRIVATE USE_FREESTANDING) target_compile_options(luna-freestanding PRIVATE -Wall -Wextra -Werror -Wvla) -target_compile_options(luna-freestanding PRIVATE -Wdisabled-optimization -Wformat=2 -Winit-self) +target_compile_options(luna-freestanding PRIVATE -Wdisabled-optimization -Wformat=2 -Winit-self -Wcast-align -Wsign-conversion) target_compile_options(luna-freestanding PRIVATE -Wmissing-include-dirs -Wswitch-default -Wcast-qual -Wundef) target_compile_options(luna-freestanding PRIVATE -Wcast-align -Wwrite-strings -Wlogical-op -Wredundant-decls -Wshadow -Wconversion) target_compile_options(luna-freestanding PRIVATE -fno-rtti -ffreestanding -fno-exceptions) diff --git a/luna/include/luna/Bitmap.h b/luna/include/luna/Bitmap.h index b7464e14..b8ab0c40 100644 --- a/luna/include/luna/Bitmap.h +++ b/luna/include/luna/Bitmap.h @@ -43,6 +43,6 @@ class Bitmap return b ? 0xff : 0; } - char* m_location = nullptr; + u8* m_location = nullptr; usize m_size_in_bytes = 0; }; \ No newline at end of file diff --git a/luna/src/Bitmap.cpp b/luna/src/Bitmap.cpp index 05566e3b..1928208e 100644 --- a/luna/src/Bitmap.cpp +++ b/luna/src/Bitmap.cpp @@ -6,13 +6,13 @@ Bitmap::Bitmap() { } -Bitmap::Bitmap(void* location, usize size_in_bytes) : m_location((char*)location), m_size_in_bytes(size_in_bytes) +Bitmap::Bitmap(void* location, usize size_in_bytes) : m_location((u8*)location), m_size_in_bytes(size_in_bytes) { } void Bitmap::initialize(void* location, usize size_in_bytes) { - m_location = (char*)location; + m_location = (u8*)location; m_size_in_bytes = size_in_bytes; } @@ -26,7 +26,7 @@ void* Bitmap::move(void* new_location, usize new_location_size_in_bytes) void* old_location = (void*)m_location; - m_location = (char*)new_location; + m_location = (u8*)new_location; m_size_in_bytes = new_location_size_in_bytes; return old_location; @@ -37,7 +37,7 @@ void Bitmap::set(usize index, bool value) expect(initialized(), "Bitmap was never initialized"); expect(index < size(), "Bitmap access out of range"); u64 byte_index = index / 8; - u8 bit_mask = 0b10000000 >> (index % 8); + u8 bit_mask = (u8)(0b10000000 >> (index % 8)); m_location[byte_index] &= (u8)(~bit_mask); if (value) { m_location[byte_index] |= bit_mask; } } @@ -47,7 +47,7 @@ bool Bitmap::get(usize index) const expect(initialized(), "Bitmap was never initialized"); expect(index < size(), "Bitmap access out of range"); usize byte_index = index / 8; - usize bit_mask = 0b10000000 >> (index % 8); + u8 bit_mask = (u8)(0b10000000 >> (index % 8)); return (m_location[byte_index] & bit_mask) > 0; } diff --git a/luna/src/Format.cpp b/luna/src/Format.cpp index 6547a7d0..5bb9cb1e 100644 --- a/luna/src/Format.cpp +++ b/luna/src/Format.cpp @@ -290,7 +290,7 @@ static Result va_output_integer(char specifier, conv_state& vstate, format v = -v; negative = true; } - return output_integer(specifier, vstate, state, v, negative); + return output_integer(specifier, vstate, state, (unsigned char)v, negative); } else { @@ -308,7 +308,7 @@ static Result va_output_integer(char specifier, conv_state& vstate, format v = -v; negative = true; } - return output_integer(specifier, vstate, state, v, negative); + return output_integer(specifier, vstate, state, (unsigned short)v, negative); } else { @@ -326,7 +326,7 @@ static Result va_output_integer(char specifier, conv_state& vstate, format v = -v; negative = true; } - return output_integer(specifier, vstate, state, v, negative); + return output_integer(specifier, vstate, state, (unsigned long long)v, negative); } else { @@ -344,7 +344,7 @@ static Result va_output_integer(char specifier, conv_state& vstate, format v = -v; negative = true; } - return output_integer(specifier, vstate, state, v, negative); + return output_integer(specifier, vstate, state, (unsigned long)v, negative); } else { @@ -362,7 +362,7 @@ static Result va_output_integer(char specifier, conv_state& vstate, format v = -v; negative = true; } - return output_integer(specifier, vstate, state, v, negative); + return output_integer(specifier, vstate, state, (unsigned int)v, negative); } else { diff --git a/luna/src/NumberParsing.cpp b/luna/src/NumberParsing.cpp index 0790ad9f..dd3d6df7 100644 --- a/luna/src/NumberParsing.cpp +++ b/luna/src/NumberParsing.cpp @@ -38,7 +38,7 @@ usize _strtou(const char* str, const char** endptr, int base) while (is_valid_digit_for_base(base, *str)) { - val = (base * val) + parse_digit_unchecked(*str); + val = ((usize)base * val) + (usize)parse_digit_unchecked(*str); str++; } diff --git a/luna/src/String.cpp b/luna/src/String.cpp index bd174d93..85535188 100644 --- a/luna/src/String.cpp +++ b/luna/src/String.cpp @@ -31,7 +31,7 @@ extern "C" { if (dest == src) return dest; if (dest > src) - for (long i = n - 1; i >= 0; i++) { *((u8*)dest + i) = *((const u8*)src + i); } + for (long i = (long)n - 1; i >= 0; i++) { *((u8*)dest + i) = *((const u8*)src + i); } else for (long i = 0; i < (long)n; i++) { *((u8*)dest + i) = *((const u8*)src + i); } return dest; @@ -42,6 +42,6 @@ extern "C" const char* i = str; for (; *i; ++i) ; - return (i - str); + return (usize)(i - str); } } \ No newline at end of file