Fix overwritten zone string
* time.c (zone_str): while rb_fstring_usascii and the family require that the argument string is never modified, tzname may point areas which will be discarded by calling tzset(). make a String then call rb_fstring to copy the zone name. when an ID equals TZ environment variable, its name string also has modified by changing tzname. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65035 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5b61288fac
commit
1821e9f4dc
8
time.c
8
time.c
@ -873,6 +873,8 @@ zone_str(const char *zone)
|
|||||||
{
|
{
|
||||||
const char *p;
|
const char *p;
|
||||||
int ascii_only = 1;
|
int ascii_only = 1;
|
||||||
|
VALUE str;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
if (zone == NULL) {
|
if (zone == NULL) {
|
||||||
return rb_fstring_usascii("(NO-TIMEZONE-ABBREVIATION)");
|
return rb_fstring_usascii("(NO-TIMEZONE-ABBREVIATION)");
|
||||||
@ -883,12 +885,14 @@ zone_str(const char *zone)
|
|||||||
ascii_only = 0;
|
ascii_only = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
len = p - zone + strlen(p);
|
||||||
if (ascii_only) {
|
if (ascii_only) {
|
||||||
return rb_fstring_usascii(zone);
|
str = rb_usascii_str_new(zone, len);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return rb_fstring_enc_cstr(zone, rb_locale_encoding());
|
str = rb_enc_str_new(zone, len, rb_locale_encoding());
|
||||||
}
|
}
|
||||||
|
return rb_fstring(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user