From: Frederic Suter Date: Mon, 9 Oct 2017 06:54:54 +0000 (+0200) Subject: stringify a bit X-Git-Tag: v3.18~514 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/19cd5a52131b50275fa26e0e53c4a8bd333f2937?hp=c430d977b0776ec16477d56be021dd15e51736c1 stringify a bit --- diff --git a/src/xbt/backtrace_linux.cpp b/src/xbt/backtrace_linux.cpp index 9bcdf55579..097519cb5b 100644 --- a/src/xbt/backtrace_linux.cpp +++ b/src/xbt/backtrace_linux.cpp @@ -222,8 +222,8 @@ std::vector resolveBacktrace( int found = 0; /* let's look for the offset of this library in our addressing space */ - char* maps_name = bprintf("/proc/%d/maps", (int) getpid()); - FILE* maps = fopen(maps_name, "r"); + std::string maps_name = std::string("/proc/") + std::to_string(getpid()) + "maps"; + FILE* maps = fopen(maps_name.c_str(), "r"); unsigned long int addr = strtoul(addrs[i].c_str(), &p, 16); if (*p != '\0') { @@ -254,7 +254,6 @@ std::vector resolveBacktrace( } } fclose(maps); - free(maps_name); addrs[i].clear(); if (not found) { @@ -286,27 +285,26 @@ std::vector resolveBacktrace( *p2 = '\0'; /* Here we go, fire an addr2line up */ - char* subcmd = bprintf("%s -f -e %s %s", ADDR2LINE, p, addrs[i].c_str()); + std::string subcmd = std::string(ADDR2LINE) + " -f -e " + p + " " + addrs[i]; free(p); - XBT_VERB("Fire a new command: '%s'", subcmd); - FILE* subpipe = popen(subcmd, "r"); + XBT_VERB("Fire a new command: '%s'", subcmd.c_str()); + FILE* subpipe = popen(subcmd.c_str(), "r"); if (not subpipe) { xbt_die("Cannot fork addr2line to display the backtrace"); } if (fgets(line_func, 1024, subpipe)) { line_func[strlen(line_func) - 1] = '\0'; } else { - XBT_VERB("Cannot read result of subcommand %s", subcmd); + XBT_VERB("Cannot read result of subcommand %s", subcmd.c_str()); strncpy(line_func, "???",3); } if (fgets(line_pos, 1024, subpipe)) { line_pos[strlen(line_pos) - 1] = '\0'; } else { - XBT_VERB("Cannot read result of subcommand %s", subcmd); + XBT_VERB("Cannot read result of subcommand %s", subcmd.c_str()); strncpy(line_pos, backtrace_syms[i],1024); } pclose(subpipe); - free(subcmd); } /* check whether the trick worked */