Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

-- >8 --
1) In other places we free ostr.text after calling cpp_translate_string
if it didn't fail.

2) tree.h says that TREE_STRING_LENGTH is like sizeof, not strlen.  Other
places use strlen+1 for istr.len, so we shouldn't add 1 to TREE_STRING_LENGTH.

gcc/cp/ChangeLog:

        * reflect.cc (eval_data_member_spec): Free ostr.text.
        (eval_exception__S_exception_cvt_tofrom_utf8): Don't add 1 to
        TREE_STRING_LENGTH.
---
 gcc/cp/reflect.cc | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/gcc/cp/reflect.cc b/gcc/cp/reflect.cc
index 4137fb64e75..a7cb236f9b1 100644
--- a/gcc/cp/reflect.cc
+++ b/gcc/cp/reflect.cc
@@ -6168,10 +6168,14 @@ eval_data_member_spec (location_t loc, const 
constexpr_ctx *ctx,
          if (len >= 64)
            XDELETEVEC (namep);
          if (!cpp_valid_identifier (parse_in, ostr.text))
-           return throw_exception (loc, ctx,
-                                   "name is not a valid identifier",
-                                   fun, non_constant_p, jump_target);
+           {
+             free (const_cast <unsigned char *> (ostr.text));
+             return throw_exception (loc, ctx,
+                                     "name is not a valid identifier",
+                                     fun, non_constant_p, jump_target);
+           }
          args[i] = get_identifier ((const char *) ostr.text);
+         free (const_cast <unsigned char *> (ostr.text));
          switch (get_identifier_kind (args[i]))
            {
            case cik_keyword:
@@ -7619,7 +7623,7 @@ eval_exception__S_exception_cvt_tofrom_utf8 (location_t 
loc,
      of non-UTF8 SOURCE_CHARSET.  First translate from {exec charset,UTF-8} to
      SOURCE_CHARSET...  */
   cpp_string istr, ostr;
-  istr.len = TREE_STRING_LENGTH (str) + 1;
+  istr.len = TREE_STRING_LENGTH (str);
   istr.text = (const unsigned char *) TREE_STRING_POINTER (str);
   const char *name;
   if (!cpp_translate_string (parse_in, &istr, &ostr,

base-commit: d93190f056f9725a614c731519aef5bbe4afd53c
-- 
2.56.1

Reply via email to