473,381 Members | 1,399 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,381 software developers and data experts.

problem while running a STL CPP application.

Hi,

I am facing a problem while running a STL CPP application Compiled
using gcc in Solaris environment.

Following is the code :
#include <set>
{
template <class SerImp>
class Services
{
public:
void Add(SerImp *TOSer)
{
if (TOSer)
m_list.insert(TOSer);
}

void Remove(SerImp *TOSer)
{
m_list.erase(TOSer);
}
protected:
typedef std::set<SerImp*> SerL;
typedef SerL::iterator SerIter;
SerL m_list;
};
Whenever I try to do "m_list.insert(TOSer)" the application is
giving Segmentation fault.
This is the call stack.

#0 0xfef64ac8 in std::_Rb_tree_decrement (__x=0xff35356c)
at /rsft/users/akankari/gcc-3.4.2/libstdc++-v3/src/tree.cc:94

#1 0xff2839a8 in std::_Rb_tree_iterator<R::BaseSerImp*>::operator--
(this=0xffbef3f0) at stl_tree.h:195

#2 0xff283434 in std::_Rb_tree<R::BaseSerImp*, R::BaseSerImp*,
std::_Identity<R::BaseSerImp*>, std::less<R::BaseSerImp*>,
std::allocator<R::BaseSerImp*> >::insert_unique (this=0xff353568,
__v=@0xffbef550) at stl_tree.h:877

#3 0xff282f08 in std::set<R::BaseSerImp*, std::less<R::BaseSerImp*>,
std::allocator<R::BaseSerImp*> >::insert (this=0xff353568,
__x=@0xffbef550) at stl_set.h:314

#4 0xff282bf0 in Services<R::BaseSerImp>::Add (this=0xff353568,
TOSer=0x246d8) at Services.h:48
Can anybody suggest what the reason for this Segmentation fault is? We
have to use any special switch while compiling this application because
the same application is working fine in windows?

Thanks,
Vinu

Dec 28 '05 #1
6 2340
Vinu wrote:
Hi,

I am facing a problem while running a STL CPP application Compiled
using gcc in Solaris environment.

Following is the code :
#include <set>
{
template <class SerImp>
class Services
{
public:
void Add(SerImp *TOSer)
{
if (TOSer)
m_list.insert(TOSer);
}

void Remove(SerImp *TOSer)
{
m_list.erase(TOSer);
}
protected:
typedef std::set<SerImp*> SerL;
typedef SerL::iterator SerIter;
SerL m_list;
};
The code is alright.
Whenever I try to do "m_list.insert(TOSer)" the application is
giving Segmentation fault.
Looks like something gets corrupted *before* this call. We've got no
way to know what.
Can anybody suggest what the reason for this Segmentation fault is? We
have to use any special switch while compiling this application because
the same application is working fine in windows?


This may be because your program has undefined behavior: it may crash
at any moment. It just happens to work on Windows. Double check
accesses to the set (derived classes have access to it, remember) and
operations on memory around this class. It is impossible to help you
more unless you can give some more context.
Jonathan

Dec 28 '05 #2

Jonathan Mcdougall wrote:
Vinu wrote:
Hi,

I am facing a problem while running a STL CPP application Compiled
using gcc in Solaris environment.

Following is the code :
#include <set>
{
template <class SerImp>
class Services
{
public:
void Add(SerImp *TOSer)
{
if (TOSer)
m_list.insert(TOSer);
}

void Remove(SerImp *TOSer)
{
m_list.erase(TOSer);
}
protected:
typedef std::set<SerImp*> SerL;
typedef SerL::iterator SerIter;
SerL m_list;
};


The code is alright.
Whenever I try to do "m_list.insert(TOSer)" the application is
giving Segmentation fault.


Looks like something gets corrupted *before* this call. We've got no
way to know what.
Can anybody suggest what the reason for this Segmentation fault is? We
have to use any special switch while compiling this application because
the same application is working fine in windows?


This may be because your program has undefined behavior: it may crash
at any moment. It just happens to work on Windows. Double check
accesses to the set (derived classes have access to it, remember) and
operations on memory around this class. It is impossible to help you
more unless you can give some more context.
Jonathan

In another file I created one global object of class BaseServices which
is derived from the "class Services"
BaseServices gBaseServices;

gBaseServices.Add(ptr);

Here ptr is valid pointer . while debugging it is going to th function
Add(ptr).

Crashing on m_list.insert(TOSer); this line.

Vinu Warrier

Dec 28 '05 #3
Vinu wrote:
Jonathan Mcdougall wrote:
Vinu wrote:
Hi,

I am facing a problem while running a STL CPP application Compiled
using gcc in Solaris environment.


This may be because your program has undefined behavior: it may crash
at any moment. It just happens to work on Windows. Double check
accesses to the set (derived classes have access to it, remember) and
operations on memory around this class. It is impossible to help you
more unless you can give some more context.


In another file I created one global object of class BaseServices which
is derived from the "class Services"

BaseServices gBaseServices;
gBaseServices.Add(ptr);

Here ptr is valid pointer . while debugging it is going to th function
Add(ptr).

Crashing on m_list.insert(TOSer); this line.


Again, this code is probably not the problem. I know it is frustrating
for you, but understand that the code you provided is valid. It should
not crash by itself.

What makes it crash is what happens before. Unfortunately, a lot may be
happening before. You may have a zillion lines of code executing before
that point. What went wrong? You'll have to find out.

Try to skip parts of the program to see if it solves the problem. You
should be able to comment everything except the portion which calls
BaseServices::Add(). If this works, you know the problem is elsewhere.
Go backward until it crashes and you'll have a better idea what could
cause the problem.

I know it's a pain but it doesn't seem you have any other choices.
Jonathan

Dec 28 '05 #4
When I declare the variable (BaseServices gBaseServices) as a local
variable

gBaseServices.Add(ptr); this is working fine.

Is I have to use any switch while compiling the application with gcc.

Dec 28 '05 #5
pH
Jonathan's right; there's no reason why it shouldn't work by itself. If
it works when gBaseServices is local, that definitely implies that it's
getting damaged beforehand when global.

Does the error occur in isolation - when the only code running is the
class and minimal supporting stuff, and the global variable hasn't been
used beforehand?

You shouldn't need any gcc switch here, as what you're trying to do
should be perfectly standard. I would probably try using a debugger
like gdb to check whether the m_list member is correctly initialised
before the call; you'll probably find it contains some invalid pointer
somewhere (which might be tricky to spot).

You should try and find the minimum amount of code needed to 'break'
it, and perhaps post it here if it's fairly short, if you still can't
find the problem.

Dec 28 '05 #6
Vinu wrote:
When I declare the variable (BaseServices gBaseServices) as a local
variable

gBaseServices.Add(ptr); this is working fine.

Is I have to use any switch while compiling the application with gcc.


This problem maybe caused by using an invalid index on global array
which is thereby corrupting the global gBaseServices. Look at setting a
breakpoint that activates if gBaseServices is changed. If you're lucky
you'll find the erroneous code without hitting too many debug breaks.

JB
Dec 28 '05 #7

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

Similar topics

12
by: SJD | last post by:
I've just read Christoph Schittko's article on XmlSerializer: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnxmlnet/html/trblshtxsd.asp . . . and very informative it is too....
8
by: mytfein | last post by:
Hi Everyone, Background: Another department intends to ftp a .txt file from the mainframe, for me to process. The objective is to write a vb script that would be scheduled to run daily to...
4
by: Chuck | last post by:
Hello everybody, I need to abort execution during start up, while the constructor called by Application.Run is executing. If the database fails to connect during my application's startup I...
2
by: Sammy | last post by:
Everyone, I have this very strange problem and we spent weeks to figure out what's going on. Let me outline the configuration of our system: 1. .NET Framework v. 1.0.3705 2. SQL 2000 SP 3...
11
by: James Warren | last post by:
I just installed VB.net 2003, upgrading from VB6. I tried to open a new ASP.net Web Application and immediately got an error stating that my Web Server isn't running ASP.net version 1.1. I tried...
3
by: Ron L | last post by:
I have an application that I am working on with 2 other developers. The applciation uses Remoting for our calls to SQL Server. We have been developing and testing against our development machines...
4
by: nishi57 | last post by:
I hope I can get some help regarding this issue, which has been going on for a while. I have a desktop user who is having problem running "Stored Procedures". The DB2 Connect application works fine...
3
by: laststubborn | last post by:
Dear Memebers, I have a critical problem. I have an application is running on 64 bit machine. It used to be running on 32 bit machine. That application is using a Stored Procedure that uses...
1
by: DLN | last post by:
Hello all, I'm running into a problem with one of our site's production web applications that was written in VB.net. The web app is running on W2K3/IIS6 and up until this afternoon, was working...
6
by: Tony Johansson | last post by:
Hello! We have a C#.ASP.NET application that runs on a IIS 6. The application contains actually several asp pages but there is no GUI. The application receive an xml file that is processed....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.