3 ms·
As I wrote some time ago, http://www.drdobbs.com/architecture-and-design/cs-biggest-mistake/228701625 http://www.drdobbs.com/architecture-and-design/cs-biggest
by WalterBright 12y ago
As I wrote some time ago,
http://www.drdobbs.com/architecture-and-design/cs-biggest-mistake/228701625 http://www.drdobbs.com/architecture-and-design/cs-biggest-mi...
it is easy to add bounds checking arrays to the C language. The trouble is, nobody is interested in doing it.
It'd be a heckuva lot easier than changing languages.
- CamperBob2 12y agoHow would that fix the problem at hand? The code in question isn't using array notation. At the end of the day, it's not a case of using C when another language would be better, it's a case of crappy coding.
- WalterBright 12y agoIt helps because instead of rewriting the whole app, just the function parameter types are redone where pointers to data are changed to bounds checked arrays, on a case by case basis. It isn't a magic bullet, but as buffer overflows are (I presume) the most common cause of C security exploits, this would help a lot.
- CamperBob2 12y agoMaybe, but my fear would be that the act of rewriting it to use array notation will introduce yet more bugs. Some of the comments point out that the problem exists because nobody cared enough to fix it for several years. Having seen that nobody cared enough to fix it, it's not clear that anyone will care enough to fix it properly.
- Animats 12y ago(Bright, of course, is the creator of D.) I agree completely about C. I've been saying this for years. There are three big problems that cause crashes in C programs: "How big is it?", "Who owns it?", and "Who locks it?". The result is over three decades of segfaults and buffer overflows. There have been three or four variants on C which address some of those issues. I've proposed one myself. None got any traction. The only thing that might work is if someone developed a safe variant of C which could be machine-generated from existing C code, and didn't add significant overhead. GCC already has a fat-pointer subscript checking option, but nobody uses it. That approach is usually slow, with a subscript check on every reference. If you do it right, most subscript checks get hoisted out of loops. Go does that for many FOR statements. Rust is one of the very few languages which addresses all three of those issues without resorting to garbage collection. I really hope the Rust crowd doesn't screw it up.
- WalterBright 12y ago> GCC already has a fat-pointer subscript checking option, but nobody uses it My experience with adding extensions to C++ is that nobody will use them, not even the people who proposed the extension, unless it is adopted by the Standard. The same goes for C. The feature I proposed for C has been in D since the beginning, and has a very strong track record of success - both in user acceptance and in eliminating bugs. Whether the runtime bounds checking is actually done or not is controlled by a compiler switch - but most users choose to leave it on.
- dbaupp 12y agoThere are a lot of GCC extensions that are not in the standard. https://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html https://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html Things that are definitely used are __attribute__'s and labels-as-values.