diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-03-20 10:11:33 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-03-20 11:47:15 +0900 |
| commit | 3703aed7ab7c056ef7a58fd8d25b84b59f715dad (patch) | |
| tree | e15ef6b6b048df9bbb29b353c4053d7698e6aee9 /mrbgems/mruby-compiler | |
| parent | 339c6aed640310249925e351e7c9b23bbdf64d07 (diff) | |
| download | mruby-3703aed7ab7c056ef7a58fd8d25b84b59f715dad.tar.gz mruby-3703aed7ab7c056ef7a58fd8d25b84b59f715dad.zip | |
Use `snprintf()` to stringify fixnum numbers; ref #3492
Diffstat (limited to 'mrbgems/mruby-compiler')
| -rw-r--r-- | mrbgems/mruby-compiler/core/codegen.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c index 1ca86761c..34efdf732 100644 --- a/mrbgems/mruby-compiler/core/codegen.c +++ b/mrbgems/mruby-compiler/core/codegen.c @@ -2181,13 +2181,13 @@ codegen(codegen_scope *s, node *tree, int val) case NODE_BACK_REF: if (val) { - char buf[2] = { '$' }; - mrb_value str; + char buf[3]; int sym; + buf[0] = '$'; buf[1] = (char)(intptr_t)tree; - str = mrb_str_new(s->mrb, buf, 2); - sym = new_sym(s, mrb_intern_str(s->mrb, str)); + buf[2] = 0; + sym = new_sym(s, mrb_intern_cstr(s->mrb, buf)); genop(s, MKOP_ABx(OP_GETGLOBAL, cursp(), sym)); push(); } @@ -2195,14 +2195,12 @@ codegen(codegen_scope *s, node *tree, int val) case NODE_NTH_REF: if (val) { - int sym; mrb_state *mrb = s->mrb; - mrb_value fix = mrb_fixnum_value((intptr_t)tree); - mrb_value str = mrb_str_buf_new(mrb, 4); + char buf[32]; + int sym; - mrb_str_cat_lit(mrb, str, "$"); - mrb_str_cat_str(mrb, str, mrb_fixnum_to_str(mrb, fix, 10)); - sym = new_sym(s, mrb_intern_str(mrb, str)); + snprintf(buf, sizeof(buf), "$%" PRId64, (intptr_t)tree); + sym = new_sym(s, mrb_intern_cstr(mrb, buf)); genop(s, MKOP_ABx(OP_GETGLOBAL, cursp(), sym)); push(); } |
