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 <noreply@anthropic.com>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2026-01-13 08:17:23 +09:00
parent 5065d7f813
commit 147b341863
+3
View File
@@ -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;