71 points · by d0ne · 12y ago · 13 comments
[1] https://www.gitorious.org/gnutls/gnutls/commit/6aa26f78150cc...
Unfortunately, the type system can't save you, so it's up to you to keep your promise to return the correct thing. Not even C99 can save you:
$ cat booltest.c
#include <stdio.h>
#include <stdbool.h>
bool moo() {
int rv = -1;
return rv;
}
int main(int argc, char *argv[]) {
printf("moo() returned %s\n", moo() ? "TRUE" : "FALSE");
}
$ clang -std=c99 -o booltest booltest.c -Wall
$First, I absolutely LOVE it when people assume I'm a dude. Plot twist: no I don't. If you don't know someone's gender, getting it wrong with an assumption is a good way to hack them off.
Second: the function is explicitly prototyped as returning bool (I highlighted this in neon green) which means caller expects true or false. It returns a negative value that is not intended to represent either true or false but a detailed error code. THAT IS THE BUG.
If bools don't exist in C then neither does strlen, gahh.
How about "how to verify a certificate?" Or better "how to write C code"
This is a scandal. Stop.