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 8 6320
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.
On Sep 24, 11:35*am, puzzlecracker <ironsel2...@gm ail.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.
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?
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.
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 &
I thought c_str() returning const char *...Hmm
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:ja******* **@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
puzzlecracker wrote:
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
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 3rd party api for sending the email, the api is written in c,
so i need to convert the string into LPSTR (windows c style string?),
i'm from unix world and new to windows mutant.
I know that c_str() converts a string to a c string and data()...
|
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 so they can
return a pointer to their internal buffer, or are
they equally likely to create a new buffer on demand?
I know the standard doesn't require any particular
implementation, which is why I'm curious if there is
a consensus among...
|
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 instances of
std::string in that implementation. I did not find anything that
|
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*
c_str() const
{
// MT: This assumes concurrent writes are OK.
size_type __n = this->size();
traits_type::assign(_M_data(), _Rep::_S_terminal);
|
by: Alex Vinokur |
last post by:
I have got two functions:
void foo1(char* str)
{
// Stuff
}
void foo2(int size)
{
char* str;
| |
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 an Error according to the Standard.
But I need to pass it to a function (in an old and unpleasant C library, ugh)
which takes an ordinary char*. What should I do? Is it really necessary to make
a fresh copy of the string?
(I'm not asking this...
|
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()" function, which copies
the chars from the vector into an array and return the pointer, I
think I need add another char array to my "Str" class. Now, the
problem is the size of the array has to be known in advance, but
obviously, the array's size...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
| |
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |