Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

compiler/prelude: Bug fix: specifying out of range index must panic #775

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

Merged
merged 5 commits into from
Mar 15, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
prelude: Bug fix: specifying out of range index must panic
Fixes #732
  • Loading branch information
hajimehoshi committed Mar 13, 2018
commit 77256a9d91efcbb5be06657cbbbde4e895ba02f0
16 changes: 8 additions & 8 deletions 16 compiler/prelude/prelude.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,19 @@ var $ifaceMethodExpr = function(name) {
};

var $subslice = function(slice, low, high, max) {
if (high === undefined) {
high = slice.$length;
}
if (max === undefined) {
max = slice.$capacity
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is missing a semicolon at the end.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}
if (low < 0 || high < low || max < high || high > slice.$capacity || max > slice.$capacity) {
$throwRuntimeError("slice bounds out of range");
}
var s = new slice.constructor(slice.$array);
s.$offset = slice.$offset + low;
s.$length = slice.$length - low;
s.$capacity = slice.$capacity - low;
if (high !== undefined) {
s.$length = high - low;
}
if (max !== undefined) {
s.$capacity = max - low;
}
s.$length = high - low;
s.$capacity = max - low;
return s;
};

Expand Down
12 changes: 12 additions & 0 deletions 12 tests/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,3 +623,15 @@ func TestTypeConversion(t *testing.T) {
t.Fail()
}
}

func TestSliceOutOfRange(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about moving this test and placing it next to TestSliceOfString, since it's quite similar and related?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

defer func() {
if err := recover(); err == nil || !strings.Contains(err.(error).Error(), "slice bounds out of range") {
t.Fail()
}
}()

a := make([]byte, 4096)
b := a[8192:]
Copy link
Member

@dmitshur dmitshur Mar 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need to use numbers so large, the same issue would happen with make([]byte, 4) and a[8:], right? Maybe it's better to use those smaller numbers to make the test focus more on the underlying issue and less resource intensive.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong opinion on it :-) Done.

_ = b
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.