LibC+userspace: Make everything compile with -Wall -Wextra -Werror

I added -Wall -Wextra -Werror as public compile flags to libc. Now
everything in userspace in compiled using these flags. I made all
necessary changes to allow compilation to work.

Only exception is execvp which has a large stack usage. Maybe it
should use malloc for the buffer but posix allows ENOMEM only when
kernel is out of memory... This can be fixed when fexecve is
implemented and there is no need for absolute path.
This commit is contained in:
2023-12-10 19:20:14 +02:00
parent f077e17b2a
commit 00d57d783e
22 changed files with 63 additions and 57 deletions

View File

@@ -47,6 +47,7 @@ add_library(libc ${LIBC_SOURCES})
add_dependencies(libc headers crtx-install)
target_compile_options(libc PRIVATE -g -Wstack-usage=512)
target_compile_options(libc PUBLIC -Wall -Wextra -Werror -Wno-error=stack-usage=)
add_custom_target(libc-install
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/libc.a ${BANAN_LIB}/

View File

@@ -104,7 +104,7 @@ struct passwd* getpwnam(const char* name)
{
passwd* pwd;
setpwent();
while (pwd = getpwent())
while ((pwd = getpwent()))
if (strcmp(pwd->pw_name, name) == 0)
return pwd;
return nullptr;
@@ -114,7 +114,7 @@ struct passwd* getpwuid(uid_t uid)
{
passwd* pwd;
setpwent();
while (pwd = getpwent())
while ((pwd = getpwent()))
if (pwd->pw_uid == uid)
return pwd;
return nullptr;

View File

@@ -13,7 +13,7 @@ struct FILE
bool eof { false };
bool error { false };
unsigned char buffer[BUFSIZ];
unsigned char buffer[BUFSIZ] {};
uint32_t buffer_index { 0 };
};
@@ -260,7 +260,7 @@ size_t fread(void* buffer, size_t size, size_t nitems, FILE* file)
while (nread < target)
{
size_t ret = syscall(SYS_READ, file->fd, (uint8_t*)buffer + nread, target - nread);
ssize_t ret = syscall(SYS_READ, file->fd, (uint8_t*)buffer + nread, target - nread);
if (ret < 0)
file->error = true;