From 5a8aaedaff48fbf715eed67f29282f9464f118f0 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sat, 23 Apr 2022 00:24:17 +0900 Subject: [ruby/date] Narrow ALLOCV region for shrunk words https://github.com/ruby/date/commit/f51b038074 --- ext/date/date_parse.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'ext/date') diff --git a/ext/date/date_parse.c b/ext/date/date_parse.c index 4890401894..6155293bb9 100644 --- a/ext/date/date_parse.c +++ b/ext/date/date_parse.c @@ -413,7 +413,6 @@ VALUE date_zone_to_diff(VALUE str) { VALUE offset = Qnil; - VALUE vbuf = 0; long l = RSTRING_LEN(str); const char *s = RSTRING_PTR(str); @@ -439,16 +438,27 @@ date_zone_to_diff(VALUE str) l -= w; dst = 1; } + { + const char *zn = s; long sl = shrunk_size(s, l); - if (sl > 0 && sl <= MAX_WORD_LENGTH) { + VALUE vbuf = 0; + const struct zone *z = 0; + + if (sl <= 0) { + sl = l; + } + else if (sl <= MAX_WORD_LENGTH) { char *d = ALLOCV_N(char, vbuf, sl); - l = shrink_space(d, s, l); - s = d; + sl = shrink_space(d, s, l); + zn = d; } - } - if (l > 0 && l <= MAX_WORD_LENGTH) { - const struct zone *z = zonetab(s, (unsigned int)l); + + if (sl > 0 && sl <= MAX_WORD_LENGTH) { + z = zonetab(zn, (unsigned int)sl); + } + ALLOCV_END(vbuf); + if (z) { int d = z->offset; if (dst) @@ -457,6 +467,7 @@ date_zone_to_diff(VALUE str) goto ok; } } + { char *p; int sign = 0; @@ -542,7 +553,6 @@ date_zone_to_diff(VALUE str) } RB_GC_GUARD(str); ok: - ALLOCV_END(vbuf); return offset; } -- cgit v1.2.3