execinfo.patch 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. --- execinfo.c.orig
  2. +++ execinfo.c
  3. @@ -69,7 +69,8 @@
  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 @@
  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 @@
  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 @@
  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. + for (i = 0; i < size; i++)
  51. + rval[i] += (long) rval;
  52. +
  53. return rval;
  54. }
  55. @@ -155,6 +158,6 @@
  56. return;
  57. snprintf(buf, len, "%p\n", buffer[i]);
  58. }
  59. - write(fd, buf, len - 1);
  60. + write(fd, buf, strlen(buf));
  61. }
  62. }