I have some old code that has out grown 32-bit address space so I'm converting it to run as a 64-bit binary instead. It compiles fine, but when I run it I get a core dump. I've traced it down to the following piece of code, but I can't figure out why it's broken, or how to fix it. The code is run on sol2.8 machines and I appear to get the same result with either SUNspro/cc or gcc.
I'm not much of a programmer, so I debugged it down to the malloc line below with printf statements:
CellData is defined in a header file:Code:TestCellData *testCellData; CellData *cellData; int c; long *cellWord; if ((cellData = malloc(sizeof(CellData))) == NULL) { Fatal("out of memory (line %s:%d)\n", __FILE__, __LINE__); }
Then in a final gasp I tried my hand at dbx and it seems to yield a bit more information:Code:#define CELL_DATA_BYTES 64 typedef unsigned char CellData[CELL_DATA_BYTES];
So, can someone explain to me why aren't the new 64-bit addresses aligned? I tried casting malloc a few ways, but nothing seemed to help. Note that this same line works fine several times before the core dump. Perhaps the code is fine and I have an environment issue (I assume _smalloc is in some lib*.so file somewhere)?Code:Current function is CreateCellData 40 if ((cellData = malloc(sizeof(CellData))) == NULL) { signal BUS (invalid address alignment) in _smalloc at 0xffffffff7ea4928c 0xffffffff7ea4928c: _smalloc+0x0094: ldx [%o0 + 0x10], %g4
Any suggestions would be greatly appreciated.



LinkBack URL
About LinkBacks


