https://gcc.gnu.org/g:d66469b5bfe5983ca35a562c89384427f6029a3e
commit r17-6424-gd66469b5bfe5983ca35a562c89384427f6029a3e Author: Marek Polacek <[email protected]> Date: Wed Nov 18 12:44:42 2026 -0500 c++/reflection: fix cpp_translate_string-related nits 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. Reviewed-by: Jakub Jelinek <[email protected]> Diff: --- 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 4137fb64e75d..a7cb236f9b18 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,
