[wx-dev] return of wxString::utf8_str()

Vadim Zeitlin vadim at wxwidgets.org
Tue Jul 3 06:15:04 PDT 2007


On Tue, 03 Jul 2007 15:11:36 +0200 Robert Roebling <robert at roebling.de> wrote:

RR> I just saw code in the GNOME printing backend
RR> that does this
RR> 
RR> const char *utf8 = string.utf8_str();
RR> 
RR> and it then uses utf8. How do we know that the string
RR> isn't destroyed afterwards

 It isn'tin UTF-8 build (where utf8_str() just returns the pointer to the
internal representation) but it's definitely a bug in wchar_t Unicode
build or ANSI build. I don't know if we have any type which maps to
char * in UTF-8 build and wxCharBuffer in the others but if not we should
add it and use it here.

RR> I'm aware of that it it probably destroyed at the
RR> end of the method,

 No, this is not true even in practice.

RR> but if I understand it right, this is not defined by C++.

 And accessing the string is definitely undefined in theory.

 Regards,
VZ





More information about the wx-dev mailing list