Hi.

The patch fixes path creation for situations when a filename.gcda
starts with e.g. '..'.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
I'll install the patch in few days.

Thanks,
Martin

gcc/ChangeLog:

2019-01-23  Martin Liska  <mli...@suse.cz>

        PR gcov-profile/88994
        * gcov-io.c (mangle_path): Do not allocate a bigger buffer,
        result will be always smaller or equal to the original.
        * gcov.c (mangle_name): Fix else branch where we should
        also copy to PTR and shift the pointer.
---
 gcc/gcov-io.c |  2 +-
 gcc/gcov.c    | 16 +++++++++-------
 2 files changed, 10 insertions(+), 8 deletions(-)


diff --git a/gcc/gcov-io.c b/gcc/gcov-io.c
index e3b1c5ce7ae..1f8ac375931 100644
--- a/gcc/gcov-io.c
+++ b/gcc/gcov-io.c
@@ -547,7 +547,7 @@ mangle_path (char const *base)
   /* Convert '/' to '#', convert '..' to '^',
      convert ':' to '~' on DOS based file system.  */
   const char *probe;
-  char *buffer = (char *)xmalloc (strlen (base) + 10);
+  char *buffer = (char *)xmalloc (strlen (base) + 1);
   char *ptr = buffer;
 
 #if HAVE_DOS_BASED_FILE_SYSTEM
diff --git a/gcc/gcov.c b/gcc/gcov.c
index b8ce1ee0e09..cb6bc7ef85f 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -2520,6 +2520,9 @@ make_gcov_file_name (const char *input_name, const char *src_name)
   return result;
 }
 
+/* Mangle BASE name, copy it at the beginning of PTR buffer and
+   return address of the \0 character of the buffer.  */
+
 static char *
 mangle_name (char const *base, char *ptr)
 {
@@ -2527,14 +2530,13 @@ mangle_name (char const *base, char *ptr)
 
   /* Generate the source filename part.  */
   if (!flag_preserve_paths)
-    {
-      base = lbasename (base);
-      len = strlen (base);
-      memcpy (ptr, base, len);
-      ptr += len;
-    }
+    base = lbasename (base);
   else
-    ptr = mangle_path (base);
+    base = mangle_path (base);
+
+  len = strlen (base);
+  memcpy (ptr, base, len);
+  ptr += len;
 
   return ptr;
 }

Reply via email to