aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2017-04-13 13:51:28 +0200
committerMartin Liska <marxin@gcc.gnu.org>2017-04-13 11:51:28 +0000
commit0040ecb07f44769025a4d8e4952e8dd7b6d5149e (patch)
treefe6e31ea3731424b2034de5ecca201c14bee2789 /gcc
parent43a3aa03aca20c7d641cf76354c3572f2a7e5864 (diff)
downloadgcc-0040ecb07f44769025a4d8e4952e8dd7b6d5149e.zip
gcc-0040ecb07f44769025a4d8e4952e8dd7b6d5149e.tar.gz
gcc-0040ecb07f44769025a4d8e4952e8dd7b6d5149e.tar.bz2
Do not call memcpy with a NULL argument (PR gcov-profile/80413).
2017-04-13 Martin Liska <mliska@suse.cz> PR gcov-profile/80413 * gcov-io.c (gcov_write_string): Copy to buffer just when allocated size is greater than zero. From-SVN: r246903
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/gcov-io.c8
2 files changed, 12 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 8918882..740ca66 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2017-04-13 Martin Liska <mliska@suse.cz>
+
+ PR gcov-profile/80413
+ * gcov-io.c (gcov_write_string): Copy to buffer just when
+ allocated size is greater than zero.
+
2017-04-13 Jakub Jelinek <jakub@redhat.com>
PR debug/80321
diff --git a/gcc/gcov-io.c b/gcc/gcov-io.c
index 3b6b022..64dedd5 100644
--- a/gcc/gcov-io.c
+++ b/gcc/gcov-io.c
@@ -347,8 +347,12 @@ gcov_write_string (const char *string)
buffer = gcov_write_words (1 + alloc);
buffer[0] = alloc;
- buffer[alloc] = 0;
- memcpy (&buffer[1], string, length);
+
+ if (alloc > 0)
+ {
+ buffer[alloc] = 0; /* place nul terminators. */
+ memcpy (&buffer[1], string, length);
+ }
}
#endif