bionic: fix assorted static analyzer warnings
Warnings: bionic/libc/bionic/fts.c:722:5: warning: Null passed to a callee that requires a non-null 1st parameter bionic/libc/bionic/sched_cpualloc.c:34:25: warning: Result of 'malloc' is converted to a pointer of type 'cpu_set_t', which is incompatible with sizeof operand type 'unsigned long' bionic/linker/linker_main.cpp:315:7: warning: Access to field 'e_type' results in a dereference of a null pointer (loaded from variable 'elf_hdr') bionic/linker/linker_main.cpp:493:66: warning: Access to field 'e_phoff' results in a dereference of a null pointer (loaded from variable 'elf_hdr') bionic/linker/linker_main.cpp:90:14: warning: Access to field 'next' results in a dereference of a null pointer (loaded from variable 'prev') Bug: None Test: mma; analyzer warnings are gone. CtsBionicTestCases pass. Change-Id: I699a60c2c6f64c50b9ea06848a680c98a8abb44a
This commit is contained in:
parent
82d746fb39
commit
705910094d
|
@ -56,7 +56,7 @@ static void DummyPthreadOnceInitFunction() {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void BM_pthread_once(benchmark::State& state) {
|
static void BM_pthread_once(benchmark::State& state) {
|
||||||
pthread_once_t once = PTHREAD_ONCE_INIT;
|
static pthread_once_t once = PTHREAD_ONCE_INIT;
|
||||||
pthread_once(&once, DummyPthreadOnceInitFunction);
|
pthread_once(&once, DummyPthreadOnceInitFunction);
|
||||||
|
|
||||||
while (state.KeepRunning()) {
|
while (state.KeepRunning()) {
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
@ -719,7 +720,8 @@ mem1: saved_errno = errno;
|
||||||
/* Build a file name for fts_stat to stat. */
|
/* Build a file name for fts_stat to stat. */
|
||||||
if (ISSET(FTS_NOCHDIR)) {
|
if (ISSET(FTS_NOCHDIR)) {
|
||||||
p->fts_accpath = p->fts_path;
|
p->fts_accpath = p->fts_path;
|
||||||
memmove(cp, p->fts_name, p->fts_namelen + 1);
|
assert(cp && "cp should be non-null if FTS_NOCHDIR is set");
|
||||||
|
memmove(cp, p->fts_name, p->fts_namelen + 1); // NOLINT
|
||||||
p->fts_info = fts_stat(sp, p, 0, dirfd(dirp));
|
p->fts_info = fts_stat(sp, p, 0, dirfd(dirp));
|
||||||
} else {
|
} else {
|
||||||
p->fts_accpath = p->fts_name;
|
p->fts_accpath = p->fts_name;
|
||||||
|
|
|
@ -31,7 +31,10 @@
|
||||||
|
|
||||||
cpu_set_t* __sched_cpualloc(size_t count)
|
cpu_set_t* __sched_cpualloc(size_t count)
|
||||||
{
|
{
|
||||||
return (cpu_set_t*) malloc(CPU_ALLOC_SIZE(count));
|
// The static analyzer complains that CPU_ALLOC_SIZE eventually expands to
|
||||||
|
// N * sizeof(unsigned long), which is incompatible with cpu_set_t. This is
|
||||||
|
// on purpose.
|
||||||
|
return (cpu_set_t*) malloc(CPU_ALLOC_SIZE(count)); // NOLINT
|
||||||
}
|
}
|
||||||
|
|
||||||
void __sched_cpufree(cpu_set_t* set)
|
void __sched_cpufree(cpu_set_t* set)
|
||||||
|
|
|
@ -87,6 +87,7 @@ bool solist_remove_soinfo(soinfo* si) {
|
||||||
|
|
||||||
// prev will never be null, because the first entry in solist is
|
// prev will never be null, because the first entry in solist is
|
||||||
// always the static libdl_info.
|
// always the static libdl_info.
|
||||||
|
CHECK(prev != nullptr);
|
||||||
prev->next = si->next;
|
prev->next = si->next;
|
||||||
if (si == sonext) {
|
if (si == sonext) {
|
||||||
sonext = prev;
|
sonext = prev;
|
||||||
|
@ -307,6 +308,11 @@ static ElfW(Addr) __linker_init_post_relocation(KernelArgumentBlock& args) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (si->base == 0) {
|
||||||
|
async_safe_fatal("Could not find a PHDR: broken executable?");
|
||||||
|
}
|
||||||
|
|
||||||
si->dynamic = nullptr;
|
si->dynamic = nullptr;
|
||||||
|
|
||||||
ElfW(Ehdr)* elf_hdr = reinterpret_cast<ElfW(Ehdr)*>(si->base);
|
ElfW(Ehdr)* elf_hdr = reinterpret_cast<ElfW(Ehdr)*>(si->base);
|
||||||
|
@ -488,6 +494,15 @@ extern "C" ElfW(Addr) __linker_init(void* raw_args) {
|
||||||
static uintptr_t linktime_addr = reinterpret_cast<uintptr_t>(&linktime_addr);
|
static uintptr_t linktime_addr = reinterpret_cast<uintptr_t>(&linktime_addr);
|
||||||
ElfW(Addr) linker_addr = reinterpret_cast<uintptr_t>(&linktime_addr) - linktime_addr;
|
ElfW(Addr) linker_addr = reinterpret_cast<uintptr_t>(&linktime_addr) - linktime_addr;
|
||||||
|
|
||||||
|
#if defined(__clang_analyzer__)
|
||||||
|
// The analyzer assumes that linker_addr will always be null. Make it an
|
||||||
|
// unknown value so we don't have to mark N places with NOLINTs.
|
||||||
|
//
|
||||||
|
// (`+=`, rather than `=`, allows us to sidestep a potential "unused store"
|
||||||
|
// complaint)
|
||||||
|
linker_addr += reinterpret_cast<uintptr_t>(raw_args);
|
||||||
|
#endif
|
||||||
|
|
||||||
ElfW(Addr) entry_point = args.getauxval(AT_ENTRY);
|
ElfW(Addr) entry_point = args.getauxval(AT_ENTRY);
|
||||||
ElfW(Ehdr)* elf_hdr = reinterpret_cast<ElfW(Ehdr)*>(linker_addr);
|
ElfW(Ehdr)* elf_hdr = reinterpret_cast<ElfW(Ehdr)*>(linker_addr);
|
||||||
ElfW(Phdr)* phdr = reinterpret_cast<ElfW(Phdr)*>(linker_addr + elf_hdr->e_phoff);
|
ElfW(Phdr)* phdr = reinterpret_cast<ElfW(Phdr)*>(linker_addr + elf_hdr->e_phoff);
|
||||||
|
|
Loading…
Reference in New Issue