This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH, libstdc++] Make empty std::string storage readonly


On 28 August 2012 16:15, Michael Haubenwallner wrote:
> Hi,
>
> in some old, large, originally C-written application (using gcc-4.2.4 still)
> I did have to find a bug that boils down to something like this:
>
>    std::string x;
>    strcpy( (char*) x.c_str(), "abc");
>
> Any subsequent empty std::string instance did contain "abc" instead of "",
> which was the issue showing up to the user.
>
> My idea what could have helped out here was to make the empty string _Rep
> object readonly (ie. const), to get a segmentation fault along the strcpy.

Does it actually produce a segfault? I suppose it might on some
platforms, but not all, so I'm not sure it's worth changing.

(It seems easier to simply track down and shoot the programmer who
thought it was OK to cast away const on the string! ;-)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]