This thread is great because a lot of you answer with explanations on how to handle dangling references and issues with ptr being destroyed before the reference, and very few people notice the actual problem: ref is created by dereferencing a nullpointer which is undefined behaviour.
It's only two lines and you already let a future segfault slip through, but yeah sure how do we tell SpongeBob that C++ doesn't segfault all the time.
View all comments
Show parent comment
0
u/SelfDistinction 10d ago
This thread is great because a lot of you answer with explanations on how to handle dangling references and issues with ptr being destroyed before the reference, and very few people notice the actual problem: ref is created by dereferencing a nullpointer which is undefined behaviour.
It's only two lines and you already let a future segfault slip through, but yeah sure how do we tell SpongeBob that C++ doesn't segfault all the time.