[前][次][番号順一覧][スレッド一覧]

ruby-changes:52823

From: nobu <ko1@a...>
Date: Sat, 13 Oct 2018 00:48:12 +0900 (JST)
Subject: [ruby-changes:52823] nobu:r65035 (trunk): Fix overwritten zone string

nobu	2018-10-13 00:48:06 +0900 (Sat, 13 Oct 2018)

  New Revision: 65035

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=65035

  Log:
    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.

  Modified files:
    trunk/time.c
Index: time.c
===================================================================
--- time.c	(revision 65034)
+++ time.c	(revision 65035)
@@ -873,6 +873,8 @@ zone_str(const char *zone) https://github.com/ruby/ruby/blob/trunk/time.c#L873
 {
     const char *p;
     int ascii_only = 1;
+    VALUE str;
+    size_t len;
 
     if (zone == NULL) {
         return rb_fstring_usascii("(NO-TIMEZONE-ABBREVIATION)");
@@ -883,12 +885,14 @@ zone_str(const char *zone) https://github.com/ruby/ruby/blob/trunk/time.c#L885
             ascii_only = 0;
             break;
         }
+    len = p - zone + strlen(p);
     if (ascii_only) {
-        return rb_fstring_usascii(zone);
+        str = rb_usascii_str_new(zone, len);
     }
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]