public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Iain Buclaw <ibuclaw@gdcproject.org>
To: gcc-patches@gcc.gnu.org
Subject: [committed 03/12] d: Insert null terminator in obstack buffers
Date: Fri, 30 Jul 2021 13:01:02 +0200	[thread overview]
Message-ID: <20210730110111.569140-3-ibuclaw@gdcproject.org> (raw)
In-Reply-To: <20210730110111.569140-1-ibuclaw@gdcproject.org>

Covers cases where functions that handle the extracted strings ignore
the explicit length.  This isn't something that's known to happen in the
current front-end, but the self-hosted front-end has been observed to do
this in its conversions between D and C-style strings.

gcc/d/ChangeLog:

	* d-lang.cc (deps_add_target): Insert null terminator in buffer.
	(deps_write): Likewise.
	(d_parse_file): Likewise.
---
 gcc/d/d-lang.cc | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc
index ac0945b1f34..4386a489ff2 100644
--- a/gcc/d/d-lang.cc
+++ b/gcc/d/d-lang.cc
@@ -108,7 +108,7 @@ deps_add_target (const char *target, bool quoted)
 
   if (!quoted)
     {
-      obstack_grow (&buffer, target, strlen (target));
+      obstack_grow0 (&buffer, target, strlen (target));
       d_option.deps_target.safe_push ((const char *) obstack_finish (&buffer));
       return;
     }
@@ -149,6 +149,7 @@ deps_add_target (const char *target, bool quoted)
       obstack_1grow (&buffer, *p);
     }
 
+  obstack_1grow (&buffer, '\0');
   d_option.deps_target.safe_push ((const char *) obstack_finish (&buffer));
 }
 
@@ -278,6 +279,8 @@ deps_write (Module *module, obstack *buffer)
       obstack_grow (buffer, str, strlen (str));
       obstack_grow (buffer, ":\n", 2);
     }
+
+  obstack_1grow (buffer, '\0');
 }
 
 /* Implements the lang_hooks.init_options routine for language D.
@@ -884,6 +887,7 @@ d_parse_file (void)
 	      obstack_grow (&buffer, str, strlen (str));
 	    }
 
+	  obstack_1grow (&buffer, '\0');
 	  message ("%s", (char *) obstack_finish (&buffer));
 	}
     }
-- 
2.30.2


  parent reply	other threads:[~2021-07-30 11:01 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-30 11:01 [committed 01/12] d: Factor d_nested_class and d_nested_struct into single function Iain Buclaw
2021-07-30 11:01 ` [committed 02/12] d: Drop any field or parameter types that got cached before conversion failed Iain Buclaw
2021-07-30 11:01 ` Iain Buclaw [this message]
2021-11-25 14:09   ` [committed 03/12] d: Insert null terminator in obstack buffers Martin Liška
2021-11-26 12:35     ` Iain Buclaw
2021-11-29  0:31       ` Iain Buclaw
2021-07-30 11:01 ` [committed 04/12] d: Use hasMonitor to determine whether to emit a __monitor field in D classes Iain Buclaw
2021-07-30 11:01 ` [committed 05/12] d: Use Identifier::idPool to generate anonymous field name Iain Buclaw
2021-07-30 11:01 ` [committed 06/12] d: Factor aggregate_initializer_decl to set the sinit for aggregate declarations Iain Buclaw
2021-07-30 11:01 ` [committed 07/12] d: Set COMDAT and visibility of thunks only if they are public Iain Buclaw
2021-07-30 11:01 ` [committed 08/12] d: Only handle named enums in enum_initializer_decl Iain Buclaw
2021-07-30 11:01 ` [committed 09/12] d: Clarify comment for generating static array assignment with literal Iain Buclaw
2021-07-30 11:01 ` [committed 10/12] d: Don't generate a PREDICT_EXPR when assert contracts are turned off Iain Buclaw
2021-07-30 11:01 ` [committed 11/12] d: Always layout initializer for the m_RTInfo field in TypeInfo_Class Iain Buclaw
2021-07-30 11:01 ` [committed 12/12] d: Remove dead code from binary_op Iain Buclaw

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210730110111.569140-3-ibuclaw@gdcproject.org \
    --to=ibuclaw@gdcproject.org \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).