From: Martin Liska Date: Thu, 13 Apr 2017 11:51:28 +0000 (+0200) Subject: Do not call memcpy with a NULL argument (PR gcov-profile/80413). X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0040ecb07f44769025a4d8e4952e8dd7b6d5149e;p=gcc.git 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 --- 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