ext/asciipack/unpacker.c in asciipack-0.2.0 vs ext/asciipack/unpacker.c in asciipack-0.2.1
- old
+ new
@@ -54,12 +54,11 @@
static uint64_t
to_i16all (unpacker_t* ptr, int len)
{
uint64_t ret = 0;
while (len--) {
- ret += to_i16(*ptr->ch);
- ptr->ch++;
+ ret += to_i16(*ptr->ch++);
if (len != 0) ret = ret << 4;
}
return ret;
}
@@ -100,10 +99,11 @@
{
char* head = ptr->ch;
VALUE str = rb_str_new(head, len);
rb_funcall(str, rb_intern("force_encoding"), 1, rb_str_new2("utf-8"));
+ ptr->ch += len;
return str;
}
static VALUE
Unpacker_map (unpacker_t* ptr, size_t len)
@@ -131,13 +131,11 @@
static VALUE
Unpacker_read (unpacker_t* ptr)
{
uint64_t num;
- ptr->ch++;
-
- switch (*(ptr->ch - 1)) {
+ switch (*ptr->ch++) {
case 'a': // int 4
num = Unpacker_int(ptr, 1);
return INT2FIX(num);
case 'b': // int 8
@@ -265,10 +263,10 @@
case 'W': return Qnil;
case 'X': return Qfalse;
case 'Y': return Qtrue;
}
- rb_raise(rb_eArgError, "undefined type:%c", *(ptr->ch));
+ rb_raise(rb_eArgError, "undefined type:%c,data:%s,at:%ld", *(ptr->ch), ptr->buffer, ptr->ch - ptr->buffer);
return Qnil;
}
static VALUE
Unpacker_unpack (VALUE self)