The C code that follows was written by a student engineer that spent a traineeship in our lab. His program was very poorly documented, and in a futile effort to find more information I even read the traineeship report he wrote for his school, which contained about fifteen grammar and spelling errors per page (despite being written in the student's mother tongue).
We eventually found that his program was bugged so the results we computed with it were unusable.
The program started with this nice wtf:
sscanf(line_cour_route,
"%s %i %i %i
%i %i %i %i %i %i %i %i %i %i
%i %i %i %i %i %i %i %i %i %i
%i %i %i %i %i %i %i %i %i %i
%i %i %i %i %i %i %i %i %i %i
%i %i %i %i %i %i %i %i %i %i
%i %i %i %i %i %i %i %i %i %i
%i %i %i %i %i %i %i %i %i %i
%i %i %i %i %i %i %i %i %i %i
%i %i %i %i %i %i %i %i %i %i
%i %i %i %i %i %i %i %i %i %i",
instr,&id_route, &Bp, &nb_sauts,
&n_r[0],&n_r[1],&n_r[2],&n_r[3],&n_r[4],&n_r[5],&n_r[6],&n_r[7],&n_r[8],&n_r[9],
&n_r[10],&n_r[11],&n_r[12],&n_r[13],&n_r[14],&n_r[15],&n_r[16],&n_r[17],&n_r[18],&n_r[19],
&n_r[20],&n_r[21],&n_r[22],&n_r[23],&n_r[24],&n_r[25],&n_r[26],&n_r[27],&n_r[28],&n_r[29],
&n_r[30],&n_r[31],&n_r[32],&n_r[33],&n_r[34],&n_r[35],&n_r[36],&n_r[37],&n_r[38],&n_r[39],
&n_r[40],&n_r[41],&n_r[42],&n_r[43],&n_r[44],&n_r[45],&n_r[46],&n_r[47],&n_r[48],&n_r[49],
&n_r[50],&n_r[51],&n_r[52],&n_r[53],&n_r[54],&n_r[55],&n_r[56],&n_r[57],&n_r[58],&n_r[59],
&n_r[60],&n_r[61],&n_r[62],&n_r[63],&n_r[64],&n_r[65],&n_r[66],&n_r[67],&n_r[68],&n_r[69],
&n_r[70],&n_r[71],&n_r[72],&n_r[73],&n_r[74],&n_r[75],&n_r[76],&n_r[77],&n_r[78],&n_r[79],
&n_r[80],&n_r[81],&n_r[82],&n_r[83],&n_r[84],&n_r[85],&n_r[86],&n_r[87],&n_r[88],&n_r[89],
&n_r[90],&n_r[91],&n_r[92],&n_r[93],&n_r[94],&n_r[95],&n_r[96],&n_r[97],&n_r[98],&n_r[99]);
A few pages below there was this horror:
j = 0;
while (fichier_noeud[j] != (char )NULL) {
j++;
}
fichier_noeud[j] = 0x5f;
fichier_noeud[j+1] = 0x30 + i /1000;
fichier_noeud[j+2] = 0x30 + ( i/100 - ( (i/1000)%10 ) *10 );
fichier_noeud[j+3] = 0x30 + ( i/10 - ( (i/100)%10 ) *10 - (
(i/1000)%10) * 100);
fichier_noeud[j+4] = 0x30 + ( i
- ( (i/10)%10 ) *10 - ( (i/100)%10 )*100 - ( (i/1000)%10)*1000 );
fichier_noeud[j+5] = (char) NULL;
affiche_noeud_fichier(fichier_noeud);
fichier_noeud[j] = (char) NULL;
i++;
This code simply concatenates the four-digit number i to the string fichier_noeud. Now I'd like to point out three things:
1) this whole blob could easily be replaced by sprintf(str, "%s", i); strcat(fichier_noeud, str);
2) even if one were ignorant about C sytem functions and too lazy to look it up on Google, it would make sense to compute the four digits only once and store them into four int variables, instead of performing about thirty mathematical operations,
and 3) I'd like to know where this guy learnt that strings end with a null pointer instead of a NUL (backslash-zero) char.
Dulcis in fundo, even the shell script that called the program contained a few gems:
mkdir
../$REP_SIMUL/$FICH_RES/
rm
../$REP_SIMUL/$FICH_RES/*
mkdir ../$REP_SIMUL/$FICH_FIG/
rm
../$REP_SIMUL/$FICH_FIG/*