Dangling pointer in ICF from c_str method.
Ian Lance Taylor
iant@google.com
Wed Feb 2 21:48:00 GMT 2011
Sriraman Tallam <tmsriram@google.com> writes:
> 2011-02-02 Sriraman Tallam <tmsriram@google.com>
>
> * icf.h (is_section_foldable_candidate): Change type of parameter
> to std::string.
> * icf.cc (Icf::find_identical_sections): Change type of local variable
> section_name to be std::string.
> (is_function_ctor_or_dtor): Change type of parameter to std::string.
> static bool
> -is_function_ctor_or_dtor(const char* mangled_func_name)
> +is_function_ctor_or_dtor(const std::string& section_name)
> {
> - if ((is_prefix_of("_ZN", mangled_func_name)
> - || is_prefix_of("_ZZ", mangled_func_name))
> - && (is_gnu_v3_mangled_ctor(mangled_func_name)
> - || is_gnu_v3_mangled_dtor(mangled_func_name)))
> + const char* mangled_func_name = strrchr(section_name.c_str(), '.');
> + gold_assert (mangled_func_name != NULL);
No space before parenthesis.
> @@ -696,7 +697,7 @@ Icf::find_identical_sections(const Input
>
> for (unsigned int i = 0;i < (*p)->shnum(); ++i)
> {
> - const char* section_name = (*p)->section_name(i).c_str();
> + const std::string& section_name = (*p)->section_name(i);
Make this a normal variable rather than a reference. That is, drop the
'&'. I think your code is correct but there is no need for a reference
here; RVO should apply, I think.
This is OK with those changes.
Thanks.
Ian
More information about the Binutils
mailing list