473,406 Members | 2,816 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,406 software developers and data experts.

Segmentation fault / string allocator question

I have a segmentation fault, and gdb says that the problem is in the
line:

buffer+=(s+' ');

inside the + operator. "buffer" and "s" are both C++ strings. When I
print out
buffer.c_str() and s.c_str() in gdb, I get ordinary strings ... no
null pointers are evident.
The line runs just fine many times in a row, and then mysteriously
fails.
I have pasted in the backtrace from gdb below, up to the point where
it reaches the + operator.

Is it possible that the program is just running out of memory? And if
so, how would I test that? Any other ideas as to what could cause
this? Is there any other useful information I should provide? Thanks
-

#0 std::__default_alloc_template<true, 0>::allocate (__n=41)
at /usr2/SOURCES/S9/gcc-3.3.2/objdir/sparc-sun-solaris2.9/libstdc+
+-v3/include/bits/stl_alloc.h:417
#1 0xff15ab8c in std::string::_Rep::_S_create (__capacity=21,
__alloc=@0xffbbd428)
at /usr2/SOURCES/S9/gcc-3.3.2/objdir/sparc-sun-solaris2.9/libstdc+
+-v3/include/bits/stl_alloc.h:673
#2 0xff15ac84 in std::string::_Rep::_M_clone (this=0x25b6b0,
__alloc=@0xffbbd428, __res=1)
at /usr2/SOURCES/S9/gcc-3.3.2/objdir/sparc-sun-solaris2.9/libstdc+
+-v3/include/bits/basic_string.tcc:582
#3 0xff158fdc in std::string::reserve (this=0xffbbd5b8,
__res=4290499624)
at /usr2/SOURCES/S9/gcc-3.3.2/objdir/sparc-sun-solaris2.9/libstdc+
+-v3/include/bits/basic_string.h:408
#4 0xff1593f4 in std::string::append (this=0xffbbd5b8, __n=1, __c=32
' ')
at /usr2/SOURCES/S9/gcc-3.3.2/objdir/sparc-sun-solaris2.9/libstdc+
+-v3/include/bits/basic_string.tcc:718
#5 0x000ba8b8 in std::operator+<char, std::char_traits<char>,
std::allocator<char (__lhs=@0xffbbd5e0, __rhs=32 ' ')

Feb 21 '07 #1
2 3053
* Josh:
I have a segmentation fault, and gdb says that the problem is in the
line:

buffer+=(s+' ');

inside the + operator. "buffer" and "s" are both C++ strings. When I
print out
buffer.c_str() and s.c_str() in gdb, I get ordinary strings ... no
null pointers are evident.
Post a complete small program that exhibits the problem.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Feb 21 '07 #2
Josh wrote:
I have a segmentation fault, and gdb says that the problem is in the
line:

buffer+=(s+' ');

inside the + operator. "buffer" and "s" are both C++ strings. When I
print out
buffer.c_str() and s.c_str() in gdb, I get ordinary strings ... no
null pointers are evident.
The line runs just fine many times in a row, and then mysteriously
fails.
I have pasted in the backtrace from gdb below, up to the point where
it reaches the + operator.

Is it possible that the program is just running out of memory? And if
so, how would I test that? Any other ideas as to what could cause
this? Is there any other useful information I should provide? Thanks
-
Your problem sounds like a classic case of memory corruption.

That's the problem with memory corruption, the crash happens sometime
after the corruption happens. This makes the bug hard to track down.

The answer is to avoid dubious coding styles in the first place, but
that's not likely to be much help to you now. If you can't figure out
wher the bug is then the answer is to methodically reduce the size of
your code. It doesn't matter if the code no longer does anything
sensible, as long as it still compiles and runs. At some point as you
are making your code smaller and smaller the bug will mysteriously go
away. When that happens the last piece of code you removed will likely
be the cause of the memory corruption. When this happens you will be in
a much better position to understand precisely what the problem was, you
will also be a better programmer, having learned a valuable lesson.

john
Feb 21 '07 #3

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

Similar topics

9
by: fudmore | last post by:
Hello Everybody. I have a Segmentation fault problem. The code section at the bottom keeps throwing a Segmentation fault when it enters the IF block for the second time. const int...
3
by: mblome | last post by:
Hi everybody! I came across a very strange problem with stl vectors during developement of a mesh creation program. As the program is quite large I can only post small parts of it. Basically I...
5
by: Fra-it | last post by:
Hi everybody, I'm trying to make the following code running properly, but I can't get rid of the "SEGMENTATION FAULT" error message when executing. Reading some messages posted earlier, I...
7
by: silverburgh.meryl | last post by:
Hi, I have a C++ problem which uses STL containers and algorithm and it has a segmentation fault under some condition. Here is a back trace from gdb. Is it possible to tell what is wrong...
27
by: Paminu | last post by:
I have a wierd problem. In my main function I print "test" as the first thing. But if I run the call to node_alloc AFTER the printf call I get a segmentation fault and test is not printed! ...
1
by: samuel.y.l.cheung | last post by:
Hi, I wrote a template to use copy() algorithm, called copyAll: template<class T> void copyAll(const T& src , T& dest ) { copy (src.begin(), src.end(), back_inserter(dest)); } but when I...
5
by: silverburgh.meryl | last post by:
Hi, I have a segmentation fault in line 66 of GroupResult.h and I can't figure out why that causes any problem, I appreciate if anyone can help. line 66 of Result.h: 66 size_t size()...
7
by: pycraze | last post by:
I would like to ask a question. How do one handle the exception due to Segmentation fault due to Python ? Our bit operations and arithmetic manipulations are written in C and to some of our...
10
by: sagitalk | last post by:
Here is my code: #include <iostream> #include <vector> #include <fstream> #include <stdio.h> #include <string> #include <cstring> using namespace std;
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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
agi2029
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,...
0
isladogs
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...

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.