node.c: check size
* node.c (rb_alloc_tmp_buffer): round up the size and check the range. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51499 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ec10c033a7
commit
8b6a0f7325
@ -1,4 +1,7 @@
|
|||||||
Thu Aug 6 10:44:00 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Thu Aug 6 10:49:57 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* node.c (rb_alloc_tmp_buffer): round up the size and check the
|
||||||
|
range.
|
||||||
|
|
||||||
* ruby_atomic.h (ATOMIC_VALUE_EXCHANGE, ATOMIC_VALUE_CAS): add
|
* ruby_atomic.h (ATOMIC_VALUE_EXCHANGE, ATOMIC_VALUE_CAS): add
|
||||||
atomic operations for VALUE.
|
atomic operations for VALUE.
|
||||||
|
16
node.c
16
node.c
@ -1079,10 +1079,18 @@ rb_gc_mark_node(NODE *obj)
|
|||||||
void *
|
void *
|
||||||
rb_alloc_tmp_buffer(volatile VALUE *store, long len)
|
rb_alloc_tmp_buffer(volatile VALUE *store, long len)
|
||||||
{
|
{
|
||||||
NODE *s = rb_node_newnode(NODE_ALLOCA, 0, 0, 0);
|
NODE *s;
|
||||||
void *ptr = xmalloc(len);
|
long cnt;
|
||||||
s->u1.node = ptr;
|
void *ptr;
|
||||||
s->u3.cnt = len / sizeof(VALUE);
|
|
||||||
|
if (len < 0 || (cnt = (long)roomof(len, sizeof(VALUE))) < 0) {
|
||||||
|
rb_raise(rb_eArgError, "negative buffer size (or size too big)");
|
||||||
|
}
|
||||||
|
|
||||||
|
s = rb_node_newnode(NODE_ALLOCA, 0, 0, 0);
|
||||||
|
ptr = xmalloc(cnt * sizeof(VALUE));
|
||||||
|
s->u1.value = (VALUE)ptr;
|
||||||
|
s->u3.cnt = cnt;
|
||||||
*store = (VALUE)s;
|
*store = (VALUE)s;
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user