aboutsummaryrefslogtreecommitdiff
path: root/libgfortran/runtime
diff options
context:
space:
mode:
authorJanne Blomqvist <jb@gcc.gnu.org>2014-10-20 10:53:37 +0300
committerJanne Blomqvist <jb@gcc.gnu.org>2014-10-20 10:53:37 +0300
commit70480968b46b95f2f1a6b290b271290c210f2cd4 (patch)
treeca6deadcd02431554c183b307d7d10cc4ef3a6af /libgfortran/runtime
parente0d37441927c02aa63e61ad5f4b37067640fe4b2 (diff)
downloadgcc-70480968b46b95f2f1a6b290b271290c210f2cd4.zip
gcc-70480968b46b95f2f1a6b290b271290c210f2cd4.tar.gz
gcc-70480968b46b95f2f1a6b290b271290c210f2cd4.tar.bz2
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. From-SVN: r216449
Diffstat (limited to 'libgfortran/runtime')
-rw-r--r--libgfortran/runtime/main.c44
1 files changed, 28 insertions, 16 deletions
diff --git a/libgfortran/runtime/main.c b/libgfortran/runtime/main.c
index 8a572ec..448dfee 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
}