TooTallNate / ref-struct

Create ABI-compliant "struct" instances on top of Buffers
118 stars 78 forks source link

Null/Zero Pointers cause seg faults... #5

Closed dijs closed 10 years ago

dijs commented 10 years ago
CNode = Struct()
CNodePtr = ref.refType CNode

CNode.defineProperty "label", ref.types.CString
CNode.defineProperty "child", CNodePtr
CNode.defineProperty "next",  "pointer"
CNode.defineProperty "start", ref.types.int
CNode.defineProperty "end",   ref.types.int

In my app a get a reference to a CNode, if the child or next property is a "<SlowBuffer@0x0 >". Then a seg fault happens, but when that buffer is not empty, the struct is filled and works!

I am sooo confused!

TooTallNate commented 10 years ago

I think you're going to have to use the ref.isNull(buffer) function to check if the value points to a null pointer before trying to dereference the value. If it's null, don't deref otherwise you'll get the segfault.