ruby: fixes MessagePack_Unpacker_mark marks uninitialized map_key

This commit is contained in:
frsyuki
2009-12-10 04:32:33 +09:00
parent eb9e892491
commit 0ae1965f6b

View File

@@ -127,6 +127,15 @@ static inline int template_callback_raw(unpack_user* u, const char* b, const cha
static VALUE cUnpacker; static VALUE cUnpacker;
static VALUE eUnpackError; static VALUE eUnpackError;
// FIXME slow operation
static void init_stack(msgpack_unpack_t* mp)
{
size_t i;
for(i=0; i < MSGPACK_MAX_STACK_SIZE; ++i) {
mp->stack[i].map_key = Qnil; /* GC */
}
}
static void MessagePack_Unpacker_free(void* data) static void MessagePack_Unpacker_free(void* data)
{ {
if(data) { free(data); } if(data) { free(data); }
@@ -137,7 +146,7 @@ static void MessagePack_Unpacker_mark(msgpack_unpack_t *mp)
unsigned int i; unsigned int i;
for(i=0; i < mp->top; ++i) { for(i=0; i < mp->top; ++i) {
rb_gc_mark(mp->stack[i].obj); rb_gc_mark(mp->stack[i].obj);
rb_gc_mark(mp->stack[i].map_key); rb_gc_mark(mp->stack[i].map_key); /* maybe map_key is not initialized */
} }
} }
@@ -154,6 +163,7 @@ static VALUE MessagePack_Unpacker_reset(VALUE self)
{ {
UNPACKER(self, mp); UNPACKER(self, mp);
template_init(mp); template_init(mp);
init_stack(mp);
unpack_user u = {0, Qnil}; unpack_user u = {0, Qnil};
mp->user = u; mp->user = u;
return self; return self;
@@ -281,6 +291,7 @@ static VALUE MessagePack_unpack_limit(VALUE self, VALUE data, VALUE limit)
msgpack_unpack_t mp; msgpack_unpack_t mp;
template_init(&mp); template_init(&mp);
init_stack(&mp);
unpack_user u = {0, Qnil}; unpack_user u = {0, Qnil};
mp.user = u; mp.user = u;