| Wabewalker ( @ 2007-11-20 13:08:00 |
| Current location: | 2821 Mission College Blvd, Santa Clara, CA |
| Current mood: | |
| Entry tags: | technology, work |
This is why you’re not allowed to have nice things
While doing maintenance, I found the following atrocity:
inline void fast_strncpy(char *dest, const char *src, int nbytes) {
if (nbytes <= 10) {
switch (nbytes) {
case 1:
dest[0] = '\0';
break;
case 2:
dest[0] = src[0];
dest[1] = '\0';
break;
case 3:
dest[0] = src[0];
dest[1] = src[1];
dest[2] = '\0';
break;
case 4:
dest[0] = src[0];
dest[1] = src[1];
dest[2] = src[2];
dest[3] = '\0';
break;
// AND SO ON FOR AN OBSCENE NUMBER OF CASES...
}
else {
memcpy(dest, src, nbytes - 1);
dest[nbytes] = '\0'; // WHAT’S WRONG HERE, KIDS?
}
}
“Why does our performance suck compared to the competitors?”
Because maybe, just maybe, your engineers can’t program worth crap?