summaryrefslogtreecommitdiffhomepage
path: root/src/dump.c
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2021-01-27 12:15:58 +0900
committerGitHub <[email protected]>2021-01-27 12:15:58 +0900
commit5e479c66d56f5938f330e7e71313dc95747b3bb1 (patch)
treea12cdf1113daa3f58aaeff5e8a478745c1534cbb /src/dump.c
parent89cd742506019d2a1987b8fdd5c8fee792d1d5c2 (diff)
parent504788bf89242c0be0c6027d59da5f5ec89b0d24 (diff)
downloadmruby-5e479c66d56f5938f330e7e71313dc95747b3bb1.tar.gz
mruby-5e479c66d56f5938f330e7e71313dc95747b3bb1.zip
Merge pull request #5300 from shuujii/avoid-possible-loss-of-data-casting-in-binary-search
Avoid 'possible loss of data' casting in binary search
Diffstat (limited to 'src/dump.c')
-rw-r--r--src/dump.c6
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;