NanoMichael / MicroTeX

A dynamic, cross-platform, and embeddable LaTeX rendering library
MIT License
418 stars 69 forks source link

Get underlying ptr of shared_ptr without dereferencing. #37

Closed blackhole89 closed 3 years ago

blackhole89 commented 3 years ago

Over at blackhole89/notekit#60, we were struggling with a crash due to a failed assertion under atom_basic.cpp:483. It turns out that trick used there to get the address from a shared_ptr does not work when _GLIBCXX_ASSERTIONS is defined and the pointer is NULL (as is the case with _previousAtom in that line at first). Indeed, if you check bits/shared_ptr_base.h, there's an assertion in the relevant operator* that the dereferenced pointer should not be NULL, regardless of the valid-ish use case of immediately taking its address again. I think the intended way of getting the underlying ptr is to use .get() instead.

I've only fixed the instance we bumped up against; if there are other places in the code with the &(*smartptr) pattern, they probably should changed in the same way too.

NanoMichael commented 3 years ago

I get it. I'll check it for this misuse.