diff options
author | jb <jb@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-10-20 07:53:37 +0000 |
---|---|---|
committer | jb <jb@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-10-20 07:53:37 +0000 |
commit | 7f0d992b62e64e043b544dd36596a9b218423dc7 (patch) | |
tree | ca6deadcd02431554c183b307d7d10cc4ef3a6af /libgfortran/runtime | |
parent | 881bdfe36ad91e1d0b49a2586b04fa0c858f66b4 (diff) | |
download | gcc-7f0d992b62e64e043b544dd36596a9b218423dc7.tar.gz |
PR 63589 Fix splitting of PATH in find_addr2line.
2014-10-20 Janne Blomqvist <jb@gcc.gnu.org>
PR libfortran/63589
* configure.ac: Check for strtok_r.
* runtime/main.c (gfstrtok_r): Fallback implementation of
strtok_r.
(find_addr2line): Use strtok_r to split PATH.
* config.h.in: Regenerated.
* configure: Regenerated.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@216449 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgfortran/runtime')
-rw-r--r-- | libgfortran/runtime/main.c | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/libgfortran/runtime/main.c b/libgfortran/runtime/main.c index 8a572ecd5ef..448dfee65d0 100644 --- a/libgfortran/runtime/main.c +++ b/libgfortran/runtime/main.c @@ -181,6 +181,16 @@ full_exe_path (void) } +#ifndef HAVE_STRTOK_R +static char* +gfstrtok_r (char *str, const char *delim, + char **saveptr __attribute__ ((unused))) +{ + return strtok (str, delim); +} +#define strtok_r gfstrtok_r +#endif + char *addr2line_path; /* Find addr2line and store the path. */ @@ -189,30 +199,32 @@ void find_addr2line (void) { #ifdef HAVE_ACCESS -#define A2L_LEN 10 +#define A2L_LEN 11 char *path = secure_getenv ("PATH"); if (!path) return; + char *tp = strdup (path); + if (!tp) + return; size_t n = strlen (path); - char ap[n + 1 + A2L_LEN]; - size_t ai = 0; - for (size_t i = 0; i < n; i++) + char *ap = xmalloc (n + A2L_LEN); + char *saveptr; + for (char *str = tp;; str = NULL) { - if (path[i] != ':') - ap[ai++] = path[i]; - else + char *token = strtok_r (str, ":", &saveptr); + if (!token) + break; + size_t toklen = strlen (token); + memcpy (ap, token, toklen); + memcpy (ap + toklen, "/addr2line", A2L_LEN); + if (access (ap, R_OK|X_OK) == 0) { - ap[ai++] = '/'; - memcpy (ap + ai, "addr2line", A2L_LEN); - if (access (ap, R_OK|X_OK) == 0) - { - addr2line_path = strdup (ap); - return; - } - else - ai = 0; + addr2line_path = strdup (ap); + break; } } + free (tp); + free (ap); #endif } |