summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2016-12-13 10:50:04 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2016-12-13 10:50:04 +0900
commit3bedd22d55fafef83f2ddf387cb595cf5ea60e63 (patch)
tree3ca9452a233e0085ed80ca27fcd41221d6714a21
parent3a7c3695360e598ce4279a979cc9138a35971615 (diff)
downloadmruby-3bedd22d55fafef83f2ddf387cb595cf5ea60e63.tar.gz
mruby-3bedd22d55fafef83f2ddf387cb595cf5ea60e63.zip
Add assertion to make sure new capacity does not overflow.
-rw-r--r--src/string.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/string.c b/src/string.c
index dfe4fa3b1..0049fdd5b 100644
--- a/src/string.c
+++ b/src/string.c
@@ -118,8 +118,8 @@ mrb_str_buf_new(mrb_state *mrb, size_t capa)
return mrb_obj_value(s);
}
-static inline void
-resize_capa(mrb_state *mrb, struct RString *s, mrb_int capacity)
+static void
+resize_capa(mrb_state *mrb, struct RString *s, size_t capacity)
{
if (RSTR_EMBED_P(s)) {
if (RSTRING_EMBED_LEN_MAX < capacity) {
@@ -133,6 +133,9 @@ resize_capa(mrb_state *mrb, struct RString *s, mrb_int capacity)
}
}
else {
+#if SIZE_MAX > MRB_INT_MAX
+ mrb_assert(capacity <= MRB_INT_MAX);
+#endif
s->as.heap.ptr = (char *)mrb_realloc(mrb, RSTR_PTR(s), capacity+1);
s->as.heap.aux.capa = capacity;
}