Mail Archives: djgpp/1997/08/21/09:53:34
Could somebody explain what is wrong in the next piece of code
which is successfully compiled from RHIDE but during execution
breaks with SIGSEGV (if execute from DOS) or SIGABRT (from RHIDE).
Debugging shows that error occures in the next line:
KeyWord=new char[strlen(keyword)]; // Create and fill key field
in the HTNode constructor.
There are declaration part,
constructor implementation and stderr output:
-------------------------------------------------------------
// HTNode declaration
class HTNode {
public:
char *KeyWord; // Title of topic/link
long Seek; // For topic: offset in the file
int Size; // Size in lines
int Appears; // Number of line where appears title
//
HTNode *NextTopic; // Next topic in the list
HTNode *PrevTopic; // Previous topic in the list
HTNode *Reference; // Next link in the list
int X,Y; // Position in the text
// (used only by interpreter)
// Constructor
HTNode(char *keyword, long seek, int size, int appears, int=0, int=0);
~HTNode(); // Destructor
// Redefine operators
friend int operator > (HTNode &a, HTNode &b); // Compare by
friend int operator < (HTNode &a, HTNode &b); // KeyWord
friend int operator > (char *a, HTNode &b); // Compare KeyWord with
friend int operator < (char *a, HTNode &b); // string
};
------------------------------------------------------------------
// HTNode constructor
HTNode::HTNode(char *keyword, long seek, int size, int appears, int x, int y)
{
NextTopic=PrevTopic=NULL; // Upper level objects set this pointers
Reference=NULL; //
KeyWord=NULL;
if(keyword)
{
// The next line caused SIGABRT when create second node
// (with first - all is OK) from RHIDE and
// caused SIGSEGV from DOS in similar situation
//
KeyWord=new char[strlen(keyword)]; // Create and fill key field
strcpy(KeyWord,strupr(keyword));
}
Seek=seek; Size=size; // Filling other
Appears=appears; X=x; Y=y; // fields
}
//...
-----------------------------------------------------------------
Exiting due to signal SIGSEGV
General Protection Fault at eip=00005310
eax=0000000c ebx=00000001 ecx=fffffffc edx=742f7070 esi=00000006 edi=00053d63
ebp=00053cb8 esp=00053cb0 program=C:\LANGS\HYPERT~1\HTMAKE.EXE
cs: sel=00f7 base=82b4d000 limit=0006ffff
ds: sel=00ff base=82b4d000 limit=0006ffff
es: sel=00ff base=82b4d000 limit=0006ffff
fs: sel=00d7 base=0001c350 limit=0000ffff
gs: sel=010f base=00000000 limit=ffffffff
ss: sel=00ff base=82b4d000 limit=0006ffff
Call frame traceback EIPs:
0x00005310
0x000039c4
0x0000397f
0x00002a36
0x000027ff
0x00002442
0x00002693
0x00003f7e
----------------------------------------------------------------
Alexander Bokovoy, <bokovoy AT bspu DOT ac DOT by>
---== The Soft Age coming soon ==---
- Raw text -