ext/struct.c in thrift-0.7.0 vs ext/struct.c in thrift-0.8.0

- old
+ new

@@ -18,38 +18,12 @@ */ #include "struct.h" #include "constants.h" #include "macros.h" +#include "strlcpy.h" -#ifndef HAVE_STRLCPY - -static -size_t -strlcpy (char *dst, const char *src, size_t dst_sz) -{ - size_t n; - - for (n = 0; n < dst_sz; n++) { - if ((*dst++ = *src++) == '\0') - break; - } - - if (n < dst_sz) - return n; - if (n > 0) - *(dst - 1) = '\0'; - return n + strlen (src); -} -#else -/* - Ruby 1.9.x includes the OpenBSD implementation of strlcpy. - See missing/strlcpy.c in Ruby 1.9 source - */ -extern size_t strlcpy(char *, const char *, size_t); -#endif - VALUE thrift_union_class; ID setfield_id; ID setvalue_id; @@ -229,14 +203,14 @@ static VALUE rb_thrift_union_write (VALUE self, VALUE protocol); static VALUE rb_thrift_struct_write(VALUE self, VALUE protocol); static void write_anything(int ttype, VALUE value, VALUE protocol, VALUE field_info); VALUE get_field_value(VALUE obj, VALUE field_name) { - char name_buf[RSTRING_LEN(field_name) + 1]; + char name_buf[RSTRING_LEN(field_name) + 2]; name_buf[0] = '@'; - strlcpy(&name_buf[1], RSTRING_PTR(field_name), sizeof(name_buf)); + strlcpy(&name_buf[1], RSTRING_PTR(field_name), RSTRING_LEN(field_name) + 1); VALUE value = rb_ivar_get(obj, rb_intern(name_buf)); return value; } @@ -415,14 +389,14 @@ static VALUE rb_thrift_struct_read(VALUE self, VALUE protocol); static void skip_map_contents(VALUE protocol, VALUE key_type_value, VALUE value_type_value, int size); static void skip_list_or_set_contents(VALUE protocol, VALUE element_type_value, int size); static void set_field_value(VALUE obj, VALUE field_name, VALUE value) { - char name_buf[RSTRING_LEN(field_name) + 1]; + char name_buf[RSTRING_LEN(field_name) + 2]; name_buf[0] = '@'; - strlcpy(&name_buf[1], RSTRING_PTR(field_name), sizeof(name_buf)); + strlcpy(&name_buf[1], RSTRING_PTR(field_name), RSTRING_LEN(field_name)+1); rb_ivar_set(obj, rb_intern(name_buf), value); } // Helper method to skip the contents of a map (assumes the map header has been read). @@ -482,10 +456,10 @@ VALUE value_info = rb_hash_aref(field_info, value_sym); if (!NIL_P(key_info) && !NIL_P(value_info)) { int specified_key_type = FIX2INT(rb_hash_aref(key_info, type_sym)); int specified_value_type = FIX2INT(rb_hash_aref(value_info, type_sym)); - if (specified_key_type == key_ttype && specified_value_type == value_ttype) { + if (num_entries == 0 || (specified_key_type == key_ttype && specified_value_type == value_ttype)) { result = rb_hash_new(); for (i = 0; i < num_entries; ++i) { VALUE key, val;