Skip to content

Commit 64f17ff

Browse files
committed
Ensure Errno.{handle,handle_errno} are never called with errno=0
(cherry picked from commit 20c93ab)
1 parent 0500aef commit 64f17ff

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/main/java/org/truffleruby/core/VMPrimitiveNodes.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,4 +529,15 @@ protected long endHash(long hash) {
529529

530530
}
531531

532+
@Primitive(name = "should_not_reach_here")
533+
public abstract static class ShouldNotReachHereNode extends PrimitiveArrayArgumentsNode {
534+
535+
@Specialization(guards = "libString.isRubyString(message)")
536+
protected Object shouldNotReachHere(Object message,
537+
@CachedLibrary(limit = "2") RubyStringLibrary libString) {
538+
throw CompilerDirectives.shouldNotReachHere(libString.getJavaString(message));
539+
}
540+
541+
}
542+
532543
}

src/main/ruby/truffleruby/core/errno.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ module Errno
4343
# Unlike rb_sys_fail(), handle does not raise an exception if errno is 0.
4444
def self.handle(additional = nil)
4545
err = errno
46-
return if err == 0
46+
Primitive.should_not_reach_here('Errno.handle called but errno was 0') if err == 0
4747

4848
raise SystemCallError.new(additional, err)
4949
end
5050

5151
def self.handle_errno(errno)
52-
return if errno == 0
52+
Primitive.should_not_reach_here('Errno.handle_errno called but errno was 0') if errno == 0
5353

5454
raise SystemCallError.new(nil, errno)
5555
end

0 commit comments

Comments
 (0)