summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Gianforcaro <b.gianfo@gmail.com>2021-02-21 02:16:16 -0800
committerAndreas Kling <kling@serenityos.org>2021-02-21 11:52:47 +0100
commitcbd8f78cceb55464534bd729a9290682af004eac (patch)
treee68098205f64ab7bb6f3ddd7a7b57955aa075108
parent7c950c2d0147b93adcca0c1cc10e9a0be09de1af (diff)
downloadserenity-cbd8f78cceb55464534bd729a9290682af004eac.zip
Kernel: Use uniform initialization instead of memset for a few stack buffer.
Raw memset is relatively easy to mess up, avoid it when there are better alternatives provided by the compiler in modern C++.
-rw-r--r--Kernel/FileSystem/Ext2FileSystem.cpp6
-rw-r--r--Kernel/Process.cpp3
-rw-r--r--Kernel/ThreadBlockers.cpp5
3 files changed, 5 insertions, 9 deletions
diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp
index 483f4ddc1f..0b6fb423e2 100644
--- a/Kernel/FileSystem/Ext2FileSystem.cpp
+++ b/Kernel/FileSystem/Ext2FileSystem.cpp
@@ -822,8 +822,7 @@ KResult Ext2FSInode::resize(u64 new_size)
// FIXME: There are definitely more efficient ways to achieve this.
size_t bytes_to_clear = new_size - old_size;
size_t clear_from = old_size;
- u8 zero_buffer[PAGE_SIZE];
- memset(zero_buffer, 0, sizeof(zero_buffer));
+ u8 zero_buffer[PAGE_SIZE] {};
while (bytes_to_clear) {
auto nwritten = write_bytes(clear_from, min(sizeof(zero_buffer), bytes_to_clear), UserOrKernelBuffer::for_kernel_buffer(zero_buffer), nullptr);
if (nwritten < 0)
@@ -1429,8 +1428,7 @@ KResultOr<NonnullRefPtr<Inode>> Ext2FS::create_inode(Ext2FSInode& parent_inode,
struct timeval now;
kgettimeofday(now);
- ext2_inode e2inode;
- memset(&e2inode, 0, sizeof(ext2_inode));
+ ext2_inode e2inode {};
e2inode.i_mode = mode;
e2inode.i_uid = uid;
e2inode.i_gid = gid;
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp
index 973b9a06eb..fedadb5099 100644
--- a/Kernel/Process.cpp
+++ b/Kernel/Process.cpp
@@ -390,8 +390,7 @@ void kgettimeofday(timeval& tv)
siginfo_t Process::wait_info()
{
- siginfo_t siginfo;
- memset(&siginfo, 0, sizeof(siginfo));
+ siginfo_t siginfo {};
siginfo.si_signo = SIGCHLD;
siginfo.si_pid = pid().value();
siginfo.si_uid = uid();
diff --git a/Kernel/ThreadBlockers.cpp b/Kernel/ThreadBlockers.cpp
index e28ee13668..68ab7a60d6 100644
--- a/Kernel/ThreadBlockers.cpp
+++ b/Kernel/ThreadBlockers.cpp
@@ -739,11 +739,10 @@ bool Thread::WaitBlocker::unblock(Process& process, UnblockFlags flags, u8 signa
// more than once!
do_set_result(process.wait_info());
} else {
- siginfo_t siginfo;
- memset(&siginfo, 0, sizeof(siginfo));
+ siginfo_t siginfo {};
{
ScopedSpinLock lock(g_scheduler_lock);
- // We need to gather the information before we release the sheduler lock!
+ // We need to gather the information before we release the scheduler lock!
siginfo.si_signo = SIGCHLD;
siginfo.si_pid = process.pid().value();
siginfo.si_uid = process.uid();