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++.
This commit is contained in:
Brian Gianforcaro 2021-02-21 02:16:16 -08:00 committed by Andreas Kling
parent 7c950c2d01
commit cbd8f78cce
Notes: sideshowbarker 2024-07-18 22:03:48 +09:00
3 changed files with 5 additions and 9 deletions

View File

@ -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;

View File

@ -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();

View File

@ -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();