mikeizbicki / ucr-cs100

open source software construction course
Other
485 stars 407 forks source link

rshell runs perfectly fine on home computer, but has random execvp: Bad address output in hammer #287

Closed hlao002 closed 9 years ago

hlao002 commented 9 years ago

While running the program at home, the program works perfectly fine. But when testing the program in hammer, all commands randomly fail giving the error "execvp: Bad address"

Note* the Argv[i]s == are whats being pass into execvp.

Output 1:

hlao002@hammer.cs.ucr.edu$ echo cat ; ls ; pwd Argv[0] ==echo Argv[1] ==cat cat Argv[0] ==ls a.out bin LICENSE Makefile README.md src Argv[0] ==pwd /home/csmajs/hlao002/CS100/rshell

Output 2:

hlao002@hammer.cs.ucr.edu$ echo cat ; ls ; pwd Argv[0] ==echo Argv[1] ==cat cat Argv[0] ==ls a.out bin LICENSE Makefile README.md src Argv[0] ==pwd execvp: Bad address hlao002@hammer.cs.ucr.edu$

Output 3:

hlao002@hammer.cs.ucr.edu$ echo cat ; ls ; pwd Argv[0] ==echo Argv[1] ==cat cat Argv[0] ==ls execvp: Bad address Argv[0] ==pwd execvp: Bad address

Any idea as to why this is happening?

hgarc014 commented 9 years ago

are you making sure the last Argv is terminated by a null character?? that might be your problem

tkimva commented 9 years ago

that's you have to check. please refer #276

tkimva commented 9 years ago

It seems like you incorrectly assigned the null terminating. It should be the last array not the end of each array as you wrote the code Argv[cmd.size()] = NULL; but I think it should be Argv[j] = NULL; Right? please change it. I think it will be fine. Let me know

tkimva commented 9 years ago

It solved.