From e11a6a4fdf1891802987519974f3a01d665126e9 Mon Sep 17 00:00:00 2001 From: Martin Milata Date: Mon, 6 Aug 2012 19:58:12 +0200 Subject: [PATCH] Fix incorrect return code of unw_get_proc_name The code for symbol lookup (elfxx.c:lookup_symbol) works by iterating over symbol tables while maintaing the symbol closest to the supplied instruction pointer. Whenever this search encountered symbol that was longer than result buffer, the function returned -UNW_ENOMEM even though the final symbol wasn't too long. Signed-off-by: Martin Milata --- src/elfxx.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/elfxx.c b/src/elfxx.c index 844cc1c9..2d5aaccb 100644 --- a/src/elfxx.c +++ b/src/elfxx.c @@ -41,7 +41,7 @@ elf_w (lookup_symbol) (unw_addr_space_t as, Elf_W (Off) soff, str_soff; Elf_W (Shdr) *shdr, *str_shdr; Elf_W (Addr) val, min_dist = ~(Elf_W (Addr))0; - int i, ret = 0; + int i, ret = -UNW_ENOINFO; char *strtab; if (!elf_w (valid_object) (ei)) @@ -102,8 +102,8 @@ elf_w (lookup_symbol) (unw_addr_space_t as, min_dist = (Elf_W (Addr)) (ip - val); strncpy (buf, strtab + sym->st_name, buf_len); buf[buf_len - 1] = '\0'; - if (strlen (strtab + sym->st_name) >= buf_len) - ret = -UNW_ENOMEM; + ret = (strlen (strtab + sym->st_name) >= buf_len + ? -UNW_ENOMEM : 0); } } }