Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error if Positional Params num is zero #1568

Merged
merged 1 commit into from
Oct 26, 2020

Conversation

mmisono
Copy link
Collaborator

@mmisono mmisono commented Oct 21, 2020

Positional parameter zero ($0) is invalid. Previously, using $0 causes
std::out_of_range error due to the underflow and confuses users.

% sudo ./src/bpftrace -e 'k:$0 {}' vfs_open
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 18446744073709551615) >= this->size() (which is 1)
zsh: abort      sudo ./src/bpftrace -e 'k:$0 {}' vfs_open

This commit changes this and in the parser check the positional params
num is not zero. This can be also done in the lexical analyzer, but to
print verbose an error message do this in the parser. Now the error message is

% sudo ./src/bpftrace -e 'k:$0 {}' vfs_open
stdin:1:1-5: ERROR: param $0 is out of integer range [1, 9223372036854775807]
k:$0 {}
~~~
Checklist
  • Language changes are updated in docs/reference_guide.md
  • User-visible and non-trivial changes updated in CHANGELOG.md
  • The new behaviour is covered by tests

src/parser.yy Show resolved Hide resolved
Positional parameter zero ($0) is invalid. Previously, using $0 causes
std::out_of_range error due to the underflow and confuses users.

```
% sudo ./src/bpftrace -e 'k:$0 {}' vfs_open
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 18446744073709551615) >= this->size() (which is 1)
zsh: abort      sudo ./src/bpftrace -e 'k:$0 {}' vfs_open
```

This commit changes this and in the parser check the positional params
num is not zero. This can be also done in the lexical analyzer, but to
print verbose an error message do this in the parser. Now the error message is

```
% sudo ./src/bpftrace -e 'k:$0 {}' vfs_open
stdin:1:1-5: ERROR: param $0 is out of integer range [1, 9223372036854775807]
k:$0 {}
~~~
```
@mmisono
Copy link
Collaborator Author

mmisono commented Oct 26, 2020

@fbs
Is It OK to merge this? My fixes' CHANGELOG would conflict, so I'll fix it one by one.

@mmisono mmisono merged commit 4c1d810 into bpftrace:master Oct 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants