From bcb24e316ccb4c9d8201fe6bea1c1a616269840c Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Mon, 28 Jan 2019 14:37:17 +0100 Subject: [PATCH] base: fix warnings reported by LLVM analyzer The warnings were false positives though. --- repos/base-foc/src/core/platform_thread.cc | 13 +++++++++++-- repos/base-linux/src/lib/base/ipc.cc | 9 +++++---- repos/base-sel4/src/core/ram_dataspace_support.cc | 11 ++++++----- .../include/base/internal/capability_space_sel4.h | 7 ++++--- .../include/base/internal/capability_space_tpl.h | 6 +++--- 5 files changed, 29 insertions(+), 17 deletions(-) diff --git a/repos/base-foc/src/core/platform_thread.cc b/repos/base-foc/src/core/platform_thread.cc index 28c9dc16e..654392f00 100644 --- a/repos/base-foc/src/core/platform_thread.cc +++ b/repos/base-foc/src/core/platform_thread.cc @@ -45,9 +45,18 @@ unsigned long long Platform_thread::execution_time() const int Platform_thread::start(void *ip, void *sp) { + if (!_platform_pd) { + + /* + * This can never happen because each 'Platform_thread' is bound + * to its 'Platform_pd' at creation time, before 'start' can be + * called. + */ + ASSERT_NEVER_CALLED; + } + /* map the pager cap */ - if (_platform_pd) - _pager.map(_platform_pd->native_task().data()->kcap()); + _pager.map(_platform_pd->native_task().data()->kcap()); /* reserve utcb area and associate thread with this task */ l4_thread_control_start(); diff --git a/repos/base-linux/src/lib/base/ipc.cc b/repos/base-linux/src/lib/base/ipc.cc index 3c9b63b4d..6ef792259 100644 --- a/repos/base-linux/src/lib/base/ipc.cc +++ b/repos/base-linux/src/lib/base/ipc.cc @@ -221,11 +221,12 @@ namespace { { *((int *)CMSG_DATA((cmsghdr *)_cmsg_buf) + _num_sds) = sd; - _num_sds++; - struct cmsghdr *cmsg = CMSG_FIRSTHDR(&_msg); - cmsg->cmsg_len = CMSG_LEN(_num_sds*sizeof(int)); - _msg.msg_controllen = cmsg->cmsg_len; /* actual cmsg length */ + if (cmsg) { + _num_sds++; + cmsg->cmsg_len = CMSG_LEN(_num_sds*sizeof(int)); + _msg.msg_controllen = cmsg->cmsg_len; /* actual cmsg length */ + } } void accept_sockets(int num_sds) diff --git a/repos/base-sel4/src/core/ram_dataspace_support.cc b/repos/base-sel4/src/core/ram_dataspace_support.cc index 0d0ea8311..7b7608911 100644 --- a/repos/base-sel4/src/core/ram_dataspace_support.cc +++ b/repos/base-sel4/src/core/ram_dataspace_support.cc @@ -41,13 +41,13 @@ void Ram_dataspace_factory::_clear_ds (Dataspace_component &ds) { size_t const page_rounded_size = (ds.size() + get_page_size() - 1) & get_page_mask(); - enum { ONE_PAGE = 1 }; - /* allocate one page in core's virtual address space */ void *virt_addr_ptr = nullptr; - if (!platform().region_alloc().alloc(get_page_size(), &virt_addr_ptr) || - !virt_addr_ptr) - ASSERT(!"could not map 4k inside core"); + if (!platform().region_alloc().alloc(get_page_size(), &virt_addr_ptr)) + ASSERT_NEVER_CALLED; + + if (!virt_addr_ptr) + ASSERT_NEVER_CALLED; addr_t const virt_addr = reinterpret_cast(virt_addr_ptr); @@ -55,6 +55,7 @@ void Ram_dataspace_factory::_clear_ds (Dataspace_component &ds) for (addr_t offset = 0; offset < page_rounded_size; offset += get_page_size()) { addr_t const phys_addr = ds.phys_addr() + offset; + enum { ONE_PAGE = 1 }; /* map one physical page to the core-local address */ if (!map_local(phys_addr, virt_addr, ONE_PAGE)) { diff --git a/repos/base-sel4/src/include/base/internal/capability_space_sel4.h b/repos/base-sel4/src/include/base/internal/capability_space_sel4.h index ba2c2ecfc..c81ada238 100644 --- a/repos/base-sel4/src/include/base/internal/capability_space_sel4.h +++ b/repos/base-sel4/src/include/base/internal/capability_space_sel4.h @@ -154,15 +154,16 @@ class Genode::Capability_space_sel4 bool higher(Tree_managed_data *data) { - return data->rpc_obj_key().value() > rpc_obj_key().value(); + return data->rpc_obj_key().value() > this->rpc_obj_key().value(); } Tree_managed_data *find_by_key(Rpc_obj_key key) { - if (key.value() == rpc_obj_key().value()) return this; + if (key.value() == this->rpc_obj_key().value()) + return this; Tree_managed_data *data = - this->child(key.value() > rpc_obj_key().value()); + this->child(key.value() > this->rpc_obj_key().value()); return data ? data->find_by_key(key) : nullptr; } diff --git a/repos/base/src/include/base/internal/capability_space_tpl.h b/repos/base/src/include/base/internal/capability_space_tpl.h index 626487c9c..d593e67f8 100644 --- a/repos/base/src/include/base/internal/capability_space_tpl.h +++ b/repos/base/src/include/base/internal/capability_space_tpl.h @@ -97,15 +97,15 @@ class Genode::Capability_space_tpl bool higher(Tree_managed_data *data) { - return data->rpc_obj_key().value() > rpc_obj_key().value(); + return data->rpc_obj_key().value() > this->rpc_obj_key().value(); } Tree_managed_data *find_by_key(Rpc_obj_key key) { - if (key.value() == rpc_obj_key().value()) return this; + if (key.value() == this->rpc_obj_key().value()) return this; Tree_managed_data *data = - this->child(key.value() > rpc_obj_key().value()); + this->child(key.value() > this->rpc_obj_key().value()); return data ? data->find_by_key(key) : nullptr; }