Open tomkoen opened 6 years ago
I've just tried and it doesn't crash.
Without the check m_descriptorData[0] is trying to access the first element of the vector while the vector is empty.
Yes, I wrote earlier too quick. Seems that vector index out of bounds is undefined. Clang seems to return NULL, which, by coincidence, works well here.
Must be corrected, yes.
Maybe
HFSBTreeNode& operator=(const HFSBTreeNode& that)
{
if (!that.isInvalid()) {
m_descriptorData = that.m_descriptorData;
m_nodeSize = that.m_nodeSize;
initFromBuffer();
}else{
m_descriptor = 0;
m_nodeSize = 0;
m_firstRecordOffset = 0;
}
return *this;
}
Thanks for confirming. Quick code to reproduce:
HFSBTreeNode retEmptyNode() { return HFSBTreeNode(); }
HFSBTreeNode crashNode;
crashNode = retEmptyNode(); // oops
Which platform/compiler do you use ?
Windows, Visual Studio 2013
I prefer things not to silently fail. Allowing an index out of bounds, at least in debug mode, is annoying. At least VC crash !
HI @LubosD and @bugaevc.
Should we do a pull request for this, so it's quicker for you ? I'm trained with pull requests, so I can do that :-)
Yes please :)
Which fix do you prefer ? In void initFromBuffer()
like tomkoen proposed, or in HFSBTreeNode& operator=(const HFSBTreeNode& that)
The one in initBuffer()
is better, don't you think ?
Done : #70
if findLeafNode returns empty HFSBTreeNode then operator= will crash in initFromBuffer. I'd change the method code to