summaryrefslogtreecommitdiff
path: root/libgcompat/backtrace.c
diff options
context:
space:
mode:
Diffstat (limited to 'libgcompat/backtrace.c')
-rw-r--r--libgcompat/backtrace.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/libgcompat/backtrace.c b/libgcompat/backtrace.c
index 4ef0f88..c8ded8b 100644
--- a/libgcompat/backtrace.c
+++ b/libgcompat/backtrace.c
@@ -2,9 +2,16 @@
#include <stddef.h>
#include <stdlib.h>
-#define _frame_level(addr_buf, curr, frame, size) \
- if(__builtin_frame_address(frame) != NULL && (curr = __builtin_return_address(frame)) > 0x1000 && frame <= size) addr_buf[frame] = curr; \
- else return size;
+#define _frame_level(addr_buf, curr, frame, size) \
+ do { \
+ if (__builtin_frame_address(frame) != NULL \
+ && (curr = __builtin_return_address(frame)) > 0x1000 \
+ && frame <= size) { \
+ addr_buf[frame] = curr; \
+ } else { \
+ return size; \
+ } \
+ } while (0)
int backtrace(void **addr_buf, int size)
{
@@ -22,18 +29,18 @@ int backtrace(void **addr_buf, int size)
return 9;
}
-char **backtrace_symbols(void * const *addr_buf, int size)
+char **backtrace_symbols(void *const *addr_buf, int size)
{
char **result = calloc(sizeof(char *), size);
- if(result == NULL) return result;
+ if (result == NULL) {
+ return result;
+ }
- for(int next = 0; next < size; next++)
- {
+ for (int next = 0; next < size; next++) {
Dl_info info;
int err = dladdr(addr_buf[next], &info);
- if(err != 0)
- {
+ if (err != 0) {
result[next] = "??:0";
} else {
result[next] = info.dli_sname;