Hasty Briefsbeta

The case of the crash on a null pointer even though we checked it for null

2 days ago
  • #Debugging
  • #Crash Analysis
  • #C++/WinRT
  • A crash investigation revealed a null pointer dereference in a C++/WinRT projection of a COM call.
  • The crash occurred when calling `IVectorView<T>::Size` on a null pointer, indicating the `std::optional` containing the vector was empty.
  • The code incorrectly checked for `nullptr` against an `std::optional`, which does not behave as intended for empty optionals.
  • The fix involved removing `std::optional` and directly using `IVectorView`, which naturally handles null checks.
  • The investigation highlighted the importance of understanding type behaviors, especially with `std::optional` and nullable types.