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

ruby-changes:32847

From: nobu <ko1@a...>
Date: Thu, 13 Feb 2014 15:43:25 +0900 (JST)
Subject: [ruby-changes:32847] nobu:r44926 (trunk): parse.y: attrset from junk ID

nobu	2014-02-13 15:43:18 +0900 (Thu, 13 Feb 2014)

  New Revision: 44926

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44926

  Log:
    parse.y: attrset from junk ID
    
    * parse.y (IDSET_ATTRSET_FOR_INTERN): fix off-by-one bug.
    * parse.y (rb_enc_symname_type): junk ID succeeded by '=' is also
      attrset ID.  [ruby-core:60668] [Bug #8756]

  Modified files:
    trunk/ChangeLog
    trunk/parse.y
    trunk/test/-ext-/symbol/test_type.rb
    trunk/test/ruby/test_struct.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 44925)
+++ ChangeLog	(revision 44926)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Feb 13 15:43:16 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* parse.y (IDSET_ATTRSET_FOR_INTERN): fix off-by-one bug.
+
+	* parse.y (rb_enc_symname_type): junk ID succeeded by '=' is also
+	  attrset ID.  [ruby-core:60668] [Bug #8756]
+
 Thu Feb 13 11:06:32 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* configure.in: check if pthread_setname_np is available.
Index: parse.y
===================================================================
--- parse.y	(revision 44925)
+++ parse.y	(revision 44926)
@@ -10222,7 +10222,7 @@ rb_enc_symname_p(const char *name, rb_en https://github.com/ruby/ruby/blob/trunk/parse.y#L10222
 }
 
 #define IDSET_ATTRSET_FOR_SYNTAX ((1U<<ID_LOCAL)|(1U<<ID_CONST))
-#define IDSET_ATTRSET_FOR_INTERN (~(~0U<<ID_SCOPE_MASK) & ~(1U<<ID_ATTRSET))
+#define IDSET_ATTRSET_FOR_INTERN (~(~0U<<(1<<ID_SCOPE_SHIFT)) & ~(1U<<ID_ATTRSET))
 
 static int
 rb_enc_symname_type(const char *name, long len, rb_encoding *enc, unsigned int allowed_attrset)
@@ -10309,7 +10309,8 @@ rb_enc_symname_type(const char *name, lo https://github.com/ruby/ruby/blob/trunk/parse.y#L10309
 	    if (type == ID_GLOBAL || type == ID_CLASS || type == ID_INSTANCE) return -1;
 	    type = ID_JUNK;
 	    ++m;
-	    break;
+	    if (m + 1 < e || *m != '=') break;
+	    /* fall through */
 	  case '=':
 	    if (!(allowed_attrset & (1U << type))) return -1;
 	    type = ID_ATTRSET;
Index: test/ruby/test_struct.rb
===================================================================
--- test/ruby/test_struct.rb	(revision 44925)
+++ test/ruby/test_struct.rb	(revision 44926)
@@ -289,6 +289,8 @@ module TestStruct https://github.com/ruby/ruby/blob/trunk/test/ruby/test_struct.rb#L289
     x = Object.new
     o = klass.new("test", x)
     assert_same(x, o.b?)
+    o.send("b?=", 42)
+    assert_equal(42, o.b?)
   end
 
   def test_bang_mark_in_member
@@ -296,6 +298,8 @@ module TestStruct https://github.com/ruby/ruby/blob/trunk/test/ruby/test_struct.rb#L298
     x = Object.new
     o = klass.new("test", x)
     assert_same(x, o.b!)
+    o.send("b!=", 42)
+    assert_equal(42, o.b!)
   end
 
   def test_setter_method_returns_value
Index: test/-ext-/symbol/test_type.rb
===================================================================
--- test/-ext-/symbol/test_type.rb	(revision 44925)
+++ test/-ext-/symbol/test_type.rb	(revision 44926)
@@ -115,6 +115,10 @@ module Test_Symbol https://github.com/ruby/ruby/blob/trunk/test/-ext-/symbol/test_type.rb#L115
       assert_equal(:"[foo]=", Bug::Symbol.attrset("[foo]"))
       assert_symtype(Bug::Symbol.attrset("[foo]"), :attrset?)
       assert_equal(:[]=, Bug::Symbol.attrset(:[]))
+      assert_symtype(Bug::Symbol.attrset("foo?="), :attrset?)
+      assert_equal(:"foo?=", Bug::Symbol.attrset(:foo?))
+      assert_symtype(Bug::Symbol.attrset("foo!="), :attrset?)
+      assert_equal(:"foo!=", Bug::Symbol.attrset(:foo!))
     end
   end
 end

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

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