You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stdcxx.apache.org by John Hollis <jo...@roguewave.com> on 2005/09/15 06:09:21 UTC

RE: [jira] Commented: (STDCXX-25) string::insert() curruption ins erting self

I think I once tracked this down to the fact the somewhere (in traits,
perhaps) it's calling memcpy and the memcpy is copying the bytes in reverse
order, so the way to fix it is to copy a single charT at a time when the
string being inserted is part of the string being inserted into.

John


-----Original Message-----
From: Martin Sebor (JIRA) [mailto:jira@apache.org] 
Sent: Wednesday, September 14, 2005 6:48 PM
To: stdcxx-dev@incubator.apache.org
Subject: [jira] Commented: (STDCXX-25) string::insert() curruption inserting
self

    [
http://issues.apache.org/jira/browse/STDCXX-25?page=comments#action_12329375
] 

Martin Sebor commented on STDCXX-25:
------------------------------------

See the failures in 21.string.insert.cpp:

$ ./21.string.insert --severity=7
# ASSERTION (S7) (4 lines):
# TEXT: basic_string<char>::insert (iterator, const_pointer, const_pointer)
expected "aabb", got "aaab"
# CLAUSE: lib.string.insert
# LINE: 190

# ASSERTION (S7) (4 lines):
# TEXT: basic_string<char>::insert (iterator, const_pointer, const_pointer)
expected "baabb", got "aaaab"
# CLAUSE: lib.string.insert
# LINE: 200

# ASSERTION (S7) (4 lines):
# TEXT: basic_string<wchar_t>::insert (iterator, const_pointer,
const_pointer) expected "aabb", got L"aaab"
# CLAUSE: lib.string.insert
# LINE: 190

# ASSERTION (S7) (4 lines):
# TEXT: basic_string<wchar_t>::insert (iterator, const_pointer,
const_pointer) expected "baabb", got L"aaaab"
# CLAUSE: lib.string.insert
# LINE: 200

# +-----------------------+--------+--------+--------+
# | DIAGNOSTIC            | ACTIVE |  TOTAL |   PASS |
# +-----------------------+--------+--------+--------+
# | (S1) INFO             |     25 |     25 |     0% |
# | (S5) WARNING          |      6 |      6 |     0% |
# | (S7) ASSERTION        |      4 |     70 |    94% |
# +-----------------------+--------+--------+--------+


> string::insert() curruption inserting self
> ------------------------------------------
>
>          Key: STDCXX-25
>          URL: http://issues.apache.org/jira/browse/STDCXX-25
>      Project: STDCXX
>         Type: Bug
>   Components: 21. Strings
>     Versions: 4.1.2
>  Environment: All
>     Reporter: Martin Sebor
>     Assignee: Martin Sebor
>      Fix For: 4.1.3

>
> The program below aborts. According to 21.3.5.4, p16 of C++ '03, the
effects of the insert member function template are "Equivalent to insert(p -
begin(), basic_string(first, last))." See also
http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#7.
> $ cat t.cpp && nice gmake SRCS=t.cpp && ./t
> #include <cassert>
> #include <string>
> int main ()
> {
>      std::string s ("ab");
>      s.insert (s.begin () + 1, s.data (), s.data () + s.length ());
>      assert ("aabb" == s);
> }
> aCC -c  -D_RWSTDDEBUG  -D_RWSTD_USE_CONFIG
-I/build/sebor/dev/stdlib/../../aCC-6.0-11s/include
-I/build/sebor/dev/stdlib/include -I/build/sebor/dev/stdlib/../rwtest
-I/build/sebor/dev/stdlib/../rwtest/include
-I/build/sebor/dev/stdlib/tests/include  -AA -g +d   +w +W392 +W655 +W684
+W818 +W819 +W849 +W2193 +W2236 +W2261 +W2340 +W2401 +W2487  t.cpp 
> aCC t.o -o t -L/build/sebor/dev/stdlib/../../aCC-6.0-11s/rwtest -lrwtest
-AA +nostl -Wl,+s -L/build/sebor/dev/stdlib/../../aCC-6.0-11s/lib
-L/build/sebor/dev/stdlib/../../aCC-6.0-11s/lib -lstd   -lm  
> Assertion failed: "aabb" == s, file t.cpp, line 10
> ABORT instruction (core dumped)

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira

Re: [jira] Commented: (STDCXX-25) string::insert() curruption inserting self

Posted by Martin Sebor <se...@roguewave.com>.
John Hollis wrote:
> I think I once tracked this down to the fact the somewhere (in traits,
> perhaps) it's calling memcpy and the memcpy is copying the bytes in reverse
> order, so the way to fix it is to copy a single charT at a time when the
> string being inserted is part of the string being inserted into.

That might be one approach. There already is a partially implemented
fix for this (see QA #23293) but it only works for string::iterators
and not for pointers. I have a patch that's based on the fix for the
QA PR that I already sent to Kostas (it's in our bugzilla -- see the
link below). Let me attach it to the bug.

Martin

http://iwww.cvo.roguewave.com/bugzilla/show_bug.cgi?id=688

> 
> John
> 
> 
> -----Original Message-----
> From: Martin Sebor (JIRA) [mailto:jira@apache.org] 
> Sent: Wednesday, September 14, 2005 6:48 PM
> To: stdcxx-dev@incubator.apache.org
> Subject: [jira] Commented: (STDCXX-25) string::insert() curruption inserting
> self
> 
>     [
> http://issues.apache.org/jira/browse/STDCXX-25?page=comments#action_12329375
> ] 
> 
> Martin Sebor commented on STDCXX-25:
> ------------------------------------
> 
> See the failures in 21.string.insert.cpp:
> 
> $ ./21.string.insert --severity=7
> # ASSERTION (S7) (4 lines):
> # TEXT: basic_string<char>::insert (iterator, const_pointer, const_pointer)
> expected "aabb", got "aaab"
> # CLAUSE: lib.string.insert
> # LINE: 190
> 
> # ASSERTION (S7) (4 lines):
> # TEXT: basic_string<char>::insert (iterator, const_pointer, const_pointer)
> expected "baabb", got "aaaab"
> # CLAUSE: lib.string.insert
> # LINE: 200
> 
> # ASSERTION (S7) (4 lines):
> # TEXT: basic_string<wchar_t>::insert (iterator, const_pointer,
> const_pointer) expected "aabb", got L"aaab"
> # CLAUSE: lib.string.insert
> # LINE: 190
> 
> # ASSERTION (S7) (4 lines):
> # TEXT: basic_string<wchar_t>::insert (iterator, const_pointer,
> const_pointer) expected "baabb", got L"aaaab"
> # CLAUSE: lib.string.insert
> # LINE: 200
> 
> # +-----------------------+--------+--------+--------+
> # | DIAGNOSTIC            | ACTIVE |  TOTAL |   PASS |
> # +-----------------------+--------+--------+--------+
> # | (S1) INFO             |     25 |     25 |     0% |
> # | (S5) WARNING          |      6 |      6 |     0% |
> # | (S7) ASSERTION        |      4 |     70 |    94% |
> # +-----------------------+--------+--------+--------+
> 
> 
> 
>>string::insert() curruption inserting self
>>------------------------------------------
>>
>>         Key: STDCXX-25
>>         URL: http://issues.apache.org/jira/browse/STDCXX-25
>>     Project: STDCXX
>>        Type: Bug
>>  Components: 21. Strings
>>    Versions: 4.1.2
>> Environment: All
>>    Reporter: Martin Sebor
>>    Assignee: Martin Sebor
>>     Fix For: 4.1.3
> 
> 
>>The program below aborts. According to 21.3.5.4, p16 of C++ '03, the
> 
> effects of the insert member function template are "Equivalent to insert(p -
> begin(), basic_string(first, last))." See also
> http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#7.
> 
>>$ cat t.cpp && nice gmake SRCS=t.cpp && ./t
>>#include <cassert>
>>#include <string>
>>int main ()
>>{
>>     std::string s ("ab");
>>     s.insert (s.begin () + 1, s.data (), s.data () + s.length ());
>>     assert ("aabb" == s);
>>}
>>aCC -c  -D_RWSTDDEBUG  -D_RWSTD_USE_CONFIG
> 
> -I/build/sebor/dev/stdlib/../../aCC-6.0-11s/include
> -I/build/sebor/dev/stdlib/include -I/build/sebor/dev/stdlib/../rwtest
> -I/build/sebor/dev/stdlib/../rwtest/include
> -I/build/sebor/dev/stdlib/tests/include  -AA -g +d   +w +W392 +W655 +W684
> +W818 +W819 +W849 +W2193 +W2236 +W2261 +W2340 +W2401 +W2487  t.cpp 
> 
>>aCC t.o -o t -L/build/sebor/dev/stdlib/../../aCC-6.0-11s/rwtest -lrwtest
> 
> -AA +nostl -Wl,+s -L/build/sebor/dev/stdlib/../../aCC-6.0-11s/lib
> -L/build/sebor/dev/stdlib/../../aCC-6.0-11s/lib -lstd   -lm  
> 
>>Assertion failed: "aabb" == s, file t.cpp, line 10
>>ABORT instruction (core dumped)
> 
>