diff options
| author | KOBAYASHI Shuji <[email protected]> | 2021-01-27 11:42:18 +0900 |
|---|---|---|
| committer | KOBAYASHI Shuji <[email protected]> | 2021-01-27 11:42:18 +0900 |
| commit | 504788bf89242c0be0c6027d59da5f5ec89b0d24 (patch) | |
| tree | 41a4d6ede8e24caa532ae2b88a68572269c5850c /src/dump.c | |
| parent | 73418a90faf9d83834191318888b74289cc3ddea (diff) | |
| download | mruby-504788bf89242c0be0c6027d59da5f5ec89b0d24.tar.gz mruby-504788bf89242c0be0c6027d59da5f5ec89b0d24.zip | |
Avoid 'possible loss of data' casting in binary search
Because it may not be expected result.
example: https://wandbox.org/permlink/F5Mp7IEJ1VY3CFLp
Diffstat (limited to 'src/dump.c')
| -rw-r--r-- | src/dump.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/dump.c b/src/dump.c index 216701ba8..5173b88e5 100644 --- a/src/dump.c +++ b/src/dump.c @@ -1036,14 +1036,16 @@ sym_name_cvar_p(const char *name, mrb_int len) static const char* sym_operator_name(const char *sym_name, mrb_int len) { - mrb_sym start, idx; mrb_sym table_size = sizeof(operator_table)/sizeof(struct operator_symbol); + if (operator_table[table_size-1].sym_name_len < len) return NULL; + + mrb_sym start, idx; int cmp; const struct operator_symbol *op_sym; for (start = 0; table_size != 0; table_size/=2) { idx = start+table_size/2; op_sym = &operator_table[idx]; - cmp = (int)(len-op_sym->sym_name_len); + cmp = (int)len-(int)op_sym->sym_name_len; if (cmp == 0) { cmp = memcmp(sym_name, op_sym->sym_name, len); if (cmp == 0) return op_sym->name; |
