Lines 1-64
Link Here
|
1 |
--- execinfo.c.orig 2004-07-19 05:21:09 UTC |
|
|
2 |
+++ execinfo.c |
3 |
@@ -69,7 +69,8 @@ backtrace(void **buffer, int size) |
4 |
char ** |
5 |
backtrace_symbols(void *const *buffer, int size) |
6 |
{ |
7 |
- int i, clen, alen, offset; |
8 |
+ size_t clen, alen; |
9 |
+ int i, offset; |
10 |
char **rval; |
11 |
char *cp; |
12 |
Dl_info info; |
13 |
@@ -78,7 +79,6 @@ backtrace_symbols(void *const *buffer, i |
14 |
rval = malloc(clen); |
15 |
if (rval == NULL) |
16 |
return NULL; |
17 |
- (char **)cp = &(rval[size]); |
18 |
for (i = 0; i < size; i++) { |
19 |
if (dladdr(buffer[i], &info) != 0) { |
20 |
if (info.dli_sname == NULL) |
21 |
@@ -92,14 +92,14 @@ backtrace_symbols(void *const *buffer, i |
22 |
2 + /* " <" */ |
23 |
strlen(info.dli_sname) + /* "function" */ |
24 |
1 + /* "+" */ |
25 |
- D10(offset) + /* "offset */ |
26 |
+ 10 + /* "offset */ |
27 |
5 + /* "> at " */ |
28 |
strlen(info.dli_fname) + /* "filename" */ |
29 |
1; /* "\0" */ |
30 |
rval = realloc_safe(rval, clen + alen); |
31 |
if (rval == NULL) |
32 |
return NULL; |
33 |
- snprintf(cp, alen, "%p <%s+%d> at %s", |
34 |
+ snprintf((char *) rval + clen, alen, "%p <%s+%d> at %s", |
35 |
buffer[i], info.dli_sname, offset, info.dli_fname); |
36 |
} else { |
37 |
alen = 2 + /* "0x" */ |
38 |
@@ -108,12 +108,15 @@ backtrace_symbols(void *const *buffer, i |
39 |
rval = realloc_safe(rval, clen + alen); |
40 |
if (rval == NULL) |
41 |
return NULL; |
42 |
- snprintf(cp, alen, "%p", buffer[i]); |
43 |
+ snprintf((char *) rval + clen, alen, "%p", buffer[i]); |
44 |
} |
45 |
- rval[i] = cp; |
46 |
- cp += alen; |
47 |
+ rval[i] = (char *) clen; |
48 |
+ clen += alen; |
49 |
} |
50 |
|
51 |
+ for (i = 0; i < size; i++) |
52 |
+ rval[i] += (long) rval; |
53 |
+ |
54 |
return rval; |
55 |
} |
56 |
|
57 |
@@ -155,6 +158,6 @@ backtrace_symbols_fd(void *const *buffer |
58 |
return; |
59 |
snprintf(buf, len, "%p\n", buffer[i]); |
60 |
} |
61 |
- write(fd, buf, len - 1); |
62 |
+ write(fd, buf, strlen(buf)); |
63 |
} |
64 |
} |