r/ProgrammingLanguages • u/ThomasMertes • Oct 05 '26
Achieving memory safety
https://seed7.net/papers/memory_safety.htm
14
Upvotes
r/ProgrammingLanguages • u/ThomasMertes • Oct 05 '26
View all comments
Show parent comment
1
u/flatfinger Oct 07 '26
On most platforms, if a function like:
is processed in a manner which is agnostic with regard to how it might be called, correct machine code would be incapable of performing an out-of-bounds store unless memory safety had already been violated. Even if the ability of the function to do anything useful relied upon the caller passing a number less than 32770, memory safety would not. Of all the possible circumstances in which the function could be called, all of them would either result in the function either performing an in-bounds store or not bothering to perform a store at all.
What causes problems are situations where a compiler would generate code that would assume that it would be impossible for a caller to pass a value greater than 32769, but then generate code for the caller which does in fact pass a larger value.
Being able to have a system automatically limit the ranges of a program that would be capable of violating memory safety is useful, but some programs need to do things whose safety cannot be statically validated under language rules. Being able to validate programs that perform such tasks by validating each individual component thereof is more useful than allowing programs to violate memory safety even when none of their individual pieces should be capable of doing so.