Kernel: Enable -Wsign-conversion
All checks were successful
continuous-integration/drone/push Build is passing

For real this time, turns out me, being dumb, added it to Luna instead of the kernel.
This commit is contained in:
apio 2022-12-08 15:09:32 +01:00
parent 779fda307a
commit 6cee208e62
Signed by: apio
GPG Key ID: B8A7D06E42258954
6 changed files with 26 additions and 26 deletions

View File

@ -45,7 +45,7 @@ target_compile_definitions(moon PRIVATE IN_MOON)
target_compile_options(moon PRIVATE -Os) target_compile_options(moon PRIVATE -Os)
target_compile_options(moon PRIVATE -Wall -Wextra -Werror -Wvla) target_compile_options(moon PRIVATE -Wall -Wextra -Werror -Wvla -Wsign-conversion)
target_compile_options(moon PRIVATE -Wdisabled-optimization -Wformat=2 -Winit-self) target_compile_options(moon PRIVATE -Wdisabled-optimization -Wformat=2 -Winit-self)
target_compile_options(moon PRIVATE -Wmissing-include-dirs -Wswitch-default -Wcast-qual -Wundef) target_compile_options(moon PRIVATE -Wmissing-include-dirs -Wswitch-default -Wcast-qual -Wundef)
target_compile_options(moon PRIVATE -Wcast-align -Wwrite-strings -Wlogical-op -Wredundant-decls -Wshadow -Wconversion) target_compile_options(moon PRIVATE -Wcast-align -Wwrite-strings -Wlogical-op -Wredundant-decls -Wshadow -Wconversion)

View File

@ -29,7 +29,7 @@ static void log_serial(LogLevel level, const char* format, va_list origin)
cstyle_format( cstyle_format(
format, format,
[](char c, void*) -> Result<void> { [](char c, void*) -> Result<void> {
Serial::putchar(c); Serial::putchar((u8)c);
return {}; return {};
}, },
nullptr, ap); nullptr, ap);

View File

@ -7,12 +7,12 @@ namespace Serial
{ {
void write(const char* str, usize size) void write(const char* str, usize size)
{ {
while (size--) putchar(*str++); while (size--) putchar((u8)*str++);
} }
void print(const char* str) void print(const char* str)
{ {
while (*str) putchar(*str++); while (*str) putchar((u8)*str++);
} }
void println(const char* str) void println(const char* str)
@ -28,7 +28,7 @@ namespace Serial
auto rc = cstyle_format( auto rc = cstyle_format(
format, format,
[](char c, void*) -> Result<void> { [](char c, void*) -> Result<void> {
putchar(c); putchar((u8)c);
return {}; return {};
}, },
nullptr, ap); nullptr, ap);

View File

@ -6,16 +6,16 @@
static u64 timer_ticks = 0; static u64 timer_ticks = 0;
static u64 boot_timestamp; static u64 boot_timestamp;
static inline constexpr int isleap(int year) static inline constexpr bool isleap(u32 year)
{ {
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0); return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
} }
static constexpr int make_yday(int year, int month) static constexpr u32 make_yday(u32 year, u32 month)
{ {
constexpr short int upto[12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; constexpr u16 upto[12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
int yd = upto[month - 1]; u32 yd = upto[month - 1];
if (month > 2 && isleap(year)) yd++; if (month > 2 && isleap(year)) yd++;
return yd; return yd;
} }
@ -30,19 +30,19 @@ static constexpr u64 broken_down_to_unix(u64 year, u64 yday, u64 hour, u64 min,
// The bootloader encodes the date and time in Binary-Coded Decimal (BCD), which represents decimal digits using // The bootloader encodes the date and time in Binary-Coded Decimal (BCD), which represents decimal digits using
// hexadecimal digits. For example, BCD 0x22 is 22 in decimal. // hexadecimal digits. For example, BCD 0x22 is 22 in decimal.
// https://gitlab.com/bztsrc/bootboot/-/blob/master/bootboot_spec_1st_ed.pdf, page 15. // https://gitlab.com/bztsrc/bootboot/-/blob/master/bootboot_spec_1st_ed.pdf, page 15.
static inline constexpr int bcd_number_to_decimal(int num) static inline constexpr u32 bcd_number_to_decimal(u32 num)
{ {
return ((num >> 4) * 10) + (num & 0xf); return ((num >> 4) * 10) + (num & 0xf);
} }
static u64 bootloader_time_to_unix(const u8 boottime[8]) static u64 bootloader_time_to_unix(const u8 boottime[8])
{ {
const int year = bcd_number_to_decimal(boottime[0]) * 100 + bcd_number_to_decimal(boottime[1]); const u32 year = bcd_number_to_decimal(boottime[0]) * 100 + bcd_number_to_decimal(boottime[1]);
const int month = bcd_number_to_decimal(boottime[2]); const u32 month = bcd_number_to_decimal(boottime[2]);
const int day = bcd_number_to_decimal(boottime[3]); const u32 day = bcd_number_to_decimal(boottime[3]);
const int hour = bcd_number_to_decimal(boottime[4]); const u32 hour = bcd_number_to_decimal(boottime[4]);
const int minute = bcd_number_to_decimal(boottime[5]); const u32 minute = bcd_number_to_decimal(boottime[5]);
const int second = bcd_number_to_decimal(boottime[6]); const u32 second = bcd_number_to_decimal(boottime[6]);
// "The last byte can store 1/100th second precision, but in lack of support on most platforms, it is 0x00". // "The last byte can store 1/100th second precision, but in lack of support on most platforms, it is 0x00".
// Therefore, let's not rely on it. // Therefore, let's not rely on it.
kinfoln("Current time: %.2d/%.2d/%d %.2d:%.2d:%.2d UTC", day, month, year, hour, minute, second); kinfoln("Current time: %.2d/%.2d/%d %.2d:%.2d:%.2d UTC", day, month, year, hour, minute, second);

View File

@ -19,7 +19,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 -Wcast-align -Wsign-conversion) target_compile_options(luna-freestanding PRIVATE -Wdisabled-optimization -Wformat=2 -Winit-self -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

@ -7,9 +7,9 @@ template <usize alignment, typename T> constexpr T is_aligned(T value)
return (value % alignment == 0); return (value % alignment == 0);
} }
static_assert(is_aligned<512>(1024)); static_assert(is_aligned<512>(1024u));
static_assert(!is_aligned<32>(235)); static_assert(!is_aligned<32>(235u));
static_assert(is_aligned<4096>(40960)); static_assert(is_aligned<4096>(40960u));
// Must ALWAYS be called with a power of two as alignment. // Must ALWAYS be called with a power of two as alignment.
template <usize alignment, typename T> constexpr T align_down(T value) template <usize alignment, typename T> constexpr T align_down(T value)
@ -18,9 +18,9 @@ template <usize alignment, typename T> constexpr T align_down(T value)
return value - value % alignment; return value - value % alignment;
} }
static_assert(align_down<512>(598) == 512); static_assert(align_down<512>(598ul) == 512ul);
static_assert(align_down<64>(194) == 192); static_assert(align_down<64>(194ul) == 192ul);
static_assert(align_down<32>(64) == 64); static_assert(align_down<32>(64ul) == 64ul);
// Must ALWAYS be called with a power of two as alignment. // Must ALWAYS be called with a power of two as alignment.
template <usize alignment, typename T> constexpr T align_up(T value) template <usize alignment, typename T> constexpr T align_up(T value)
@ -29,9 +29,9 @@ template <usize alignment, typename T> constexpr T align_up(T value)
return align_down<alignment>(value) + alignment; return align_down<alignment>(value) + alignment;
} }
static_assert(align_up<512>(598) == 1024); static_assert(align_up<512>(598ul) == 1024ul);
static_assert(align_up<64>(194) == 256); static_assert(align_up<64>(194ul) == 256ul);
static_assert(align_up<32>(64) == 64); static_assert(align_up<32>(64ul) == 64ul);
template <typename T> constexpr T get_blocks_from_size(T value, T block_size) template <typename T> constexpr T get_blocks_from_size(T value, T block_size)
{ {