From 0e9169639764c8a4cd57235a04d85dcf3544575f Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Thu, 24 Jul 2025 12:30:04 +0900 Subject: [PATCH] dump.c: add type cast to retrieve bigint length from the pool If bigint representation is too long, the retrieved length (without type cast) can be considered as negative. To avoid the issue, we have to add type cast before assignments. --- src/dump.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dump.c b/src/dump.c index b06863e22..844a86225 100644 --- a/src/dump.c +++ b/src/dump.c @@ -165,7 +165,7 @@ get_pool_block_size(mrb_state *mrb, const mrb_irep *irep) case IREP_TT_BIGINT: { - mrb_int len = irep->pool[pool_no].u.str[0]; + mrb_int len = (uint8_t)irep->pool[pool_no].u.str[0]; mrb_assert_int_fit(mrb_int, len, size_t, SIZE_MAX); size += (size_t)len+2; } @@ -242,7 +242,7 @@ write_pool_block(mrb_state *mrb, const mrb_irep *irep, uint8_t *buf) case IREP_TT_BIGINT: cur += uint8_to_bin(IREP_TT_BIGINT, cur); /* data type */ - len = irep->pool[pool_no].u.str[0]; + len = (uint8_t)irep->pool[pool_no].u.str[0]; memcpy(cur, irep->pool[pool_no].u.str, (size_t)len+2); cur += len+2; break;