Compare commits

..

2 Commits

Author SHA1 Message Date
beab3454b5
kernel: Enable -Wsign-conversion and -Wcast-align
All checks were successful
continuous-integration/drone/push Build is passing
2022-12-07 11:47:46 +01:00
1badc40a4a
Run include-what-you-use everywhere 2022-12-07 11:40:02 +01:00
15 changed files with 32 additions and 20 deletions

View File

@ -1,6 +1,7 @@
#include "arch/Serial.h" #include "arch/Serial.h"
#include "arch/CPU.h" #include <luna/Result.h>
#include <luna/Format.h> #include <luna/Format.h>
#include <stdarg.h>
namespace Serial namespace Serial
{ {

View File

@ -1,12 +1,14 @@
#include "arch/CPU.h"
#include "arch/x86_64/CPU.h" #include "arch/x86_64/CPU.h"
#include "Log.h" #include "Log.h"
#include "arch/Serial.h"
#include "arch/Timer.h" #include "arch/Timer.h"
#include "arch/x86_64/IO.h" #include "arch/x86_64/IO.h"
#include <cpuid.h> #include <cpuid.h>
#include <luna/String.h> #include <luna/String.h>
#include <luna/SystemError.h> #include <luna/SystemError.h>
#include <luna/Types.h> #include <luna/Types.h>
#include <luna/Check.h>
#include <luna/Result.h>
extern "C" void enable_sse(); extern "C" void enable_sse();
extern "C" void enable_write_protect(); extern "C" void enable_write_protect();

View File

@ -1,4 +1,3 @@
#include "arch/CPU.h"
#include <luna/Types.h> #include <luna/Types.h>
struct Registers // Saved CPU registers for x86-64 struct Registers // Saved CPU registers for x86-64

View File

@ -2,6 +2,7 @@
#include "memory/MemoryManager.h" #include "memory/MemoryManager.h"
#include <luna/String.h> #include <luna/String.h>
#include <luna/SystemError.h> #include <luna/SystemError.h>
#include <luna/Result.h>
#pragma GCC push_options #pragma GCC push_options
#pragma GCC diagnostic ignored "-Wconversion" #pragma GCC diagnostic ignored "-Wconversion"

View File

@ -1,11 +1,11 @@
#include "boot/Init.h" #include "boot/Init.h"
#include "Log.h" #include "Log.h"
#include "arch/CPU.h" #include "arch/CPU.h"
#include "arch/Serial.h"
#include "boot/bootboot.h" #include "boot/bootboot.h"
#include "memory/MemoryManager.h" #include "memory/MemoryManager.h"
#include "video/Framebuffer.h" #include "video/Framebuffer.h"
#include <luna/String.h> #include <luna/String.h>
#include <luna/Result.h>
extern const BOOTBOOT bootboot; extern const BOOTBOOT bootboot;

View File

@ -5,6 +5,7 @@
#include "config.h" #include "config.h"
#include "memory/MemoryManager.h" #include "memory/MemoryManager.h"
#include <luna/Units.h> #include <luna/Units.h>
#include <luna/Result.h>
Result<void> init() Result<void> init()
{ {

View File

@ -1,4 +1,6 @@
#include "memory/MemoryMap.h" #include "memory/MemoryMap.h"
#include <luna/Result.h>
#include <luna/SystemError.h>
extern const BOOTBOOT bootboot; extern const BOOTBOOT bootboot;

View File

@ -3,6 +3,8 @@
#include "video/Framebuffer.h" #include "video/Framebuffer.h"
#include <luna/Format.h> #include <luna/Format.h>
#include <luna/String.h> #include <luna/String.h>
#include <luna/Result.h>
#include <stdarg.h>
extern const BOOTBOOT bootboot; extern const BOOTBOOT bootboot;

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

@ -1,6 +1,9 @@
#include <luna/CType.h> #include <luna/CType.h>
#include <luna/Format.h> #include <luna/Format.h>
#include <luna/NumberParsing.h> #include <luna/NumberParsing.h>
#include <luna/Result.h>
#include <stddef.h>
#include <stdarg.h>
extern "C" usize strlen(const char*); extern "C" usize strlen(const char*);
@ -287,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
{ {
@ -305,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
{ {
@ -323,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
{ {
@ -341,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
{ {
@ -359,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);
} }
} }

View File

@ -1,7 +1,8 @@
#include <luna/Format.h> #include <luna/Format.h>
#include <luna/Units.h> #include <luna/Units.h>
#include <luna/Result.h>
Result<usize> to_dynamic_unit(usize value, char* buffer, size_t max) Result<usize> to_dynamic_unit(usize value, char* buffer, usize max)
{ {
if (value < 1024) { return string_format(buffer, max, "%u bytes", value); } if (value < 1024) { return string_format(buffer, max, "%u bytes", value); }