Skip to content

Commit f62bf0a

Browse files
committed
The shrunk words to be copied is limited
Th buffer size is small enough and no need to allocate dynamically.
1 parent f51b038 commit f62bf0a

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

ext/date/date_parse.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,22 +442,21 @@ date_zone_to_diff(VALUE str)
442442
{
443443
const char *zn = s;
444444
long sl = shrunk_size(s, l);
445-
VALUE vbuf = 0;
445+
char shrunk_buff[MAX_WORD_LENGTH]; /* no terminator to be added */
446446
const struct zone *z = 0;
447447

448448
if (sl <= 0) {
449449
sl = l;
450450
}
451451
else if (sl <= MAX_WORD_LENGTH) {
452-
char *d = ALLOCV_N(char, vbuf, sl);
452+
char *d = shrunk_buff;
453453
sl = shrink_space(d, s, l);
454454
zn = d;
455455
}
456456

457457
if (sl > 0 && sl <= MAX_WORD_LENGTH) {
458458
z = zonetab(zn, (unsigned int)sl);
459459
}
460-
ALLOCV_END(vbuf);
461460

462461
if (z) {
463462
int d = z->offset;

test/date/test_date_parse.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def test__parse
4141
[['Sat Aug 28 02:29:34 Mountain Daylight Time 2000',false],[2000,8,28,2,29,34,'Mountain Daylight Time',-6*3600,6], __LINE__],
4242
[['Sat Aug 28 02:29:34 Mexico Standard Time 2000',false],[2000,8,28,2,29,34,'Mexico Standard Time',-6*3600,6], __LINE__],
4343
[['Sat Aug 28 02:29:34 E. Australia Standard Time 2000',false],[2000,8,28,2,29,34,'E. Australia Standard Time',10*3600,6], __LINE__],
44+
[['Sat Aug 28 02:29:34 W. Central Africa Standard Time 2000',false],[2000,8,28,2,29,34,'W. Central Africa Standard Time',1*3600,6], __LINE__],
4445

4546
# part of iso 8601
4647
[['1999-05-23 23:55:21',false],[1999,5,23,23,55,21,nil,nil,nil], __LINE__],

0 commit comments

Comments
 (0)