Skip to content

Commit e3fdbcb

Browse files
author
Eric Wong
committed
result: avoid dynamically-sized stack allocation
Otherwise, long field names have the potential to cause stack overflow and perhaps slow down the MRI GC. This reduces one extraneous data copy while we're at it, too. Using the checkstack.pl script in the Linux kernel reveals no other dynamically sized stack allcations after this change. usage: objdump -d mysql2.so | ~/linux/scripts/checkstack.pl x86_64
1 parent ba0068c commit e3fdbcb

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

ext/mysql2/result.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,12 @@ static VALUE rb_mysql_result_fetch_field(VALUE self, unsigned int idx, short int
122122

123123
field = mysql_fetch_field_direct(wrapper->result, idx);
124124
if (symbolize_keys) {
125-
char buf[field->name_length+1];
126-
memcpy(buf, field->name, field->name_length);
127-
buf[field->name_length] = 0;
128-
129125
#ifdef HAVE_RB_INTERN3
130-
rb_field = rb_intern3(buf, field->name_length, rb_utf8_encoding());
126+
rb_field = rb_intern3(field->name, field->name_length, rb_utf8_encoding());
131127
rb_field = ID2SYM(rb_field);
132128
#else
133129
VALUE colStr;
134-
colStr = rb_str_new2(buf);
130+
colStr = rb_str_new(field->name, field->name_length);
135131
rb_field = ID2SYM(rb_to_id(colStr));
136132
#endif
137133
} else {

0 commit comments

Comments
 (0)