kernel: Enable -Wsign-conversion and -Wcast-align
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2022-12-07 11:47:46 +01:00
parent 1badc40a4a
commit beab3454b5
Signed by: apio
GPG Key ID: B8A7D06E42258954
6 changed files with 15 additions and 15 deletions

View File

@ -17,7 +17,7 @@ set(SOURCES
add_library(luna-freestanding ${FREESTANDING_SOURCES}) add_library(luna-freestanding ${FREESTANDING_SOURCES})
target_compile_definitions(luna-freestanding PRIVATE USE_FREESTANDING) target_compile_definitions(luna-freestanding PRIVATE USE_FREESTANDING)
target_compile_options(luna-freestanding PRIVATE -Wall -Wextra -Werror -Wvla) 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 -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 -Wcast-align -Wwrite-strings -Wlogical-op -Wredundant-decls -Wshadow -Wconversion)
target_compile_options(luna-freestanding PRIVATE -fno-rtti -ffreestanding -fno-exceptions) target_compile_options(luna-freestanding PRIVATE -fno-rtti -ffreestanding -fno-exceptions)

View File

@ -43,6 +43,6 @@ class Bitmap
return b ? 0xff : 0; return b ? 0xff : 0;
} }
char* m_location = nullptr; u8* m_location = nullptr;
usize m_size_in_bytes = 0; usize m_size_in_bytes = 0;
}; };

View File

@ -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) void Bitmap::initialize(void* location, usize size_in_bytes)
{ {
m_location = (char*)location; m_location = (u8*)location;
m_size_in_bytes = size_in_bytes; 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; 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; m_size_in_bytes = new_location_size_in_bytes;
return old_location; return old_location;
@ -37,7 +37,7 @@ void Bitmap::set(usize index, bool value)
expect(initialized(), "Bitmap was never initialized"); expect(initialized(), "Bitmap was never initialized");
expect(index < size(), "Bitmap access out of range"); expect(index < size(), "Bitmap access out of range");
u64 byte_index = index / 8; 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); m_location[byte_index] &= (u8)(~bit_mask);
if (value) { m_location[byte_index] |= 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(initialized(), "Bitmap was never initialized");
expect(index < size(), "Bitmap access out of range"); expect(index < size(), "Bitmap access out of range");
usize byte_index = index / 8; 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; return (m_location[byte_index] & bit_mask) > 0;
} }

View File

@ -290,7 +290,7 @@ static Result<void> va_output_integer(char specifier, conv_state& vstate, format
v = -v; v = -v;
negative = true; negative = true;
} }
return output_integer(specifier, vstate, state, v, negative); return output_integer(specifier, vstate, state, (unsigned char)v, negative);
} }
else else
{ {
@ -308,7 +308,7 @@ static Result<void> va_output_integer(char specifier, conv_state& vstate, format
v = -v; v = -v;
negative = true; negative = true;
} }
return output_integer(specifier, vstate, state, v, negative); return output_integer(specifier, vstate, state, (unsigned short)v, negative);
} }
else else
{ {
@ -326,7 +326,7 @@ static Result<void> va_output_integer(char specifier, conv_state& vstate, format
v = -v; v = -v;
negative = true; negative = true;
} }
return output_integer(specifier, vstate, state, v, negative); return output_integer(specifier, vstate, state, (unsigned long long)v, negative);
} }
else else
{ {
@ -344,7 +344,7 @@ static Result<void> va_output_integer(char specifier, conv_state& vstate, format
v = -v; v = -v;
negative = true; negative = true;
} }
return output_integer(specifier, vstate, state, v, negative); return output_integer(specifier, vstate, state, (unsigned long)v, negative);
} }
else else
{ {
@ -362,7 +362,7 @@ static Result<void> va_output_integer(char specifier, conv_state& vstate, format
v = -v; v = -v;
negative = true; negative = true;
} }
return output_integer(specifier, vstate, state, v, negative); return output_integer(specifier, vstate, state, (unsigned int)v, negative);
} }
else else
{ {

View File

@ -38,7 +38,7 @@ usize _strtou(const char* str, const char** endptr, int base)
while (is_valid_digit_for_base(base, *str)) 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++; str++;
} }

View File

@ -31,7 +31,7 @@ extern "C"
{ {
if (dest == src) return dest; if (dest == src) return dest;
if (dest > src) 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 else
for (long i = 0; i < (long)n; i++) { *((u8*)dest + i) = *((const u8*)src + i); } for (long i = 0; i < (long)n; i++) { *((u8*)dest + i) = *((const u8*)src + i); }
return dest; return dest;
@ -42,6 +42,6 @@ extern "C"
const char* i = str; const char* i = str;
for (; *i; ++i) for (; *i; ++i)
; ;
return (i - str); return (usize)(i - str);
} }
} }