From 0040ecb07f44769025a4d8e4952e8dd7b6d5149e Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Thu, 13 Apr 2017 13:51:28 +0200 Subject: [PATCH] Do not call memcpy with a NULL argument (PR gcov-profile/80413). 2017-04-13 Martin Liska PR gcov-profile/80413 * gcov-io.c (gcov_write_string): Copy to buffer just when allocated size is greater than zero. From-SVN: r246903 --- gcc/ChangeLog | 6 ++++++ gcc/gcov-io.c | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8918882fe42..740ca666456 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2017-04-13 Martin Liska + + 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 PR debug/80321 diff --git a/gcc/gcov-io.c b/gcc/gcov-io.c index 3b6b022d143..64dedd5528e 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 -- 2.30.2