aboutsummaryrefslogtreecommitdiff
path: root/linux-user
diff options
context:
space:
mode:
authorStefan Weil <sw@weilnetz.de>2012-01-05 15:39:39 +0100
committerAndrzej Zaborowski <andrew.zaborowski@intel.com>2012-01-10 18:40:09 +0100
commitc7c530cd3e23219a9be10323ba7876f68d54c107 (patch)
tree78e52ee094cafd6e4b1c7bc86635d6ccaa72879f /linux-user
parent563c2bf35cf4a20b504dd371c395d987f67e16d4 (diff)
downloadqemu-c7c530cd3e23219a9be10323ba7876f68d54c107.zip
qemu-c7c530cd3e23219a9be10323ba7876f68d54c107.tar.gz
qemu-c7c530cd3e23219a9be10323ba7876f68d54c107.tar.bz2
elf: Improve symbol lookup (optimize, fix for bsd-user)
Coverity complained about local variable key which was only partially initiated. Only key.st_value was set. As this was also the only part of key which was used in function symfind, the code could be optimized by directly passing a pointer to orig_addr. In bsd-user/elfload.c, fix ec822001a2f26eef8701194714f6482b6d852de2 was missing. This was a simple replacement of > by >= in symfind, so I fixed it here without creating an additional patch. Signed-off-by: Stefan Weil <sw@weilnetz.de> Signed-off-by: Andrzej Zaborowski <andrew.zaborowski@intel.com>
Diffstat (limited to 'linux-user')
-rw-r--r--linux-user/elfload.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index ea61d0d..845be8b 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -1683,12 +1683,12 @@ static void load_elf_interp(const char *filename, struct image_info *info,
static int symfind(const void *s0, const void *s1)
{
- struct elf_sym *key = (struct elf_sym *)s0;
+ target_ulong addr = *(target_ulong *)s0;
struct elf_sym *sym = (struct elf_sym *)s1;
int result = 0;
- if (key->st_value < sym->st_value) {
+ if (addr < sym->st_value) {
result = -1;
- } else if (key->st_value >= sym->st_value + sym->st_size) {
+ } else if (addr >= sym->st_value + sym->st_size) {
result = 1;
}
return result;
@@ -1703,12 +1703,9 @@ static const char *lookup_symbolxx(struct syminfo *s, target_ulong orig_addr)
#endif
// binary search
- struct elf_sym key;
struct elf_sym *sym;
- key.st_value = orig_addr;
-
- sym = bsearch(&key, syms, s->disas_num_syms, sizeof(*syms), symfind);
+ sym = bsearch(&orig_addr, syms, s->disas_num_syms, sizeof(*syms), symfind);
if (sym != NULL) {
return s->disas_strtab + sym->st_name;
}