Browse Source

Replace variable length array with std::vector in print_stacktrace()

The function does memory allocation from heap anyway, so should not be
a problem to use STL container.
adaptive-webui-19844
Eugene Shalygin 8 years ago
parent
commit
71cf25ae99
  1. 8
      src/app/stacktrace.h

8
src/app/stacktrace.h

@ -9,16 +9,18 @@ @@ -9,16 +9,18 @@
#include <execinfo.h>
#include <cxxabi.h>
#include <vector>
/** Print a demangled stack backtrace of the caller function to FILE* out. */
static inline void print_stacktrace(FILE *out = stderr, unsigned int max_frames = 63)
{
fprintf(out, "stack trace:\n");
// storage array for stack trace address data
void *addrlist[max_frames + 1];
std::vector<void *> addrlist(max_frames + 1);
// retrieve current stack addresses
int addrlen = backtrace(addrlist, sizeof(addrlist) / sizeof(void *));
int addrlen = backtrace(addrlist.data(), addrlist.size());
if (addrlen == 0) {
fprintf(out, " <empty, possibly corrupt>\n");
@ -27,7 +29,7 @@ static inline void print_stacktrace(FILE *out = stderr, unsigned int max_frames @@ -27,7 +29,7 @@ static inline void print_stacktrace(FILE *out = stderr, unsigned int max_frames
// resolve addresses into strings containing "filename(function+address)",
// this array must be free()-ed
char * *symbollist = backtrace_symbols(addrlist, addrlen);
char * *symbollist = backtrace_symbols(addrlist.data(), addrlen);
// allocate string which will be filled with the demangled function name
size_t funcnamesize = 256;

Loading…
Cancel
Save