From 147b3418637bb9851871ffb02083e09efb5b9b1d Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Tue, 13 Jan 2026 08:17:23 +0900 Subject: [PATCH] mruby-bigint: fix missing null terminator in D&C to_s mpz_to_s_dc_recur fills in exactly num_digits characters but did not add a null terminator. This caused valgrind errors when strlen was called on the resulting string. Co-authored-by: Claude --- mrbgems/mruby-bigint/core/bigint.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mrbgems/mruby-bigint/core/bigint.c b/mrbgems/mruby-bigint/core/bigint.c index ce502c520..7116aaa36 100644 --- a/mrbgems/mruby-bigint/core/bigint.c +++ b/mrbgems/mruby-bigint/core/bigint.c @@ -2755,6 +2755,9 @@ mpz_to_s_dc(mpz_ctx_t *ctx, char *s, mpz_t *x) /* Do the recursive conversion */ mpz_to_s_dc_recur(ctx, s, &tmp, num_digits, pow5, num_powers, &scratch); + /* Null-terminate the string */ + s[num_digits] = '\0'; + mrb->jmp = prev_jmp; } MRB_CATCH(&c_jmp) { mrb->jmp = prev_jmp;