News for hackers. Stuff that matters.
Re:Getting Past C by JKCalhoun on Tuesday January 03, 2017 @04:47PM (#13313430)
Or perhaps just some helper functions in C that wrap array and pointer allocation/access to provide sanity checks. Seems like moving to a new language is rather extreme....
Re:Getting Past C by geofft on Tuesday January 03, 2017 @05:04PM (#13313570)
If you want to do this well, as other commenters pointed out, your entire C library interface is going to have to change to accept bounded arrays instead of pointers and lengths as separate arguments, or worse, just pointers and implicit lengths by looking for the NUL character. But then you've given up the ability to directly call into existing code; everything is at best using a little translation layer to check bounds before/after passing buffers to outside functions. So the advantage of staying in the language is minimal (note that you've given up on "C strings" entirely), and if you're going to have all of this, you might as well use a language with compile-time checks (types, etc.) that you're doing all of this right.

Rust and Go are not your only choices here. C++ with aggressive use of modern features and aggressive non-use of everything inherited from C is also a fine choice, but enforcing that discipline is hard, and the compiler won't help you a lot. Honestly, a dynamic language like Python or Ruby is also a fine choice in many cases, although NTP might be too latency-sensitive for that to work. (But it might not be! Premature optimization and all that.)

Re:Getting Past C by viraptor on Tuesday January 03, 2017 @05:03PM (#13313561)
Sure, glib for example contains all the wrapped network / file / string handling you need. But then you need to make sure you use it correctly. And that no code goes around that API. And that you didn't make mistakes that invalidate the safety of your abstraction.

Moving to an abstraction would potentially solve some overflow issues and requires constant attention. Moving to a safe language likely solves all of them and you get checked by the compiler instead.

Re:Getting Past C by jdmichal on Tuesday January 03, 2017 @05:01PM (#13313540)
Why? Rust includes index checks by default, so you have zero chance of programmer error. And, to boot, it removes the checks when the compiler decides that the code is provably safe.
Re:Getting Past C by ue_ on Wednesday January 04, 2017 @07:19AM (#13317633)
Why does Rust still not warn at compile time and furthermore actually crash (panic) on OOB access if it has the checks you describe?
Re:Getting Past C by jdmichal on Wednesday January 04, 2017 @09:56AM (#13318710)
I never stated whether the checks were static or runtime. In this case, they are runtime checks.

What you are talking about is value range analysis. Rust does a limited amount of it, and if it can prove safe indexing it will remove the runtime checks.