Is there a formal definition for what it means for a language to be spatially memory-safe but not temporally memory-safe? Is it something like "memory-safe under the assumption that, once freed, that memory block (whether heap or stack) will never be reused"?
Conversation
Replying to
I don't really see how you can have one without the other. If you reduce the size of a dynamic array from 2M to 1M in-place and then access beyond 1M due to lack of temporal safety that looks a lot like an out-of-bounds access to me. They're not really cleanly separated things.
Hmm. spatial safety: all accesses are to memory that has been allocated?
temporal safety: no accesses to memory that has been deallocated?
C - neither
Java - both (excluding the evil low-level API)
2
Pascal without variant records or free - both;
Pascal with variants & free - neither;
Pascal with variant records but not free - temporal only;
Pascal with free but not variant records - spatial;
I fear I'm eliding (or assuming) issues with type-safety
1
A closely related well known example would be golang slices which are spatially safe, but only in absence of race conditions.
You can have spatial without temporal memory safety: spatial memory safety is "if the current size of the object is known when it is accessed, then the access will not be out of bound". It is weaker than temporal memory safety, as it doesn't support any change.
1
If there's a change involved, then temporal memory safety is needed. Your example is temporal. Allegedly, spatial memory safety is not memory safety. Since some languages have it and tend to indicate it is sufficient (IMO it's not) it is important we have this conversation.



