aboutsummaryrefslogtreecommitdiffstats
path: root/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'io.c')
-rw-r--r--io.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/io.c b/io.c
index e4084e7104..de5e6cf136 100644
--- a/io.c
+++ b/io.c
@@ -4461,14 +4461,16 @@ rb_open_file(int argc, VALUE *argv, VALUE io)
int flags;
unsigned int fmode;
- opt = rb_check_convert_type(argv[argc-1], T_HASH, "Hash", "to_hash");
- if (!NIL_P(opt)) {
- VALUE v;
- v = rb_hash_aref(opt, sym_mode);
- if (!NIL_P(v)) vmode = v;
- v = rb_hash_aref(opt, sym_perm);
- if (!NIL_P(v)) perm = v;
- argc -= 1;
+ if (0 < argc) {
+ opt = rb_check_convert_type(argv[argc-1], T_HASH, "Hash", "to_hash");
+ if (!NIL_P(opt)) {
+ VALUE v;
+ v = rb_hash_aref(opt, sym_mode);
+ if (!NIL_P(v)) vmode = v;
+ v = rb_hash_aref(opt, sym_perm);
+ if (!NIL_P(v)) perm = v;
+ argc -= 1;
+ }
}
rb_scan_args(argc, argv, "12", &fname, &vmode, &perm);