Use `snprintf()` to stringify fixnum numbers; ref #3492

parent 339c6aed
...@@ -2181,13 +2181,13 @@ codegen(codegen_scope *s, node *tree, int val) ...@@ -2181,13 +2181,13 @@ codegen(codegen_scope *s, node *tree, int val)
case NODE_BACK_REF: case NODE_BACK_REF:
if (val) { if (val) {
char buf[2] = { '$' }; char buf[3];
mrb_value str;
int sym; int sym;
buf[0] = '$';
buf[1] = (char)(intptr_t)tree; buf[1] = (char)(intptr_t)tree;
str = mrb_str_new(s->mrb, buf, 2); buf[2] = 0;
sym = new_sym(s, mrb_intern_str(s->mrb, str)); sym = new_sym(s, mrb_intern_cstr(s->mrb, buf));
genop(s, MKOP_ABx(OP_GETGLOBAL, cursp(), sym)); genop(s, MKOP_ABx(OP_GETGLOBAL, cursp(), sym));
push(); push();
} }
...@@ -2195,14 +2195,12 @@ codegen(codegen_scope *s, node *tree, int val) ...@@ -2195,14 +2195,12 @@ codegen(codegen_scope *s, node *tree, int val)
case NODE_NTH_REF: case NODE_NTH_REF:
if (val) { if (val) {
int sym;
mrb_state *mrb = s->mrb; mrb_state *mrb = s->mrb;
mrb_value fix = mrb_fixnum_value((intptr_t)tree); char buf[32];
mrb_value str = mrb_str_buf_new(mrb, 4); int sym;
mrb_str_cat_lit(mrb, str, "$"); snprintf(buf, sizeof(buf), "$%" PRId64, (intptr_t)tree);
mrb_str_cat_str(mrb, str, mrb_fixnum_to_str(mrb, fix, 10)); sym = new_sym(s, mrb_intern_cstr(mrb, buf));
sym = new_sym(s, mrb_intern_str(mrb, str));
genop(s, MKOP_ABx(OP_GETGLOBAL, cursp(), sym)); genop(s, MKOP_ABx(OP_GETGLOBAL, cursp(), sym));
push(); push();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment