2 ms·
What you mean by smart ptrs not being memory safe? Vector access can be done with at method
by Moldoteck 8mo ago
What you mean by smart ptrs not being memory safe?
Vector access can be done with at method
- pjmlp 8mo agoWhich unfortunately most people avoid using, and until C++26 there is no at() for span. The best is really to enable compiler specific hardening.
- ben-schaaf 8mo agoAs I said, unique_ptr (or any of the others), do not check for null. So you can do this, and it will cause a segfault: std::unique_ptr<int> a; printf("%d\n", *a); Similarly unique_ptr::operator[] doesn't (and can't) do bounds checking, for example: std::unique_ptr<int[]> a = std::make_unique<int[]>(2); printf("%d\n", a[2]); There's also no attempt to limit the construction of invalid smart pointers, for example: int num; std::unique_ptr<int> a(&num); Smart pointers simplify memory management, and they're slightly harder to misuse than regular pointers, but they simply make no attempt at providing memory safety.