4 ms·
I tend to agree. Fixing C++ memory safety without turning it into a different language is hopeless. It's been tried many times. I took a crack at it once. So
by Animats 10y ago
I tend to agree. Fixing C++ memory safety without turning it into a different language is hopeless. It's been tried many times. I took a crack at it once. So did the Rust designers. There's a whole literature on this. You have to forbid too much.
Previous attempts include Microsoft source code annotation language (SAL), Cyclone (AT&T research language), SCC, the Safe C compiler, Ccured, and MemSafe. None really went anywhere.
What this probably means is another sort-of-safe dialect of C++, accompanied by hand-waving and PR.
C++ is trying to do single owner semantics, but without something like Rust's borrow checker, the best you can do is crash at runtime on violations of move semantics. You have to design the language around borrow checking to get ownership right.
Still, it's good that the C++ crowd is trying. A decade ago, I was trying to get the standards committee interested in memory safety issues, but they were into exciting new template features used by few.
- lloeki 10y agoYou can add to this list strictly-restricted subsets of C++ used for kernel development because it just has to be sane. A notable example is Darwin and kexts. I don't know what the NT folks are using.
- catnaroek 10y agoThe idea that you can find a sane subset of C++ is itself insane.
- nickpsecurity 10y agoReally? https://news.ycombinator.com/item?id=11895686 https://news.ycombinator.com/item?id=11895686
- catnaroek 10y agoFrom your linked post: > https://www.cis.upenn.edu/~eir/papers/2013/ironclad/paper.pdf https://www.cis.upenn.edu/~eir/papers/2013/ironclad/paper.pd... It still relies on dynamic checks. So you still have the same problem as in Java: just because you have a reference, it doesn't mean you actually have a valid object. You can make any language trivially safe by checking absolutely everything at runtime, but the whole point to using a language like C++ is to not incur in unnecessary performance overheads. > http://research.microsoft.com/en-us/um/people/marron/selectpubs/Undangle.pdf http://research.microsoft.com/en-us/um/people/marron/selectp... Have you actually read the paper? This isn't a static analysis at all. It just makes a dynamic analysis more eager and precise.
- nickpsecurity 10y agoAppreciate insight on first link. Far as other, that's my mistake given I only read parts on anslysis, diagnostic, and performance. It was in a list of static anslysis stuff I found. So, I wrongly assumed it was static analysis instead of verifying it myself as I did first one on that page [that worked but had limitations].
- pjmlp 10y agoThe SAL annotations and the Z3 theorem prover developed at MSR are part of the DDK. Additionally, since Windows 8 C++ is allowed on the kernel space and they have re-written the C library in C++, exposing the API via extern "C".
- cwzwarich 10y ago> Previous attempts include Microsoft source code annotation language (SAL), Cyclone (AT&T research language), SCC, the Safe C compiler, Ccured, and MemSafe. None really went anywhere. None of these projects were trying to define safe C subsets. SAL is a system of annotations for static analysis tools. SCC, CCured, and MemSafe were all attempts to add dynamic checks for memory safety to C; they are the ancestors of things like the Address Sanitizer. Cyclone was a new programming language, and it innovated the system of ownership and borrowing that is used in Rust.
- Animats 10y agoThey were all attempts to fix memory safety without straying too far from C/C++. But that's really tough to retrofit.
- catnaroek 10y agoCyclone is pretty different from C. It has parametric polymorphism, type inference, built-in support for region allocation, sum types (both open and closed) and pattern matching... and sadly also an unsightly surface syntax.
- blub 10y agoHow does providing N examples of failed attempts at improving C safety have any relevance to C++ safety? Have you seen Sutter's video where he presented the static analysis that the Visual C++ team was working on? The whole point is that with some additional code changes (especially around pointer usage) one WOULD detect errors at compile-time. When and if this static analysis will be released remains to be seen, but this blog post sounds petty.
- catnaroek 10y ago> The whole point is that with some additional code changes (especially around pointer usage) one WOULD detect errors at compile-time. The point isn't just detecting errors, but rather completely disallowing code that does unsafe things, by turning every undefined behavior into a compilation error. Unfortunately, determining whether a C++ program has undefined behavior is equivalent to solving the Halting problem.
- comex 10y ago> Unfortunately, determining whether a C++ program has undefined behavior is equivalent to solving the Halting problem. The Core Guidelines analyzers do not try to accept all valid C++ programs, or even a large percentage of real-world C++ programs. In principle they will accept a subset (+ annotations), a language within a language, designed to make it possible to statically verify memory safety, similar to Rust.
- catnaroek 10y ago> The Core Guidelines analyzers do not try to accept all valid C++ programs I'm aware. My point is: Are the Core Guidelines enough to completely rule out memory errors? This is essentially a type safety claim, and thus requires (possibly informal) proof.
- coldtea 10y ago>Are the Core Guidelines enough to completely rule out memory errors? Does it matter? As long as they rule out the vast majority of memory errors, e.g. many times more than static analysis tools find today.