Projects

Ticket #249 (closed defect: fixed)

Opened 3 years ago

Last modified 2 years ago

Attempting to modify instances of NSString or NSArray causes crash

Reported by: jesper@… Owned by: lsansonetti@…
Priority: blocker Milestone: MacRuby 0.5
Component: MacRuby Keywords:
Cc: jesper@…

Description

Creating an instance of NSString or NSArray, and then attempting to modify it, causes a crash in MacRuby 0.4 (built from source, revision 1541):

$ macirb 
irb(main):001:0> str = NSString.stringWithString 'a'
=> "a"
irb(main):002:0> str << 'b'
(irb):2: [BUG] Bus Error
MacRuby version 0.4 (ruby 1.9.1) [universal-darwin9.5, x86_64]
$ macirb 
irb(main):001:0> arr = NSArray.arrayWithObject 'a'
=> ["a"]
irb(main):002:0> arr << 'b'
/Library/Frameworks/MacRuby.framework/Versions/0.4/usr/lib/ruby/1.9.1/irb.rb:302: [BUG] Segmentation fault
MacRuby version 0.4 (ruby 1.9.1) [universal-darwin9.5, x86_64]

(Yes, I know that NSString and NSArray are immutable types, but a bus error or segfault seems a bit harsh.)

Change History

Changed 3 years ago by jesper@…

  • cc jesper@… added

Cc Me!

Changed 3 years ago by lsansonetti@…

Thanks for the report, this is likely a bug in the YARV #<< optimization. We do check for mutability before doing any destructive operations.

$ macruby -e 's=NSString.string; s.strip!'
-e:1:in `strip!': can't modify immutable string (RuntimeError)
	from -e:1:in `<main>'

Also, I noticed that the check doesn't work for NSArray in 64-bit.

$ arch -i386 macruby -e "a = NSArray.array; a.clear"
-e:1:in `clear': can't modify frozen/immutable array (RuntimeError)
	from -e:1:in `<main>'
$ arch -x86_64 macruby -e "a = NSArray.array; a.clear"

Changed 2 years ago by lsansonetti@…

  • status changed from new to closed
  • resolution set to fixed
  • milestone set to MacRuby 0.5

Definitely fixed in trunk.

$ ./miniruby -e "str = NSString.stringWithString 'a'; str << 'b'"
can't modify frozen/immutable string (RuntimeError)
Note: See TracTickets for help on using tickets.