summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'string.c')
-rw-r--r--string.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/string.c b/string.c
index cb371c2662..0aa2e6c52c 100644
--- a/string.c
+++ b/string.c
@@ -1693,10 +1693,15 @@ rb_str_unlocktmp(VALUE str)
void
rb_str_set_len(VALUE str, long len)
{
+ long capa;
+
str_modifiable(str);
if (STR_SHARED_P(str)) {
rb_raise(rb_eRuntimeError, "can't set length of shared string");
}
+ if (len > (capa = (long)rb_str_capacity(str))) {
+ rb_bug("probable buffer overflow: %ld for %ld", len, capa);
+ }
STR_SET_LEN(str, len);
RSTRING_PTR(str)[len] = '\0';
}