[PATCH 5/5] os: compress two conditions

Peter Hutterer peter.hutterer at who-t.net
Wed Oct 30 00:25:12 CET 2013


The recent change to use elfutils made these conditions almost identical.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 os/backtrace.c | 29 +++++++++++------------------
 1 file changed, 11 insertions(+), 18 deletions(-)

diff --git a/os/backtrace.c b/os/backtrace.c
index acf110a..c3a31bc 100644
--- a/os/backtrace.c
+++ b/os/backtrace.c
@@ -134,32 +134,25 @@ xorg_backtrace(void)
     size = backtrace(array, BT_SIZE);
     for (i = 0; i < size; i++) {
         int rc = dladdr(array[i], &info);
+        const char *name;
+        unsigned int addr;
 
         if (rc == 0) {
             ErrorFSigSafe("%u: ?? [%p]\n", i, array[i]);
             continue;
         }
         mod = (info.dli_fname && *info.dli_fname) ? info.dli_fname : "(vdso)";
-        if (info.dli_saddr)
-            ErrorFSigSafe(
-                "%u: %s (%s+0x%x) [%p]\n",
-                i,
-                mod,
-                info.dli_sname,
-                (unsigned int)((char *) array[i] -
-                               (char *) info.dli_saddr),
-                array[i]);
+
+        if (info.dli_saddr) {
+            name = info.dli_sname;
+            addr = (unsigned int)((char *) array[i] - (char *) info.dli_saddr);
+        }
         else {
-            const char *name = symbol_name(array[i], info.dli_fbase);
-            ErrorFSigSafe(
-                "%u: %s (%s+0x%x) [%p]\n",
-                i,
-                mod,
-                name,
-                (unsigned int)((char *) array[i] -
-                               (char *) info.dli_fbase),
-                array[i]);
+            name = symbol_name(array[i], info.dli_fbase);
+            addr = (unsigned int)((char *) array[i] - (char *) info.dli_fbase);
         }
+
+        ErrorFSigSafe("%u: %s (%s+0x%x) [%p]\n", i, mod, name, addr, array[i]);
     }
     ErrorFSigSafe("\n");
 }
-- 
1.8.3.1



More information about the xorg-devel mailing list