Horror Code - Who Needs Enumerators?

When I stumbled into this piece of C code, at first, it looked not so bad to me. void foobar(const char *par) { if (!strcmp(par, "FirstString")) { // do something } else if (!strcmp(par, "SecondString")) {… (read more)

Horror Code - Copying & Pasting Errors

The following piece of code contains a trivial error. int v; char buf[11], *p; memset(buf, 0, sizeof(buf)); /* Fill buf with a string */ v = strtoul(buf, &p, 16); p = NULL; // <--- This is w… (read more)

Horror Code - Loop And Re-loop

Some time ago, a colleague of mine told me to look at a function. It was something similar to this: void foo(struct bar array[], unsigned int count) { /* some initialization code */ for (int i = 0; i < count; i++) {… (read more)

Horror Code: Paid By The Number Of Rows

The first thing I've thought is: "I'm missing something". But after few seconds the doubt that the author of the following code is paid for the number of lines of code come to my mind. Judge yourself: struct data_node *node = calloc(1, sizeof(*node))… (read more)

Horror Code - Why?

while (x &gt;= 0) { x--; y--; } I've only a question: why? Image taken from Pixabay licensed under the Creative Commons Public Domain Dedication license.… (read more)

Horror Code: The Matryoshka Functions

Some years ago, when I was a Windows developer, the maintenance of a big project has been assigned to me. My job was to fix a couple of minor bugs and add some new functions. The problem was that the creator (and previous maintainer) have resigned ye… (read more)

Horror Code: the Impossible Function

This is one of the less readable functions that I've found in my life. I've removed any reference to structures and variable names, according to the Italian law about privacy ;-) I don't want to add any other comment. Enjoy! static int my_function( /… (read more)