Commit f2f67326 authored by Augusto Caringi's avatar Augusto Caringi

Avoid crashing if mistakenly just '-d' or '-v' is used

Currently, if by mistake just '-v' or '-d' is used without any
additional parameter (no filename nor -e 'program') bpftrace crashes:

./src/bpftrace -v
terminate called after throwing an instance of 'std::logic_error'
what():  basic_string::_M_construct null not valid
Aborted (core dumped)

This commit fix this problem.
parent 578bfb84
...@@ -152,6 +152,11 @@ int main(int argc, char *argv[]) ...@@ -152,6 +152,11 @@ int main(int argc, char *argv[])
{ {
// Script file // Script file
char *file_name = argv[optind]; char *file_name = argv[optind];
if (!file_name)
{
std::cerr << "USAGE: filename or -e 'program' required." << std::endl;
return 1;
}
err = driver.parse_file(file_name); err = driver.parse_file(file_name);
optind++; optind++;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment