aboutsummaryrefslogtreecommitdiffstats
path: root/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'io.c')
-rw-r--r--io.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/io.c b/io.c
index bb62d3de54..45931adacf 100644
--- a/io.c
+++ b/io.c
@@ -7959,13 +7959,12 @@ setup_narg(int cmd, VALUE *argp, int io_p)
len = 256;
rb_str_modify(arg);
- if (len <= RSTRING_LEN(arg)) {
- len = RSTRING_LEN(arg);
- }
- if (RSTRING_LEN(arg) < len) {
+ /* expand for data + sentinel. */
+ if (RSTRING_LEN(arg) < len+1) {
rb_str_resize(arg, len+1);
}
- RSTRING_PTR(arg)[len] = 17; /* a little sanity check here */
+ /* a little sanity check here */
+ RSTRING_PTR(arg)[RSTRING_LEN(arg) - 1] = 17;
narg = (long)(SIGNED_VALUE)RSTRING_PTR(arg);
}
}