From 511fc870a126ee89cd241bdbd98118df5911adee Mon Sep 17 00:00:00 2001 From: Bananymous Date: Mon, 17 Jun 2024 20:19:36 +0300 Subject: [PATCH] BAN: Mark RefPtr and WeakPtr operator bool() as explicit --- BAN/include/BAN/RefPtr.h | 2 +- BAN/include/BAN/WeakPtr.h | 2 +- kernel/kernel/OpenFileDescriptorSet.cpp | 12 ++++++++++-- kernel/kernel/Terminal/TTY.cpp | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/BAN/include/BAN/RefPtr.h b/BAN/include/BAN/RefPtr.h index e76a542618..8595dac1db 100644 --- a/BAN/include/BAN/RefPtr.h +++ b/BAN/include/BAN/RefPtr.h @@ -128,7 +128,7 @@ namespace BAN bool operator!=(RefPtr other) const { return m_pointer != other.m_pointer; } bool empty() const { return m_pointer == nullptr; } - operator bool() const { return m_pointer; } + explicit operator bool() const { return m_pointer; } void clear() { diff --git a/BAN/include/BAN/WeakPtr.h b/BAN/include/BAN/WeakPtr.h index 4c999731dc..b8626875a0 100644 --- a/BAN/include/BAN/WeakPtr.h +++ b/BAN/include/BAN/WeakPtr.h @@ -91,7 +91,7 @@ namespace BAN bool valid() const { return m_link && m_link->valid(); } - operator bool() const { return valid(); } + explicit operator bool() const { return valid(); } private: WeakPtr(const RefPtr>& link) diff --git a/kernel/kernel/OpenFileDescriptorSet.cpp b/kernel/kernel/OpenFileDescriptorSet.cpp index 2043ead30d..ba1fc3390e 100644 --- a/kernel/kernel/OpenFileDescriptorSet.cpp +++ b/kernel/kernel/OpenFileDescriptorSet.cpp @@ -95,8 +95,7 @@ namespace Kernel BAN::ErrorOr OpenFileDescriptorSet::socket(int domain, int type, int protocol) { - if (protocol != 0) - return BAN::Error::from_errno(EPROTONOSUPPORT); + bool valid_protocol = true; SocketDomain sock_domain; switch (domain) @@ -109,6 +108,7 @@ namespace Kernel break; case AF_UNIX: sock_domain = SocketDomain::UNIX; + valid_protocol = false; break; default: return BAN::Error::from_errno(EPROTOTYPE); @@ -119,17 +119,25 @@ namespace Kernel { case SOCK_STREAM: sock_type = SocketType::STREAM; + if (protocol != IPPROTO_TCP) + valid_protocol = false; break; case SOCK_DGRAM: sock_type = SocketType::DGRAM; + if (protocol != IPPROTO_UDP) + valid_protocol = false; break; case SOCK_SEQPACKET: sock_type = SocketType::SEQPACKET; + valid_protocol = false; break; default: return BAN::Error::from_errno(EPROTOTYPE); } + if (protocol && !valid_protocol) + return BAN::Error::from_errno(EPROTONOSUPPORT); + auto socket = TRY(NetworkManager::get().create_socket(sock_domain, sock_type, 0777, m_credentials.euid(), m_credentials.egid())); int fd = TRY(get_free_fd()); diff --git a/kernel/kernel/Terminal/TTY.cpp b/kernel/kernel/Terminal/TTY.cpp index c91e068925..23d58e14b1 100644 --- a/kernel/kernel/Terminal/TTY.cpp +++ b/kernel/kernel/Terminal/TTY.cpp @@ -361,7 +361,7 @@ namespace Kernel bool TTY::is_initialized() { - return s_tty; + return !!s_tty; } }