Operating System - HP-UX
1833770 Members
2084 Online
110063 Solutions
New Discussion

SIGBUS immediately after creating C++ object

 
Gary Williams_3
New Member

SIGBUS immediately after creating C++ object

I have run into a problem on 11i (11.11) that seems to have strange behaviors. The code has been working for a long time on NT, Solaris, AIX and HP-UX. I suspect this is a compiler bug, but I wanted to check the forums for help.

I have a C++ class inside of a shared library that is dynamically loaded at run time. When the code is compiled on 10.20, the code runs just fine. When compiled on 11i, it works in some cases, but not others. Here is a snippet of the code:

if (stream == NULL)
{
stream = new CMemoryStream;
THROW_NO_MEMORY(stream, "CPDFFile::StartSave");
}
else
{
stream->Reset();
}
TRACE(qWARNING,("StartSave: Stream has %d bytes\n", stream->GetLength()));
m_pSaveStream = stream;
m_bSaveText = TRUE;

The CMemoryStream looks like this:
class CMemoryStream : public CStream
{
CDynamicArray m_arrBytes;
int m_nSize;
BOOL m_bTextMode;
public:
CMemoryStream(BOOL bTextMode = FALSE);
~CMemoryStream();
int GetLength();
void Reset();
void Write(CStream& strOutput);
void Write(LPCBYTE pData, int len);
int Read(LPCBYTE pData, int max);
};

and the base class looks like this:
// The base class for a stream.
class CStream
{
protected:
long m_nPosition; // The current position in the stream.
public:
CStream();
virtual ~CStream();
virtual long GetPosition();
virtual void GotoPosition(long nPosition);
virtual int GetLength();
virtual void Reset();
virtual void Write(LPCBYTE pData, int len);
virtual int Read(LPCBYTE, int max);
virtual void Flush();
};

Now the problem I have is that the object is not getting constructed properly in those cases where I get the SIGBUS errors. The virtual function table looks like garbage, as well as other members of the CMemoryStream class, and of course, the first attempt to call a virtual function results in the SIGBUS error. Sometimes.

The compiler flags are as follows:
Setting Makefile Macro $VISTAHOME=/vista/garyw/4.4/server
aCC -c +Z -DHPUX_11_00 -DUNIX -DvHPUX -D_HPUX_SOURCE -D_REENTRANT -D_RWSTD_MULTI_THREAD +Z -AA +DA1.1 -D_POSIX_SOURCE -D_XOPEN_SOURCE_EXTENDED +W749,495,67,503 -oHP-UX-B.11.11/PDFFile.o -D_DEBUG -g -DSMARTHEAP -I/opt/SmartHeap/include -I. -I../include -I../../include -I../../winclude -I.. PDFFile.cpp
(cd HP-UX-B.11.11; ld +b.:/lib:/usr/lib -h_Lib -b DllMain.o vpf2html.o VPFFile.o RenditionFile.o HTMLFile.o RTFFile.o PDFFile.o StreamOutput.o StreamFilter.o Report.o ASCIIFile.o XMLFile.o -L/opt/SmartHeap/lib -lsmartheap_smp -lpthread -o libRendition.sl -L../../../../lib/HP-UX-B.11.11 -lServices -lSvcMgr -lttl -lCsup_v2 -lstd_v2; cp libRendition.sl ../../../../lib/HP-UX-B.11.11)

Anyone care to enlighten me on what I may be going wrong?
1 REPLY 1
Gary Williams_3
New Member

Re: SIGBUS immediately after creating C++ object

Found the problem. Someone left out the -Bsymbolic flag from the linker options.