Re: basic_string causes crash in _vsnprintf???
- From: WXS <WXS@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 23 Jun 2005 08:47:04 -0700
As someone said both StlPort and CString took great pains to support this
functionality so while it was not a standard STL implementation it was an
implementation specific functionality that could be relied upon from those
vendors.
So the code is not proper to the STL standard baseline implementation but it
is valid for the vendor specific implementations that chose to support it.
It is surprising microsoft's implementation does not given stlport chose to.
I agree with the point it is not proper STL usage as per spec of the STL
standard, just we have a lot of code that relied on a specific implementation
that did work well with the ms crt libraries.
The problem with migrating the code is that anywhere a basic_string was used
we have to make sure there are no calls to ANY variable argument methods
which include any printf family of functions. Even closely examining all the
code would not likely guarantee nothing was missed so I'd like to find a way
to make the basic_string work like it used to.
The options I'm considering to have a better guarantee of success:
1. Checking with MS to see if they encountered this and have an option for
their STL to do this (slim chance but worth a check)
2. Go back to using STL port instead of the MS version of STL
3. create an enhanced CString with stl functionality such that any code
using stl like syntax will work and will support the behavior some code
relied upon.
The last option would be to go through every line of code and examine it to
see if c_str() needs to be called, that seems VERY error prone, so seems like
it is not a good option at this point. I need something that will most
definately work and in the shortest time possible (Usual software development
schedules you know :) )
"Stephen Howe" wrote:
> > Thanks. Was just doing internet searches and found the same thing, that
> does
> > in fact work. The problem is we have a half million lines of code that
> was
> > using stlport and that worked in stlport.
>
> You should _NEVER_ code because it sort of ..."works".
> You should code because it is "correct". Correct according to C++ standard.
> No "undefined behaviour" - a technical term according to the standard.
>
> Correct code is more maintainable. You shift compiler vendor it should still
> work even if the vendors implementation is different under the hood.
>
> Even if you 500,000 lines of code that "work" but it turns out that it is
> just an accident that "work", you should make an effort to correct the lines
> of code. It is an error to write code in C++ that relies on some aspect of
> "undefined behaviour" working the way you expect. I regard this as so severe
> that I would correct it immediately, even 500,000 lines of code. And I would
> fire programmers that write "undefined behaviour" code, particularly if it
> turns out there is a decent alternative which works with _ALL_ compilers.
>
> In the case of std::string, getting a pointer to the internal buffer of
> characters means that member function c_str() should be called. And note
> this is constant so you should never attempt to write to that buffer - it is
> read-only.
>
> > So the question is how to avoid
> > having to do that for every string everywhere in the code. Not sure all
> code
> > would be compatible if a changed everything to a CString instead of a
> > tstring... anyone run into this before?
>
> CString allows you to do that operation.
> But these days, implicit conversion operators are frowned on for classes.
> Better to have explicit named conversions - like std::string - less
> unexpected nasty surprises
>
> Stephen Howe
>
>
>
.
- Follow-Ups:
- Re: basic_string causes crash in _vsnprintf???
- From: Arnaud Debaene
- Re: basic_string causes crash in _vsnprintf???
- From: Stephen Howe
- Re: basic_string causes crash in _vsnprintf???
- From: Carl Daniel [VC++ MVP]
- Re: basic_string causes crash in _vsnprintf???
- References:
- basic_string causes crash in _vsnprintf???
- From: WXS
- Re: basic_string causes crash in _vsnprintf???
- From: Hendrik Schober
- Re: basic_string causes crash in _vsnprintf???
- From: WXS
- Re: basic_string causes crash in _vsnprintf???
- From: Stephen Howe
- basic_string causes crash in _vsnprintf???
- Prev by Date: Re: about the key of map
- Next by Date: Re: about the key of map
- Previous by thread: Re: basic_string causes crash in _vsnprintf???
- Next by thread: Re: basic_string causes crash in _vsnprintf???
- Index(es):
Relevant Pages
|
Loading