473,785 Members | 2,989 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bug in std containers?


Hi

I have a really weird bug. An object in my program contains a
std::stack<T>. When push is called, the program crashes. To eliminate
that the error has to do with what is pushed, I create a new local
stack that has nothing to do with any other code. Then I push a 5 and
the program crashes. In detail, i added

stack<doubleane wstack; // Code that has nothing to do with the
rest of the program
anewstack.push( 5);

instead of the call to the other stack (that call I out-commented). If
I remove "irrelevant " code the bug disappears so I can't provide a
small complete program that generates the bug.

Does anyone have any clue how this kind of bug can appear, and be
resolved? Below some output from the debugger. I'm working in Sun
Solaris on a Sun X-Ray computer.
t@1 (l@1) stopped in Solver::feed at line 249 in file "solver.cc"
249 stack<doubleane wstack;
(dbx) next
t@1 (l@1) stopped in Solver::feed at line 250 in file "solver.cc"
250 anewstack.push( 4);
(dbx) next
t@1 (l@1) signal SEGV (no mapping at the fault address) in
_malloc_unlocke d at 0xfed47090
0xfed47090: _malloc_unlocke d+0x023c: ld [%o0 + 8], %o1
Current function is std::allocator< double>::alloca te
391 void * tmp = _RWSTD_STATIC_C AST(void*,(::op erator
new(_RWSTD_STAT IC_CAST(size_t, (n)))));
(dbx)

Nov 16 '06 #1
3 1816
t@1 (l@1) stopped in Solver::feed at line 249 in file "solver.cc"
249 stack<doubleane wstack;
(dbx) next
t@1 (l@1) stopped in Solver::feed at line 250 in file "solver.cc"
250 anewstack.push( 4);
(dbx) next
t@1 (l@1) signal SEGV (no mapping at the fault address) in
_malloc_unlocke d at 0xfed47090
0xfed47090: _malloc_unlocke d+0x023c: ld [%o0 + 8], %o1
Current function is std::allocator< double>::alloca te
391 void * tmp = _RWSTD_STATIC_C AST(void*,(::op erator
new(_RWSTD_STAT IC_CAST(size_t, (n)))));
(dbx)

Ok. I have a theory: Somewhere I write outside allocated memory. This
corrupts data malloc needs for allocation, and hence an ordinary buffer
overflow causes malloc to crash later on.

Nov 16 '06 #2
<ja****@gmail.c omwrote in message
news:11******** **************@ h48g2000cwc.goo glegroups.com.. .
>
>t@1 (l@1) stopped in Solver::feed at line 249 in file "solver.cc"
249 stack<doubleane wstack;
(dbx) next
t@1 (l@1) stopped in Solver::feed at line 250 in file "solver.cc"
250 anewstack.push( 4);
(dbx) next
t@1 (l@1) signal SEGV (no mapping at the fault address) in
_malloc_unlock ed at 0xfed47090
0xfed47090: _malloc_unlocke d+0x023c: ld [%o0 + 8], %o1
Current function is std::allocator< double>::alloca te
391 void * tmp = _RWSTD_STATIC_C AST(void*,(::op erator
new(_RWSTD_STA TIC_CAST(size_t ,(n)))));
(dbx)


Ok. I have a theory: Somewhere I write outside allocated memory. This
corrupts data malloc needs for allocation, and hence an ordinary buffer
overflow causes malloc to crash later on.
Yep, that was going to be my suggestion. Most bugs of this type (I change
something that should absolutely have nothing to do with it and the behavior
changes) has to do with corrputed memory. You wrote somewhere you shouldn't
of. Buffer over, unallocated pointer, etc...
Nov 16 '06 #3
Hi

ja****@gmail.co m wrote:
stack<doubleane wstack; // Code that has nothing to do with the
rest of the program
anewstack.push( 5);

instead of the call to the other stack (that call I out-commented). If
I remove "irrelevant " code the bug disappears so I can't provide a
small complete program that generates the bug.
Ever thought that the code you removed might not be irrelevant at all? :-)
This is something that very much looks like undefined behavior. You have
done something wrong before which now causes a crash. That's the bad thing
with undefined behavior: your program might run, but it might also crash at
any time.
Does anyone have any clue how this kind of bug can appear, and be
resolved? Below some output from the debugger. I'm working in Sun
Solaris on a Sun X-Ray computer.
Look for the bug in your program. Those generally include free/delete-ing
memory twice, falling off the end of a non-void function and so on...
You should turn on all compiler warnings, it might help. If there is some
sort of memory debugger for your platform, it might also be helpful.

Markus

Nov 16 '06 #4

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

Similar topics

13
5008
by: Dylan | last post by:
I'd like to compare two containers. They should be considered equivalent if both containers have the same number of elements with the same values, no matter what order the values are in. For instance the containers A = B = are obviously equal, but so would be
14
8220
by: phil_gg04 | last post by:
Dear C++ Experts, Over the last couple of months I have been writing my first program using shared memory. It has been something of an "in-at-the-deep-end" experience, to say the least. At present the shared memory contains a few fixed-size structs, but I really need to be able to store more complex variable-sized data in there. So the next task is to work out how to store C++ objects, and if possible STL containers, in this shared...
18
3061
by: Matthias Kaeppler | last post by:
Hi, in my program, I have to sort containers of objects which can be 2000 items big in some cases. Since STL containers are based around copying and since I need to sort these containers quite frequently, I thought it'd be a better idea to manage additional containers which are initialized with pointers to the objects in the primary containers and sort those (only pointers have to be copied around then). However, that also means if I...
8
3954
by: Gregory | last post by:
I have a question about using STL containers in C++ class public interface. Lets say that I want to return some container from class method or accept class method parameter as some container. For example: class A { public: const vector<int>& getTable() { return m_table; }
2
1600
by: bob | last post by:
Hi, Given: 1) Custom containers that have nothing to do with vector, deque, list, map etc, 2) a custom version of new and delete defined for these containers, customNew and customDelete, say. When an item is to be inserted/removed into/from these custom containers, customNew and customDelete is called.
1
2272
by: Jean-Marc Blaise | last post by:
IBM recommends to place each ts container on a different physical disk. What about the impacts if all containers (DMS) are in the same FS (supported by multiple disks) ? Does DB2 preallocate doing // IO, so we could assume to have, for 2 containers as exemple: Ext1ct1, Ext1ct2, Ext2ct1, Ext2ct2
4
2585
by: Michel Esber | last post by:
Hello, DB2 V8 FP12 LUW. My system is under heavy wait-io times. I have read the following article: http://tinyurl.com/p844z and it says that prefetchsize should be the product of extentsize and the number of containers.
35
2860
by: dragoncoder | last post by:
Just a simple theoritical question to the experts. What was the rationale behind making STL containers follow copy semantics rather than reference semantics. References almost always make things easier without much of overhead. Then why not reference ? Thanks /P
15
4099
by: Nindi73 | last post by:
HI If I define the class DoubleMap such that struct DoubleMap : public std::map<std::string, double>{}; Is there any overhead in calling std::map member functions ? Moreover are STL containers destructors virtual >
11
1930
by: jimxoch | last post by:
Hi list, Most STL containers are storing their data on the heap. (although some std::string implementations are notable exceptions) Of course, using the heap as storage increases flexibility and allows the handling of much bigger amounts of data. However, there are cases where this turns out to be inefficient for at least two reasons: A) Allocations and deallocations on heap are much slower. B) Memory access on stack is more cache...
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10330
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10093
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,...
0
8976
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, 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...
1
7500
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 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...
0
6740
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();...
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3654
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2880
bsmnconsultancy
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...

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.