summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2022-04-23 00:24:17 +0900
committergit <svn-admin@ruby-lang.org>2022-09-29 14:06:36 +0900
commit5a8aaedaff48fbf715eed67f29282f9464f118f0 (patch)
tree45afcaf12ef62ced85636678317536dd36c3e350 /ext
parent2f7a530f593dc592b8fe87b65b7d083327b2c1f5 (diff)
[ruby/date] Narrow ALLOCV region for shrunk words
https://github.com/ruby/date/commit/f51b038074
Diffstat (limited to 'ext')
-rw-r--r--ext/date/date_parse.c26
1 files changed, 18 insertions, 8 deletions
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;
}