4820 P1M3-Memory check
You cannot submit for this problem because the homework's deadline is due.
Final Pretest
Memory leaks and undefined behaviors are tested here but not counted into grade.
Hint: LeakSanitizer
is unstable. You may ignore the cases when it meets fatal error.
Tasks
12. Handle errors for all supported features. [10]
- Case: 1-8
- At most one of these error occurs in a command
- Non-existing program (Case 1)
- input:
non-exist abc def
- input:
echo abc | non-exist
- output:
non-exist: command not found
- input:
- Non-existing file in input redirection (Case 2)
- input:
cat < non-existing.txt
- output:
non-existing.txt: No such file or directory
- input:
- Failed to open file in output redirection (Case 3)
- input:
echo abc > /dev/permission_denied
- output:
/dev/permission_denied: Permission denied
- input:
- Duplicated input redirection (Case 4)
- input:
echo abc < 1.txt < 2.txt
- input:
echo abc | grep abc < 1.txt
- output:
error: duplicated input redirection
- input:
- Duplicated output redirection (Case 5)
- input:
echo abc > 1.txt > 2.txt
- input:
echo abc > 1.txt >> 2.txt
- input:
echo abc > 1.txt | grep abc
- output:
error: duplicated output redirection
- input:
- Syntax Error (Case 6)
- input:
echo abc > > > >
- output:
syntax error near unexpected token `>'
- input:
echo abc > < 1.txt
- output:
syntax error near unexpected token `<'
- input:
echo abc > | grep abc
- output:
syntax error near unexpected token `|'
- input:
- Missing program (Case 7)
- input:
echo 123 | | grep 123
- input:
> abc
- output:
error: missing program
- input:
cd
to non-existing directory (Case 8)- input:
cd non-existing
- output:
non-existing: No such file or directory
- input: