5 ms·
Zig has raw pointers with pointer arithmetic/indexing [1], so as far as I can tell it doesn't enforce spatial memory safety. I don't think spatial memory safet
by pcwalton 4y ago
Zig has raw pointers with pointer arithmetic/indexing [1], so as far as I can tell it doesn't enforce spatial memory safety.
I don't think spatial memory safety alone is a large improvement over C++ in particular, since most memory safety vulnerabilities nowadays are UAF. For C, maybe; I'd have to look at LazyFishBarrel to see how many bugs nowadays are spatial as opposed to temporal (I'd guess that temporal vulnerabilities are more common nowadays in C too).
[1]: https://ziglang.org/documentation/master/#Pointers https://ziglang.org/documentation/master/#Pointers
- azakai 4y agoI'm not an expert on Zig, but my understanding is that it also has safe slices, and pointers which disallow arithmetic, and encourages their usage in idiomatic Zig. I assume that's why this nice post describes Zig as having spatial memory safety: https://www.scattered-thoughts.net/writing/how-safe-is-zig/ https://www.scattered-thoughts.net/writing/how-safe-is-zig/ Agreed that UAF is the larger factor these days for C++. Those are just impossible to really get rid of in such a language, without the overhead of something like Type-After-Type (which in some cases is just too much).
- pjmlp 4y agoWhich Modula-2 and Mesa were already doing in the 70's, or NEWP/ESPOL in the 60's, or JOVIAL in the late 50's. Hence why it would be nice if Zig would be a bit better in that regard.