Forgot that the index 0 was reserved

This commit is contained in:
Gerard Wagener 2010-01-08 22:25:24 +01:00
parent 16989baa5f
commit e50b1b2c29

View file

@ -7,20 +7,27 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#define N 4 #define N 5
char* list[] = {"Fuck you",
/* The element 0 is reserved for that insult is not set and if the program is
* started from the shell with no arguments nothing should happen
* atoi(sss) -> 0
*/
char* list[] = {"",
"Fuck you",
"Is that all? I want to do more ...", "Is that all? I want to do more ...",
"Go away", "Go away",
"I love you"}; "I love you"};
int main(int argc, char* argv[]){ int main(int argc, char* argv[]){
int idx; int idx;
if (argc==2){ /* If another argv is used, then maybe only argv[0] is allocated when
idx=atoi(argv[1]); * no command lines are delivered. Therefore the kernel overwrites this
* to avoid to allocate / smash the stack
*/
idx=atoi(argv[0]);
if ((idx>=0) && (idx<N)) if ((idx>=0) && (idx<N))
printf("%s\n",list[idx]); printf("%s\n",list[idx]);
return 0; return 0;
}
return 1;
} }