On Sep 24, 3:34 pm, Juha Nieminen <nos...@thanks. invalidwrote:
>puzzlecracke r wrote:
>>Any ideas what may cause that for the string class to core dump?
>>#0 0x0018de92 in std::string::c_ str () from /usr/lib/libstdc++.so.5
> Yes: You are accessing out of bounds somewhere.
>>
> Run your program with valgrind.
>
Argh, I traced why it happened, and modified my code, removing the
stupidity. Here what I had:
>
void foo(std::string &str)
{
>
}
>
>
void bar(std::string str)
{
foo(str.c_str() );
}
That shouldn't compile. You're trying to bind a non-const reference to
a temporary object (created from the pointer to char you get by calling
the 'c_str()'). That's not allowed. Begin by dialing up the warning
level on your compiler and possibly by disabling extensions you're not
consciously using.
OTOH, there is nothing in this particular code that would cause the
crash. Are you sure you're not trying to access 'c_str' member using an
invalid reference?
Never used valgrind before. How does it work?
It works quite well.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
On Sep 24, 5:35 pm, Victor Bazarov <v.Abaza...@com Acast.netwrote:
puzzlecracker wrote:
On Sep 24, 3:34 pm, Juha Nieminen <nos...@thanks. invalidwrote:
puzzlecracker wrote:
>Any ideas what may cause that for the string class to core dump?
>#0 0x0018de92 in std::string::c_ str () from /usr/lib/libstdc++.so.5
Yes: You are accessing out of bounds somewhere.
>
Run your program with valgrind.
>
Argh, I traced why it happened, and modified my code, removing the
stupidity. Here what I had:
>
void foo(std::string &str)
{
>
}
>
void bar(std::string str)
{
foo(str.c_str() );
}
>
That shouldn't compile. You're trying to bind a non-const reference to
a temporary object (created from the pointer to char you get by calling
the 'c_str()'). That's not allowed. Begin by dialing up the warning
level on your compiler and possibly by disabling extensions you're not
consciously using.
>
OTOH, there is nothing in this particular code that would cause the
crash. Are you sure you're not trying to access 'c_str' member using an
invalid reference?
>
Never used valgrind before. How does it work?
>
It works quite well.
>
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Argh, I was passing string in Foo as a const std::string &
On Sep 25, 3:50 am, puzzlecracker <ironsel2...@gm ail.comwrote:
On Sep 24, 5:35 pm, Victor Bazarov <v.Abaza...@com Acast.netwrote:
puzzlecracker wrote:
On Sep 24, 3:34 pm, Juha Nieminen <nos...@thanks. invalidwrote:
>puzzlecracke r wrote:
>>Any ideas what may cause that for the string class to core dump?
>>#0 0x0018de92 in std::string::c_ str () from /usr/lib/libstdc++.so.5
> Yes: You are accessing out of bounds somewhere.
> Run your program with valgrind.
Argh, I traced why it happened, and modified my code, removing the
stupidity. Here what I had:
void foo(std::string &str)
{
}
void bar(std::string str)
{
foo(str.c_str() );
}
That shouldn't compile. You're trying to bind a non-const
reference to a temporary object (created from the pointer to
char you get by calling the 'c_str()'). That's not allowed.
Begin by dialing up the warning level on your compiler and
possibly by disabling extensions you're not consciously
using.
OTOH, there is nothing in this particular code that would
cause the crash. Are you sure you're not trying to access
'c_str' member using an invalid reference?
Never used valgrind before. How does it work?
It works quite well.
Argh, I was passing string in Foo as a const std::string &
I thought c_str() returning const char *...Hmm
It does, but there is an implicit conversion from char const* to
std::string.
And as Victor said, there's no reason in the code you posted for
anything not to work. You're probably overwriting memory
somewhere else. Valgrind is free; download it and use it.
--
James Kanze (GABI Software) email:james.kan ze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
On Sep 24, 5:35 pm, Victor Bazarov <v.Abaza...@com Acast.netwrote:
>puzzlecracke r wrote:
>>On Sep 24, 3:34 pm, Juha Nieminen <nos...@thanks. invalidwrote:
>>>puzzlecracke r wrote:
>>>>Any ideas what may cause that for the string class to core dump?
>>>>#0 0x0018de92 in std::string::c_ str () from /usr/lib/libstdc++.so.5
>>> Yes: You are accessing out of bounds somewhere.
>>> Run your program with valgrind.
>>Argh, I traced why it happened, and modified my code, removing the
>>stupidity. Here what I had:
>>void foo(std::string &str)
>>{
>>}
>>void bar(std::string str)
>>{
>> foo(str.c_str() );
>>}
>That shouldn't compile. You're trying to bind a non-const reference to
>a temporary object (created from the pointer to char you get by calling
>the 'c_str()'). That's not allowed. Begin by dialing up the warning
>level on your compiler and possibly by disabling extensions you're not
>consciously using.
>>
>OTOH, there is nothing in this particular code that would cause the
>crash. Are you sure you're not trying to access 'c_str' member using an
>invalid reference?
>>
>>Never used valgrind before. How does it work?
>It works quite well.
>>
>V
>--
>Please remove capital 'A's when replying by e-mail
>I do not respond to top-posted replies, please don't ask
>
Argh, I was passing string in Foo as a const std::string &
So, is it 'Foo' or 'foo'? Something makes me think that you're not
posting your real code. See FAQ 5.8.
>
I thought c_str() returning const char *...Hmm
It does.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
You start valgrind giving it your program (and its possible
command-line parameters) as parameter (similarly to how you would use
eg. the "time" command), and it will report about a wide variety of
possible errors in your program.
Comment