Skip to content

Commit

Permalink
[Truffle] Add EINVAL for negative File.truncate length
Browse files Browse the repository at this point in the history
  • Loading branch information
bjfish committed May 7, 2015
1 parent 15863ec commit dc1de58
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 0 additions & 1 deletion spec/truffle/tags/core/file/truncate_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
fails:File.truncate raises an Errno::EINVAL if the length argument is not valid
fails:File#truncate raises an IOError if file is closed
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ public int truncate(RubyString path, int length) {

@Specialization
public int truncate(RubyString path, long length) {
if (length < 0) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().invalidArgumentError(Long.toString(length), this));
}
final String pathString = RubyEncoding.decodeUTF8(path.getByteList().getUnsafeBytes(), path.getByteList().getBegin(), path.getByteList().getRealSize());
return posix().truncate(pathString, length);
}
Expand Down

2 comments on commit dc1de58

@nirvdrum
Copy link
Contributor

Choose a reason for hiding this comment

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

You might be better off checking the return value from the POSIX call for -1 and then converting the errno value to a Ruby exception.

@bjfish
Copy link
Contributor Author

@bjfish bjfish commented on dc1de58 May 7, 2015

Choose a reason for hiding this comment

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

@nirvdrum Fixed here: 440a90f

Please sign in to comment.