Skip to content

Commit

Permalink
Enable and fix more warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
djphoenix committed May 14, 2019
1 parent d50fa52 commit 5126dca
Show file tree
Hide file tree
Showing 26 changed files with 161 additions and 162 deletions.
4 changes: 3 additions & 1 deletion cmake/toolchain.cmake
Expand Up @@ -39,7 +39,9 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O2 -Os")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections -fpic -fpie")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wproperty-attribute-mismatch")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wold-style-cast -Wcast-qual -Wcast-align -Winline")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wold-style-cast -Wcast-qual -Wcast-align")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wcomma -Wconditional-uninitialized -Wconversion")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wzero-as-null-pointer-constant")

set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "" FORCE)

Expand Down
4 changes: 2 additions & 2 deletions src/boot/efiboot.cpp
Expand Up @@ -5,8 +5,8 @@
#include "efi.hpp"

namespace EFI {
const struct EFI::SystemTable *SystemTable = 0;
const void *ImageHandle = 0;
const struct EFI::SystemTable *SystemTable = nullptr;
const void *ImageHandle = nullptr;
}
const struct EFI::SystemTable *EFI::getSystemTable() { return SystemTable; }
const void *EFI::getImageHandle() { return ImageHandle; }
2 changes: 1 addition & 1 deletion src/boot/multiboot_info.cpp
Expand Up @@ -3,7 +3,7 @@

#include "multiboot_info.hpp"

Multiboot::Payload *Multiboot::payload = 0;
Multiboot::Payload *Multiboot::payload = nullptr;
Multiboot::Payload *Multiboot::getPayload() {
return payload;
}
10 changes: 5 additions & 5 deletions src/kernlib/display.cpp
Expand Up @@ -14,7 +14,7 @@ class ConsoleDisplay: public Display {
char *display;
void putc(const char c) {
if (c == 0) return;
size_t pos = display - base;
size_t pos = size_t(display - base);
if (c == '\n') {
display += 160 - (pos % 160);
} else if (c == '\t') {
Expand All @@ -36,7 +36,7 @@ class ConsoleDisplay: public Display {

public:
ConsoleDisplay() {
if (EFI::getSystemTable() != 0) return;
if (EFI::getSystemTable() != nullptr) return;
display = base;
clean();
}
Expand Down Expand Up @@ -166,7 +166,7 @@ class SerialDisplay: public Display {
uint64_t t = EnterCritical();
mutex.lock();
char c;
while ((c = *str++) != 0) Port<port>::out<uint8_t>(c);
while ((c = *str++) != 0) Port<port>::out(uint8_t(c));
mutex.release();
LeaveCritical(t);
}
Expand All @@ -189,9 +189,9 @@ void Display::setup() {
if (instance != &serialConsole) return;
const struct EFI::SystemTable *ST = EFI::getSystemTable();
if (ST) { // EFI Framebuffer
EFI::GraphicsOutput *graphics_output = 0;
EFI::GraphicsOutput *graphics_output = nullptr;
ST->BootServices->LocateProtocol(
&EFI::GUID_GraphicsOutputProtocol, 0,
&EFI::GUID_GraphicsOutputProtocol, nullptr,
reinterpret_cast<void**>(&graphics_output));
PixelFormat pixelFormat;
switch (graphics_output->Mode->Info->PixelFormat) {
Expand Down
2 changes: 1 addition & 1 deletion src/kernlib/include/kernlib/std.hpp
Expand Up @@ -19,7 +19,7 @@ namespace klib {
template<typename T> inline static T PURE min(T a, T b) { return a < b ? a : b; }
template<typename T> inline static T PURE abs(T a) { return a > 0 ? a : -a; }

size_t strlen(const char*, size_t limit = -1) PURE;
size_t strlen(const char*, size_t limit = static_cast<size_t>(-1)) PURE;
char* strdup(const char*);
int strcmp(const char*, const char*) PURE;

Expand Down
2 changes: 1 addition & 1 deletion src/kernlib/include/list.hpp
Expand Up @@ -7,7 +7,7 @@
template<typename Item>
class List {
private:
Item *items = 0;
Item *items = nullptr;
size_t count = 0;
size_t capacity = 0;
public:
Expand Down
4 changes: 2 additions & 2 deletions src/kernlib/include/stream.hpp
Expand Up @@ -9,7 +9,7 @@ class Stream {
virtual size_t read(void* dest, size_t size) = 0;
virtual size_t size() = 0;
virtual size_t seek(int64_t offset, char base = 0) = 0;
virtual Stream* substream(int64_t offset = -1, size_t limit = -1) = 0;
virtual Stream* substream(int64_t offset = -1, size_t limit = size_t(-1)) = 0;
virtual bool eof() = 0;
virtual char* readstr() = 0;
virtual ~Stream() {}
Expand All @@ -26,7 +26,7 @@ class MemoryStream: public Stream {
size_t read(void* dest, size_t size);
size_t size() PURE;
size_t seek(int64_t offset, char base = 0);
Stream* substream(int64_t offset = -1, size_t limit = -1);
Stream* substream(int64_t offset = -1, size_t limit = size_t(-1));
char* readstr();
bool eof() PURE;
};
48 changes: 24 additions & 24 deletions src/kernlib/printf.cpp
Expand Up @@ -7,7 +7,7 @@
static inline char *longlong_to_string(
char *buf, size_t len, uint64_t n, uint8_t base,
bool fl_signed, bool fl_showsign, bool fl_caps) {
int pos = len;
size_t pos = len;
char table_start = fl_caps ? 'A' : 'a';
bool negative = 0;
if (fl_signed && int64_t(n) < 0) {
Expand All @@ -19,7 +19,7 @@ static inline char *longlong_to_string(
uint8_t digit = n % base;
n /= base;
if (digit < 10) {
buf[ --pos] = digit + '0';
buf[ --pos] = static_cast<char>(digit + '0');
} else {
buf[ --pos] = digit - 10 + table_start;
}
Expand All @@ -33,7 +33,7 @@ static inline char *longlong_to_string(
static void printf_putc(char *str, size_t *size, int *len, char c) {
if ((*len) == -1) return;
(*len)++;
if (str == 0) return;
if (str == nullptr) return;
if (*size == 0) {
*len = -1;
return;
Expand Down Expand Up @@ -71,7 +71,7 @@ int vsnprintf(char *str, size_t size, const char *format, va_list ap) {
} PACKED;

char c;
const char *fmt_start;
const char *fmt_start = nullptr;
int out_len = 0;

flags_t flags;
Expand Down Expand Up @@ -205,36 +205,36 @@ int vsnprintf(char *str, size_t size, const char *format, va_list ap) {
printf_putc(str, &size, &out_len, '%');
goto next_format;
case 'c':
c = va_arg(ap, /* char */ int) & 0xFF;
c = static_cast<char>(va_arg(ap, /* char */ int) & 0xFF);
numbuf[0] = c;
numbuf[1] = 0;
strval = numbuf;
goto out_str;
case 's':
strval = va_arg(ap, const char*);
if (strval == 0) strval = "<null>";
if (strval == nullptr) strval = "<null>";
goto out_str;
case 'd':
case 'i':
numsig = 1;
if (flags.sz_halfhalf)
numval = va_arg(ap, /* signed char, int8_t */ int32_t);
numval = uintmax_t(va_arg(ap, /* signed char, int8_t */ int32_t));
else if (flags.sz_half)
numval = va_arg(ap, /* short int, int16_t */ int32_t);
numval = uintmax_t(va_arg(ap, /* short int, int16_t */ int32_t));
else if (flags.sz_long)
numval = va_arg(ap, int32_t);
numval = uintmax_t(va_arg(ap, int32_t));
else if (flags.sz_longlong)
numval = va_arg(ap, int64_t);
numval = uintmax_t(va_arg(ap, int64_t));
else if (flags.sz_max)
numval = va_arg(ap, intmax_t);
numval = uintmax_t(va_arg(ap, intmax_t));
else if (flags.sz_sizet)
numval = va_arg(ap, size_t);
numval = uintmax_t(va_arg(ap, size_t));
else if (flags.sz_ptrdiff)
numval = va_arg(ap, ptrdiff_t);
numval = uintmax_t(va_arg(ap, ptrdiff_t));
else if (flags.sz_longdbl)
goto invalid_fmt;
else
numval = va_arg(ap, int);
numval = uintmax_t(va_arg(ap, int));
goto out_num;
case 'X':
upcaseout = 1;
Expand Down Expand Up @@ -268,27 +268,27 @@ int vsnprintf(char *str, size_t size, const char *format, va_list ap) {
else if (flags.sz_sizet)
numval = va_arg(ap, size_t);
else if (flags.sz_ptrdiff)
numval = va_arg(ap, ptrdiff_t);
numval = uintmax_t(va_arg(ap, ptrdiff_t));
else if (flags.sz_longdbl)
goto invalid_fmt;
else
numval = va_arg(ap, uint32_t);
goto out_num;
case 'n': {
void *ptrval = va_arg(ap, void*);
if (ptrval == 0) goto next_format;
if (ptrval == nullptr) goto next_format;
if (flags.sz_halfhalf)
*static_cast<int8_t*>(ptrval) = out_len;
*static_cast<int8_t*>(ptrval) = int8_t(out_len);
else if (flags.sz_half)
*static_cast<int16_t*>(ptrval) = out_len;
*static_cast<int16_t*>(ptrval) = int16_t(out_len);
else if (flags.sz_long)
*static_cast<int64_t*>(ptrval) = out_len;
else if (flags.sz_longlong)
*static_cast<int64_t*>(ptrval) = out_len;
else if (flags.sz_max)
*static_cast<intmax_t*>(ptrval) = out_len;
else if (flags.sz_sizet)
*static_cast<size_t*>(ptrval) = out_len;
*static_cast<size_t*>(ptrval) = size_t(out_len);
else if (flags.sz_ptrdiff)
*static_cast<ptrdiff_t*>(ptrval) = out_len;
else if (flags.sz_longdbl)
Expand Down Expand Up @@ -326,7 +326,7 @@ int vsnprintf(char *str, size_t size, const char *format, va_list ap) {

out_str:

int pad = width - klib::strlen(strval);
int pad = width - static_cast<int>(klib::strlen(strval));
if (!flags.fl_leftfmt && (flags.fl_leadzero || flags.fl_leadspace)) {
c = flags.fl_leadzero ? '0' : ' ';
while (pad-- > 0) printf_putc(str, &size, &out_len, c);
Expand All @@ -338,22 +338,22 @@ int vsnprintf(char *str, size_t size, const char *format, va_list ap) {
goto next_format;
}

if (str != 0 && out_len != -1) str[out_len] = 0;
if (str != nullptr && out_len != -1) str[out_len] = 0;
return out_len;
}

int vprintf(const char *format, va_list ap) {
va_list tmp;
va_copy(tmp, ap);
int len = vsnprintf(0, 0, format, tmp);
int len = vsnprintf(nullptr, 0, format, tmp);
va_end(tmp);
char smbuf[512], *buf;
if (len > 511) {
buf = static_cast<char*>(Heap::alloc(len + 1));
buf = static_cast<char*>(Heap::alloc(size_t(len) + 1));
} else {
buf = smbuf;
}
len = vsnprintf(buf, len, format, ap);
len = vsnprintf(buf, size_t(len), format, ap);
buf[len] = 0;
Display::getInstance()->write(buf);
if (len > 511) Heap::free(buf);
Expand Down
4 changes: 2 additions & 2 deletions src/kernlib/std.cpp
Expand Up @@ -4,7 +4,7 @@
#include "kernlib.hpp"

extern "C" {
void *__dso_handle = 0;
void *__dso_handle = nullptr;

void CONST __cxa_pure_virtual() {}
int CONST __cxa_atexit(void (*)(void*), void*, void*) { return 0; }
Expand All @@ -14,7 +14,7 @@ namespace klib {
size_t strlen(const char* c, size_t limit) {
const char *e = c;
while ((size_t(e - c) < limit) && (*e++) != 0) {}
return e - c - 1;
return size_t(e - c - 1);
}

char* strdup(const char* c) {
Expand Down
12 changes: 6 additions & 6 deletions src/kernlib/stream.cpp
Expand Up @@ -16,10 +16,10 @@ size_t MemoryStream::size() {
}
size_t MemoryStream::seek(int64_t offset, char base) {
if (base == -1)
return (this->offset = offset);
return (this->offset = size_t(offset));
if (base == 1)
return (this->offset = this->limit - offset);
return (this->offset += offset);
return (this->offset = size_t(ptrdiff_t(this->limit) - offset));
return (this->offset = size_t(ptrdiff_t(this->offset) + offset));
}
size_t MemoryStream::read(void* dest, size_t size) {
if (offset + size >= limit)
Expand All @@ -30,9 +30,9 @@ size_t MemoryStream::read(void* dest, size_t size) {
}
Stream* MemoryStream::substream(int64_t offset, size_t limit) {
if (offset == -1)
offset = this->offset;
if ((limit == size_t(-1)) || (limit > this->limit - offset))
limit = this->limit - offset;
offset = ptrdiff_t(this->offset);
if ((limit == size_t(-1)) || (limit > size_t(ptrdiff_t(this->limit) - offset)))
limit = size_t(ptrdiff_t(this->limit) - offset);
return new MemoryStream(memory + size_t(offset), limit);
}
char* MemoryStream::readstr() {
Expand Down
22 changes: 10 additions & 12 deletions src/platform/acpi.cpp
Expand Up @@ -8,7 +8,7 @@
#include "pagetable.hpp"

Mutex ACPI::controllerMutex;
ACPI* ACPI::controller = 0;
ACPI* ACPI::controller = nullptr;

ACPI* ACPI::getController() {
if (controller) return controller;
Expand All @@ -22,10 +22,8 @@ ACPI* ACPI::getController() {
}

ACPI::ACPI() {
static const void *const ACPI_FIND_START =
reinterpret_cast<char*>(0x000e0000);
static const void *const ACPI_FIND_TOP =
reinterpret_cast<char*>(0x000fffff);
static const void *const ACPI_FIND_START = reinterpret_cast<char*>(0x000e0000);
static const void *const ACPI_FIND_TOP = reinterpret_cast<char*>(0x000fffff);
static const uint64_t ACPI_SIG_RTP_DSR = 0x2052545020445352; // 'RTP DSR '

acpiCpuCount = 0;
Expand All @@ -38,7 +36,7 @@ ACPI::ACPI() {

const struct EFI::SystemTable *ST = EFI::getSystemTable();
if (ST && ST->ConfigurationTable) {
const EFI::ConfigurationTable *acpi1 = 0, *acpi2 = 0;
const EFI::ConfigurationTable *acpi1 = nullptr, *acpi2 = nullptr;
for (uint64_t i = 0; i < ST->NumberOfTableEntries; i++) {
const EFI::ConfigurationTable *tbl = ST->ConfigurationTable + i;
if (tbl->VendorGuid == EFI::GUID_ConfigTableACPI1) acpi1 = tbl;
Expand Down Expand Up @@ -81,10 +79,10 @@ ACPI::ACPI() {
uint8_t t = Port<0x61>::in<uint8_t>() & 0xFE;
Port<0x61>::out<uint8_t>(t);
Port<0x61>::out<uint8_t>(t | 1);
LapicOut(LAPIC_TMRINITCNT, -1);
LapicOut(LAPIC_TMRINITCNT, 0xFFFFFFFF);
while ((Port<0x61>::in<uint8_t>() & 0x20) == (t & 0x20)) {}
LapicOut(LAPIC_LVT_TMR, LAPIC_DISABLE);
busfreq = (static_cast<uint64_t>(-1 - LapicIn(LAPIC_TMRCURRCNT)) << 4) * 100;
busfreq = (static_cast<uint64_t>(0xFFFFFFFF - LapicIn(LAPIC_TMRCURRCNT)) << 4) * 100;
}
void ACPI::ParseDT(const Header *header) {
Pagetable::map(header);
Expand Down Expand Up @@ -163,7 +161,7 @@ bool ACPI::ParseRsdp(const void *ptr) {
Memory::copy(oem, p + 9, 6);
oem[6] = 0;

char revision = p[15];
uint8_t revision = p[15];
const uint32_t *rsdtPtr = static_cast<const uint32_t*>(ptr) + 4;
const uint64_t *xsdtPtr = static_cast<const uint64_t*>(ptr) + 3;

Expand Down Expand Up @@ -231,7 +229,7 @@ void ACPI::IOapicOut(uint32_t reg, uint32_t data) {
MmioWrite32(ioApicAddr + IOAPIC_REGSEL, reg);
MmioWrite32(ioApicAddr + IOAPIC_REGWIN, data);
}
void ACPI::IOapicMap(uint32_t idx, IOApicRedir r) {
void ACPI::IOapicMap(uint32_t idx, const IOApicRedir &r) {
IOapicOut(IOAPIC_REDTBL + idx * 2 + 0, r.raw[0]);
IOapicOut(IOAPIC_REDTBL + idx * 2 + 1, r.raw[1]);
}
Expand Down Expand Up @@ -305,7 +303,7 @@ void ACPI::EOI() {
(ACPI::getController())->LapicOut(LAPIC_EOI, 0);
}
void ACPI::initIOAPIC() {
if (ioApicAddr == 0)
if (ioApicAddr == nullptr)
return;
ioApicMaxCount = (IOapicIn(IOAPIC_VER) >> 16) & 0xFF;
IOApicRedir kbd;
Expand All @@ -321,7 +319,7 @@ void ACPI::initIOAPIC() {
IOapicMap(1, kbd);
}
bool ACPI::initAPIC() {
if (localApicAddr == 0)
if (localApicAddr == nullptr)
return false;
initCPU();
initIOAPIC();
Expand Down

0 comments on commit 5126dca

Please sign in to comment.