Does STLPort have a problem with the standard string and assignment?
I am sure I am reading something incorrectly, but I don't know what:
Here is a summary of a few functions
_Self& append(_ForwardIter __first,
_ForwardIter __last,
forward_iterator_tag)
....
/* Get the length of the data we are assigning into the string */
const size_type __old_size = size();
difference_type __n = 0;
distance(__first, __last, __n);
/* If there is there is not enough room for it, then allocate and
copy. Otherwise just copy *.
if (__old_size + __n > capacity()) {
//Allocate and copy
}
else
{
//Copy
}
Now, all of that is fine. If the string is totally empty, then
(begin() and end() are both NULL) then we should allocate and copy.
The only problem is that the capacity function looks like this:
size_type capacity() const
{ return (_M_end_of_storage._M_data - _M_start) - 1; }
So, if the data is 0, and the start is 0, then we subract one and
return it. Unfortunately, the returntype is unsigned, so this becomes
a very large number. This causes the comparision against copy to
succeed when it should fail.
What am I missing? 1 1514
"A.L" <ca********@earthlink.net> wrote in message
news:41************************@posting.google.com ... Does STLPort have a problem with the standard string and assignment? I am sure I am reading something incorrectly, but I don't know what:
Here is a summary of a few functions
_Self& append(_ForwardIter __first, _ForwardIter __last, forward_iterator_tag) ... /* Get the length of the data we are assigning into the string */ const size_type __old_size = size(); difference_type __n = 0; distance(__first, __last, __n);
/* If there is there is not enough room for it, then allocate and copy. Otherwise just copy *.
if (__old_size + __n > capacity()) { //Allocate and copy } else { //Copy }
Now, all of that is fine. If the string is totally empty, then (begin() and end() are both NULL) then we should allocate and copy. The only problem is that the capacity function looks like this:
If the string is empty, then begin() == end(). They are not null. size_type capacity() const { return (_M_end_of_storage._M_data - _M_start) - 1; }
So, if the data is 0, and the start is 0, then we subract one and return it. Unfortunately, the returntype is unsigned, so this becomes a very large number. This causes the comparision against copy to succeed when it should fail.
Did you debug and saw that _M_end_of_storage._M_data and _M_start are 0? Or
you just assumed?
What am I missing?
How about, what if _M_end_of_storage._M_data is 1 past the end of string?
Actually capacity tells you the _capacity_ not the _length_ of the string so
I think that even an empty string has a capacity > 0.
Hope it helped.
Dan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Gary |
last post by:
I am trying to compile the STLPORT 4.5.3 using g++ 3.3 compiler on sun. I
have modified the stl_gcc.h file to point to the correct include path for
the compiler.
I am getting the following errors:...
|
by: Icosahedron |
last post by:
I'm sure it's been done. I'm sure that I'm an idiot for
even asking the question, but has anyone been successful in
getting Comeau 4.3.0.1 to compile STLPort, or even use
STLPort in a program...
|
by: pervinder |
last post by:
Hi,
When i link a C++ test app with stlport, it throws some errors on AIX
like
Linking ../../output/AIX_32/bin/test
"/hm/test/stlport/stl/_fstream.h", line 30.11: 1540-0836 (S) The
#include...
|
by: programmer_pete |
last post by:
I am trying to switch to STLPort 4.6.2 from the MSVC STL.
My project uses Spirit 1.6.0 and MSVC++ 6.
I have configured STLPort as follows:
#define _STLP_NO_OWN_IOSTREAMS 1
#define...
|
by: Boris |
last post by:
Hi,
I'm using STLport-4.5.3 with Visual C++ 6.0 on Windows XP. It seems, the
module built requires MSVCP60.DLL - which (mostly) contains Streams
implementation by Microsoft. So, STLport falls...
|
by: Gernot Frisch |
last post by:
Hi,
we have to use stlport here, but With a code like this:
void DoSomething(int english_version)
{
// make no use of english_version
}
|
by: PangFromChina |
last post by:
Platform:window 2000 professional, VC++6.0 +SP5
STLport: STLport 5.0.2
While test STLport following "STLport README for Microsoft Visual C++
compilers." of README.msvc(readme.txt), there is a...
|
by: Artur Bac |
last post by:
I got a problem with eVc4 i STLPort and i dont known why
c:\stlport-5.0.2\stlport\stl\_construct.h(115) : error C2665: 'new' :
none of
the 2 overloads can convert parameter 2 from type 'struct...
|
by: francois.cppdevs |
last post by:
Hi C++ supporters
I just wanted to let you know that STLport 5.1.0 has been released,
it is available here:
https://sourceforge.net/projects/stlport/
Since 5.0 this library implements some...
|
by: Aman JIANG |
last post by:
vc8 + STLport 5.1.3:
cout << fixed << numeric_limits<double>::max();
It result a runtime error.
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |