473,395 Members | 1,677 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

core dump due to string::c_str ()

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
Sep 24 '08 #1
8 6279
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.
Sep 24 '08 #2
On Sep 24, 11:35*am, puzzlecracker <ironsel2...@gmail.comwrote:
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
Come on Puzzlecracker, you should know FAQ 5.8 by now.

There is an error on line 42 of your code.

Post a minimal, compileable example that exhibits the behavior in
question.
Sep 24 '08 #3
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());
}
Never used valgrind before. How does it work?

Sep 24 '08 #4
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
Sep 24 '08 #5
On Sep 24, 5:35 pm, Victor Bazarov <v.Abaza...@comAcast.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 &

I thought c_str() returning const char *...Hmm
Sep 25 '08 #6
On Sep 25, 3:50 am, puzzlecracker <ironsel2...@gmail.comwrote:
On Sep 24, 5:35 pm, Victor Bazarov <v.Abaza...@comAcast.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.
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:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Sep 25 '08 #7
puzzlecracker wrote:
On Sep 24, 5:35 pm, Victor Bazarov <v.Abaza...@comAcast.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 &
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
Sep 25 '08 #8
puzzlecracker wrote:
Never used valgrind before. How does it work?
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.
Sep 25 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tony Murphy | last post by:
I've got an application that sends emails (not spam!). The application reads a template file (html/text) into a string, the string is processed and placeholders filled in as appropiate. I call a...
15
by: Derek | last post by:
I'm curious about the performance of string::c_str, so I'm wondering how it's commonly implemented. Do most std::string implementations just keep an extra char allocated for the NULL termination...
2
by: Vyacheslav Kononenko | last post by:
All, If I am not mistaken I had some problems with code like this: std::string foo, bar; .... somefunc( foo.c_str(), bar.c_str() ); Problem was that c_str() used buffer shared btw...
18
by: Metro12 | last post by:
In the <basic_string.h>, I find the implementation of these two functions. But I can't understand the difference between them. Please give me some help! //basic_string::c_str() const _CharT*...
4
by: Alex Vinokur | last post by:
I have got two functions: void foo1(char* str) { // Stuff } void foo2(int size) { char* str;
5
by: Tom Smith | last post by:
I hardly dare ask this given the furore in another thread over strings and const... My problem is this. I am assured that casting away the constness of the return value of std::string::c_str() is...
8
by: Jess | last post by:
Hello, I'm doing an exercise that defines a new abstract class "Str" that has the same functions as "string" class, which holds a vector of chars. But since I'm also trying to define a "c_str()"...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.