Skip to content

Commit

Permalink
Add assertion to make sure new capacity does not overflow.
Browse files Browse the repository at this point in the history
  • Loading branch information
matz committed Dec 13, 2016
1 parent 3a7c369 commit 3bedd22
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down

0 comments on commit 3bedd22

Please sign in to comment.