mpictor/StepClassLibrary — Issue #98: OSX p21read segfault
Author: mpictor
Created: 2011-11-12 19:48:48+00:00
State: open

p21read has a segfault on OSX:

$ gdb --args ./p21read_sdai_AP214E3_2010 ../../data/ap214e3/dm1-id-214.stp
GNU gdb 6.3.50-20050815 (Apple version gdb-1515) (Sat Jan 15 08:33:48 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin"...Reading symbols for shared libraries ......... done

(gdb) r
Starting program: /Users/thomas/Devel/StepClassLibrary/cmake-build/bin/p21read_sdai_AP214E3_2010 ../../data/ap214e3/dm1-id-214.stp
Reading symbols for shared libraries .++++++++ done

EXAMPLE : load file ...
Reading Data from /Users/thomas/Devel/StepClassLibrary/data/ap214e3/dm1-id-214.stp...

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000010
0x0000000100e6e790 in AttrDescriptor::NonRefType (this=0x0) at /Users/thomas/Devel/StepClassLibrary/src/clstepcore/ExpDict.cc:625
625 if( _domainType ) {
(gdb) bt
#0 0x0000000100e6e790 in AttrDescriptor::NonRefType (this=0x0) at /Users/thomas/Devel/StepClassLibrary/src/clstepcore/ExpDict.cc:625
#1 0x0000000100e5ed06 in STEPattribute::NonRefType (this=0x1010ec600) at /Users/thomas/Devel/StepClassLibrary/src/clstepcore/STEPattribute.inline.cc:101
#2 0x0000000100e5c4b0 in STEPattribute::set_null (this=0x1010ec600) at /Users/thomas/Devel/StepClassLibrary/src/clstepcore/STEPattribute.cc:653
#3 0x0000000100e1b06a in SdaiFile_name::SdaiFile_name (this=0x1010ec520) at /Users/thomas/Devel/StepClassLibrary/src/cleditor/SdaiHeaderSchema.cc:228
#4 0x0000000100e1da56 in create_SdaiFile_name () at SdaiHeaderSchema.h:132
#5 0x0000000100e6d6f5 in Registry::ObjCreate (this=0x1010ea850, nm=0x7fff5fbfde10 "FILE_NAME", schnm=0x0, check_case=0) at /Users/thomas/Devel/StepClassLibrary/src/clstepcore/Registry.inline.cc:280
#6 0x0000000100e0f4fe in STEPfile::ReadHeader (this=0x7fff5fbfe900, in=@0x1010ebc40) at /Users/thomas/Devel/StepClassLibrary/src/cleditor/STEPfile.cc:154
#7 0x0000000100e0fd78 in STEPfile::AppendFile (this=0x7fff5fbfe900, in=0x1010ebc40, useTechCor=1) at /Users/thomas/Devel/StepClassLibrary/src/cleditor/STEPfile.cc:2265
#8 0x0000000100e120ec in STEPfile::ReadExchangeFile (this=0x7fff5fbfe900, filename=@0x7fff5fbfe9d0, useTechCor=1) at /Users/thomas/Devel/StepClassLibrary/src/cleditor/STEPfile.inline.cc:119
#9 0x0000000100003e9b in main (argc=2, argv=0x7fff5fbfea28) at /Users/thomas/Devel/StepClassLibrary/src/test/p21read/p21read.cc:131
(gdb)

------

I think that the segfault is because aDesc is 0 at [STEPattribute.inline.cc:101](https://github.com/mpictor/StepClassLibrary/blob/master/src/clstepcore/STEPattribute.inline.cc#L101)

At [SdaiHeaderSchema.cc:227](https://github.com/mpictor/StepClassLibrary/blob/master/src/cleditor/SdaiHeaderSchema.cc#L227), `a_5name` is zero. It becomes param `d` at [STEPattribute.inline.cc:34](https://github.com/mpictor/StepClassLibrary/blob/master/src/clstepcore/STEPattribute.inline.cc#L34).

`a_5name` is initialized in `SdaiHEADER_SECTION_SCHEMAInit()` at [SdaiHeaderSchemaInit.cc:71](https://github.com/mpictor/StepClassLibrary/blob/master/src/cleditor/SdaiHeaderSchemaInit.cc#L71), which is called from [HeaderSchemaInit()](https://github.com/mpictor/StepClassLibrary/blob/master/src/cleditor/SdaiSchemaInit.cc#L10). A function pointer to `HeaderSchemaInit()` is passed to the `Registry` ctor in the [STEPfile ctor](https://github.com/mpictor/StepClassLibrary/blob/master/src/cleditor/STEPfile.inline.cc#L36).

There is an `extern` declaration in that file on line 21, as well:

```C
extern void HeaderSchemaInit( Registry & reg );
```

I am not very familiar with `extern`, but I wonder if it is causing the unexpected behavior.

---
See also https://github.com/mpictor/StepClassLibrary/pull/85#issuecomment-2633438