public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/guojiufu/heads/personal-branch)] [PR95456] avoid memcpy (_, NULL, 0) in gcc.c
@ 2020-06-10  3:43 Jiu Fu Guo
  0 siblings, 0 replies; only message in thread
From: Jiu Fu Guo @ 2020-06-10  3:43 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:2e6a6644db0ef0f369df4e5b1b337122d84c1a39

commit 2e6a6644db0ef0f369df4e5b1b337122d84c1a39
Author: Alexandre Oliva <oliva@adacore.com>
Date:   Fri Jun 5 22:31:19 2020 -0300

    [PR95456] avoid memcpy (_, NULL, 0) in gcc.c
    
    Some newly-added code in gcc.c might call memcpy with a NULL source
    pointer and zero-length inputs.  Avoid such calls by rearranging the
    code a little.
    
    
    for  gcc/ChangeLog
    
            PR driver/95456
            * gcc.c (do_spec_1): Don't call memcpy (_, NULL, 0).

Diff:
---
 gcc/gcc.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/gcc/gcc.c b/gcc/gcc.c
index e2362175f40..c0eb3c10cfd 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -6024,19 +6024,19 @@ do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part)
 		      }
 		    temp_filename_length
 		      = dumpdir_length + suffix_length + 1;
-		    if (!outbase_length)
-		      temp_filename_length += basename_length;
-		    else
+		    if (outbase_length)
 		      temp_filename_length += outbase_length;
+		    else
+		      temp_filename_length += basename_length;
 		    tmp = (char *) alloca (temp_filename_length);
 		    if (dumpdir_length)
 		      memcpy (tmp, dumpdir, dumpdir_length);
-		    if (!outbase_length)
-		      memcpy (tmp + dumpdir_length, input_basename,
-			      basename_length);
-		    else
+		    if (outbase_length)
 		      memcpy (tmp + dumpdir_length, outbase,
 			      outbase_length);
+		    else if (basename_length)
+		      memcpy (tmp + dumpdir_length, input_basename,
+			      basename_length);
 		    memcpy (tmp + temp_filename_length - suffix_length - 1,
 			    suffix, suffix_length);
 		    if (adjusted_suffix)


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-06-10  3:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-10  3:43 [gcc(refs/users/guojiufu/heads/personal-branch)] [PR95456] avoid memcpy (_, NULL, 0) in gcc.c Jiu Fu Guo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).