Unsafe functions philosophy
Posted: Fri Mar 09, 2012 5:16 am
I noticed that there are functions such as and the entire n-family from C99, where there's a size_t limit.
My question is: isn't this the wrong approach, in the wrong programming language? I'll elaborate...
I perceive a difference between writing user-proof code, and programmer-proof code.
In C, you can do the latter by adding extra validation of input (i.e. pass the size of the array).
But if C itself doesn't provide automatic bounds checking, isn't it against the language's nature to try to emulate it?
Shouldn't the focus shift to making the code user-proof, that is to say sanitize all input at one bottleneck, and keep the functions fast and dumb?
(Of course, we're talking about kernel development, and not of libraries where programmer-proofing could be beneficial.)
Edit: some stupid things.
Code: Select all
char * strnlen(const char *, size_t);
My question is: isn't this the wrong approach, in the wrong programming language? I'll elaborate...
I perceive a difference between writing user-proof code, and programmer-proof code.
In C, you can do the latter by adding extra validation of input (i.e. pass the size of the array).
But if C itself doesn't provide automatic bounds checking, isn't it against the language's nature to try to emulate it?
Shouldn't the focus shift to making the code user-proof, that is to say sanitize all input at one bottleneck, and keep the functions fast and dumb?
(Of course, we're talking about kernel development, and not of libraries where programmer-proofing could be beneficial.)
Edit: some stupid things.