From 3f26134944c1773cd3f2cfaff9856fe9f9774efa Mon Sep 17 00:00:00 2001 From: Bernie Hackett Date: Tue, 19 Nov 2013 17:33:43 -0800 Subject: [PATCH] Fix min_key decoding on ARM RUBY-704 Tested on armhf - Raspberry Pi. --- ext/cbson/cbson.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/ext/cbson/cbson.c b/ext/cbson/cbson.c index d863ac7..993d684 100644 --- a/ext/cbson/cbson.c +++ b/ext/cbson/cbson.c @@ -648,10 +648,10 @@ static VALUE method_serialize(VALUE self, VALUE doc, VALUE check_keys, return result; } -static VALUE get_value(const char* buffer, int* position, int type) { +static VALUE get_value(const char* buffer, int* position, unsigned char type) { VALUE value; switch (type) { - case -1: + case 255: { value = rb_class_new_instance(0, NULL, MinKey); break; @@ -682,14 +682,14 @@ static VALUE get_value(const char* buffer, int* position, int type, struct deser int offset = *position + 10; VALUE argv[2]; int collection_length = *(int*)(buffer + offset) - 1; - char id_type; + unsigned char id_type; offset += 4; argv[0] = STR_NEW(buffer + offset, collection_length); offset += collection_length + 1; - id_type = buffer[offset]; + id_type = (unsigned char)buffer[offset]; offset += 5; - argv[1] = get_value(buffer, &offset, (int)id_type); + argv[1] = get_value(buffer, &offset, id_type); value = rb_class_new_instance(2, argv, DBRef); } else { value = elements_to_hash(buffer + *position + 4, size - 5); @@ -706,7 +706,7 @@ static VALUE get_value(const char* buffer, int* position, int type, struct deser value = rb_ary_new(); while (*position < end) { - int type = (int)buffer[(*position)++]; + unsigned char type = (unsigned char)buffer[(*position)++]; int key_size = (int)strlen(buffer + *position); VALUE to_append; @@ -904,7 +904,7 @@ static VALUE elements_to_hash(const char* buffer, int max, struct deserialize_op VALUE hash = rb_class_new_instance(0, NULL, OrderedHash); int position = 0; while (position < max) { - int type = (int)buffer[position++]; + unsigned char type = (unsigned char)buffer[position++]; int name_length = (int)strlen(buffer + position); VALUE name = STR_NEW(buffer + position, name_length); VALUE value; -- 1.8.4