summaryrefslogtreecommitdiff
path: root/io_buffer.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-02-23 14:40:13 +0900
committerGitHub <noreply@github.com>2023-02-23 18:40:13 +1300
commit3b567eb491e460e00a66fdea8054eeb083b5dafd (patch)
tree95475d23504adf491c2772d3b52303c824b44e31 /io_buffer.c
parentda0e6b99c7bae9b1e4644fa8b053d3ed4d67be3f (diff)
downloadruby-3b567eb491e460e00a66fdea8054eeb083b5dafd.tar.gz
[Bug #19459] Remove unnecessary always-true checks (#7362)
`length` is a required argument for `IO::Buffer#read` and `IO::Buffer#write` methods, and `argc` is already checked with `rb_check_arity`. Also fix the call-seq of `IO::Buffer#read`.
Diffstat (limited to 'io_buffer.c')
-rw-r--r--io_buffer.c24
1 files changed, 7 insertions, 17 deletions
diff --git a/io_buffer.c b/io_buffer.c
index c5f0b193c3..6a6bc25628 100644
--- a/io_buffer.c
+++ b/io_buffer.c
@@ -2415,13 +2415,11 @@ rb_io_buffer_read(VALUE self, VALUE io, size_t length, size_t offset)
}
/*
- * call-seq: read(io, [length, [offset]]) -> read length or -errno
+ * call-seq: read(io, length, [offset]) -> read length or -errno
*
* Read at most +length+ bytes from +io+ into the buffer, starting at
* +offset+. If an error occurs, return <tt>-errno</tt>.
*
- * If +length+ is not given, read until the end of the buffer.
- *
* If +offset+ is not given, read from the beginning of the buffer.
*
* If +length+ is 0, read nothing.
@@ -2447,14 +2445,10 @@ io_buffer_read(int argc, VALUE *argv, VALUE self)
VALUE io = argv[0];
- size_t length;
- if (argc >= 2) {
- if (rb_int_negative_p(argv[1])) {
- rb_raise(rb_eArgError, "Length can't be negative!");
- }
-
- length = NUM2SIZET(argv[1]);
+ if (rb_int_negative_p(argv[1])) {
+ rb_raise(rb_eArgError, "Length can't be negative!");
}
+ size_t length = NUM2SIZET(argv[1]);
size_t offset = 0;
if (argc >= 3) {
@@ -2660,14 +2654,10 @@ io_buffer_write(int argc, VALUE *argv, VALUE self)
VALUE io = argv[0];
- size_t length;
- if (argc >= 2) {
- if (rb_int_negative_p(argv[1])) {
- rb_raise(rb_eArgError, "Length can't be negative!");
- }
-
- length = NUM2SIZET(argv[1]);
+ if (rb_int_negative_p(argv[1])) {
+ rb_raise(rb_eArgError, "Length can't be negative!");
}
+ size_t length = NUM2SIZET(argv[1]);
size_t offset = 0;
if (argc >= 3) {