From d87ef24bf0cadb0b5de5ab6e098aa839cec06c84 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Mon, 20 Jul 2026 09:34:33 +0900 Subject: [PATCH 1/2] Fix build failure on mswin due to VLA in packer.h MSVC does not support C99 variable-length arrays, so `char buf[len]` in msgpack_packer_write_bignum_value fails with C2057/C2466/C2133. Use ALLOCV_N instead, which falls back to a GC-managed heap buffer and stays safe across rb_raise. Co-Authored-By: Claude Fable 5 --- ext/cbor/packer.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ext/cbor/packer.h b/ext/cbor/packer.h index 21a5001..b6efbf3 100644 --- a/ext/cbor/packer.h +++ b/ext/cbor/packer.h @@ -268,11 +268,13 @@ static inline void msgpack_packer_write_bignum_value(msgpack_packer_t* pk, VALUE cbor_encoder_write_head(pk, IB_BYTES, len); msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), len); - char buf[len]; /* XXX */ + VALUE buf_v; + char *buf = ALLOCV_N(char, buf_v, len); /* MSVC C has no VLA */ if (rb_integer_pack(v, buf, len, 1, 0, INTEGER_PACK_BIG_ENDIAN) != 1) rb_raise(rb_eRangeError, "cbor rb_integer_pack() error"); msgpack_buffer_append(PACKER_BUFFER_(pk), buf, len); + ALLOCV_END(buf_v); #else From 0a5aa49fcdc660ae2cb6c0fdacf51b9c0a4e7b30 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Mon, 20 Jul 2026 09:34:47 +0900 Subject: [PATCH 2/2] Use rb_num2ull for tag values unsigned long is 32-bit on Windows (LLP64), so rb_num2ulong raises RangeError for tags above 0xffffffff and the "Tagged" spec fails. cbor_encoder_write_head takes uint64_t; convert with rb_num2ull. Co-Authored-By: Claude Fable 5 --- ext/cbor/packer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/cbor/packer.h b/ext/cbor/packer.h index b6efbf3..eb8f1c9 100644 --- a/ext/cbor/packer.h +++ b/ext/cbor/packer.h @@ -358,7 +358,7 @@ void msgpack_packer_write_value(msgpack_packer_t* pk, VALUE v); static inline void msgpack_packer_write_tagged_value(msgpack_packer_t* pk, VALUE v) { - cbor_encoder_write_head(pk, IB_TAG, rb_num2ulong(rb_struct_aref(v, INT2FIX(0)))); + cbor_encoder_write_head(pk, IB_TAG, rb_num2ull(rb_struct_aref(v, INT2FIX(0)))); msgpack_packer_write_value(pk, rb_struct_aref(v, INT2FIX(1))); }