From 8d4e7f7caf97aa7e9d5140443c598925978b9bc5 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Sat, 10 Oct 2026 03:46:28 +0900 Subject: [PATCH] Use rb_len_t for String lengths in erb/escape It falls back to long on Ruby versions that do not define HAVE_RB_LEN_T, so the change also builds there. Co-Authored-By: Claude Opus 5.5 --- ext/erb/escape/escape.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ext/erb/escape/escape.c b/ext/erb/escape/escape.c index 80f6c73..9a85fd3 100644 --- a/ext/erb/escape/escape.c +++ b/ext/erb/escape/escape.c @@ -1,6 +1,11 @@ #include "ruby.h" #include "ruby/encoding.h" +#ifndef HAVE_RB_LEN_T +typedef long rb_len_t; +# define RB_LEN_MAX LONG_MAX +#endif + static VALUE rb_cCGI; static ID id_escapeHTML; @@ -14,11 +19,11 @@ static const bool html_escape_table[UCHAR_MAX+1] = { ['>'] = true, }; -static inline long +static inline rb_len_t escaped_length(VALUE str) { - const long len = RSTRING_LEN(str); - if (len >= LONG_MAX / HTML_ESCAPE_MAX_LEN) { + const rb_len_t len = RSTRING_LEN(str); + if (len >= RB_LEN_MAX / HTML_ESCAPE_MAX_LEN) { ruby_malloc_size_overflow(len, HTML_ESCAPE_MAX_LEN); } return len * HTML_ESCAPE_MAX_LEN;