Good morning, Is it possible to fix Sun Solaris OS 5.8 segmention fault related to int * cast with gcc version 3.3? The gdb variable values are shown below. The cOrderedList class member variables are shown below. The uname -a and gcc -v outputa are shown below.
This code works fine on Windows Visual Studio C++ 9.0 .Thank you.
[New LWP 1] Program received signal SIGSEGV, Segmentation fault. 0xff064b04 in cOrderedList::LoadDatabaseRecords(cSQLite*, char const*) ( this=0x68f10, Database_=0xa4ba8, Command_=0xffbed468 "SELECT * FROM LeftPattern") at ../Source/cOrderedList.cpp:272 272 *((int*) (Records+RecordCount*RecordSize+FieldOffsets[i]))=Database_->ColumnInt(i); (gdb) print i $3 = 3 (gdb) print Records $4 = 0xa0800 "" (gdb) print RecordCount $5 = 0 (gdb) print RecordSize $6 = 50 (gdb) print FieldOffsets[i] $7 = 46
class cOrderedList {
private:
enum eFieldTypes {
Character,
Integer
};
bool CopyConstructed;
int RecordCount;
int FieldCount;
int RecordSize;
char *Records;
int *FieldSizes,*FieldOffsets;
eFieldTypes *FieldTypes;
char *CurrentPos;
$ uname -a SunOS 5.8 Generic_108528-22 sun4u sparc SUNW,Sun-Fire-V210 $ gcc -v Reading specs from /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.3/specs Configured with: ../configure --disable-nls --with-as=/usr/ccs/bin/as --with-ld= /usr/ccs/bin/ld Thread model: posix
bool cOrderedList::LoadDatabaseRecords(cSQLite *Database_,const char *Command_) {
int retVal;
char str[4096];
RetrySQL:
RecordCount=0;
Database_->Prepare(Command_);
while ((retVal=Database_->Step())!=SQLITE_DONE) {
switch (retVal) {
case SQLITE_ROW:
for (int i=0;i<FieldCount;i++) {
if (FieldTypes[i]==Integer) {
*((int*) (Records+RecordCount*RecordSize+FieldOffsets[i]))=Database_->ColumnInt(i);
} else {
Database_->ColumnText(i,str);
LTrim(str);
RTrim(str);
#if defined(_DEBUG)
if ((int) strlen(str)>=FieldSizes[i])
printf("Field not large enough: %s\n",Command_);
#endif
strncpy(Records+RecordCount*RecordSize+FieldOffsets[i],str,FieldSizes[i]);
Records[RecordCount*RecordSize+FieldOffsets[i]+FieldSizes[i]-1]='\x0';
}
}
RecordCount++;
break;
case SQLITE_BUSY:
continue;
case SQLITE_MISUSE:
goto RetrySQL;
default:
break;
}
}
return true;
}