diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2019-03-27 17:38:06 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2019-03-27 17:38:06 +0900 |
| commit | 92dce053ad3432587425ad5b1e4a3cc12b190edc (patch) | |
| tree | c2f3d2c26c640b27a775e6195a7fe0ba45cb7df5 /src | |
| parent | b8f00e439dd0eaa8282b635bfdaff446ae52d760 (diff) | |
| download | mruby-92dce053ad3432587425ad5b1e4a3cc12b190edc.tar.gz mruby-92dce053ad3432587425ad5b1e4a3cc12b190edc.zip | |
Fix another bug related to #4342
For short symbols with alpha numeric characters, `mrb_sym2name_len()`
returns the same buffer `mrb->symbuf`. Some occasion, we forget the fact
that the second call could overwrite the result of first call of the
function.
We have prepared the static function `sym2name()` which specifies the
buffer region for inline packed symbols and use the function in
`mrb_sym_to_s`.
Diffstat (limited to 'src')
| -rw-r--r-- | src/symbol.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/symbol.c b/src/symbol.c index 4d6c20e68..4cf79046e 100644 --- a/src/symbol.c +++ b/src/symbol.c @@ -237,11 +237,11 @@ mrb_check_intern_str(mrb_state *mrb, mrb_value str) } MRB_API const char* -mrb_sym2name_len(mrb_state *mrb, mrb_sym sym, mrb_int *lenp) +sym2name(mrb_state *mrb, mrb_sym sym, char *buf, mrb_int *lenp) { #ifndef MRB_ENABLE_ALL_SYMBOLS if (sym & 1) { /* inline packed symbol */ - return sym_inline_unpack(sym, mrb->symbuf, lenp); + return sym_inline_unpack(sym, buf, lenp); } #endif @@ -255,6 +255,12 @@ mrb_sym2name_len(mrb_state *mrb, mrb_sym sym, mrb_int *lenp) return mrb->symtbl[sym].name; } +MRB_API const char* +mrb_sym2name_len(mrb_state *mrb, mrb_sym sym, mrb_int *lenp) +{ + return sym2name(mrb, sym, mrb->symbuf, lenp); +} + void mrb_free_symtbl(mrb_state *mrb) { @@ -325,10 +331,9 @@ mrb_sym_to_s(mrb_state *mrb, mrb_value sym) mrb_int len; p = mrb_sym2name_len(mrb, id, &len); -#ifndef MRB_ENABLE_SYMBOLL_ALL - if (p == mrb->symbuf) + if (id&1) { /* inline symbol */ return mrb_str_new(mrb, p, len); -#endif + } return mrb_str_new_static(mrb, p, len); } @@ -545,9 +550,10 @@ sym_cmp(mrb_state *mrb, mrb_value s1) const char *p1, *p2; int retval; mrb_int len, len1, len2; + char buf1[8], buf2[8]; - p1 = mrb_sym2name_len(mrb, sym1, &len1); - p2 = mrb_sym2name_len(mrb, sym2, &len2); + p1 = sym2name(mrb, sym1, buf1, &len1); + p2 = sym2name(mrb, sym2, buf2, &len2); len = lesser(len1, len2); retval = memcmp(p1, p2, len); if (retval == 0) { |
