aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/libgfortran/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'gcc-4.9/libgfortran/runtime')
-rw-r--r--gcc-4.9/libgfortran/runtime/main.c44
-rw-r--r--gcc-4.9/libgfortran/runtime/memory.c4
2 files changed, 31 insertions, 17 deletions
diff --git a/gcc-4.9/libgfortran/runtime/main.c b/gcc-4.9/libgfortran/runtime/main.c
index 58ec6cc49..a103c554b 100644
--- a/gcc-4.9/libgfortran/runtime/main.c
+++ b/gcc-4.9/libgfortran/runtime/main.c
@@ -153,6 +153,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. */
@@ -161,30 +171,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
}
diff --git a/gcc-4.9/libgfortran/runtime/memory.c b/gcc-4.9/libgfortran/runtime/memory.c
index c1e735894..d3b77de4b 100644
--- a/gcc-4.9/libgfortran/runtime/memory.c
+++ b/gcc-4.9/libgfortran/runtime/memory.c
@@ -56,7 +56,9 @@ xmallocarray (size_t nmemb, size_t size)
if (!nmemb || !size)
size = nmemb = 1;
- else if (nmemb > SIZE_MAX / size)
+#define HALF_SIZE_T (((size_t) 1) << (__CHAR_BIT__ * sizeof (size_t) / 2))
+ else if (__builtin_expect ((nmemb | size) >= HALF_SIZE_T, 0)
+ && nmemb > SIZE_MAX / size)
{
errno = ENOMEM;
os_error ("Integer overflow in xmallocarray");