Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#7] Convert to Float before rounding; avoid a segfault #15

Merged
merged 1 commit into from
Sep 19, 2013

Conversation

bf4
Copy link
Contributor

@bf4 bf4 commented Sep 18, 2013

For a covered percent of the Rational 800/22 see #7

(800/22).round(2)  #=> segfault
Float(800/22).round(2) #=> 36.36

Found it by reading the stacktrace and using a debugger

Coverage = 67.5%.projekt/.rvm/gems/ruby-1.9.3-p448@projekt/gems/codeclimate-test-reporter-0.0.9/lib/code_climate/test_reporter/formatter.rb:49: [BUG] Segmentation fault
ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-darwin12.4.0]

-- Control frame information -----------------------------------------------
c:0013 p:---- s:0056 b:0056 l:000055 d:000055 CFUNC  :round
c:0012 p:0198 s:0052 b:0043 l:000034 d:000042 BLOCK  projekt/.rvm/gems/ruby-1.9.3-p448@projekt/gems/codeclimate-test-reporter-0.0.9/lib/code_climate/test_reporter/forma
c:0011 p:---- s:0040 b:0040 l:000039 d:000039 FINISH
c:0010 p:---- s:0038 b:0038 l:000037 d:000037 CFUNC  :map
c:0009 p:0037 s:0035 b:0035 l:000034 d:000034 METHOD projekt/.rvm/gems/ruby-1.9.3-p448@projekt/gems/codeclimate-test-reporter-0.0.9/lib/code_climate/test_reporter/forma
c:0008 p:0046 s:0029 b:0029 l:000028 d:000028 METHOD projekt/.rvm/gems/ruby-1.9.3-p448@projekt/gems/codeclimate-test-reporter-0.0.9/lib/code_climate/test_reporter/forma
c:0007 p:0030 s:0020 b:0020 l:000019 d:000019 METHOD projekt/.rvm/gems/ruby-1.9.3-p448@projekt/gems/simplecov-0.7.1/lib/simplecov/result.rb:91
c:0006 p:0021 s:0017 b:0017 l:0017b0 d:000016 BLOCK  projekt/.rvm/gems/ruby-1.9.3-p448@projekt/gems/simplecov-0.7.1/lib/simplecov/configuration.rb:133
c:0005 p:---- s:0015 b:0015 l:000014 d:000014 FINISH
c:0004 p:---- s:0013 b:0013 l:000012 d:000012 CFUNC  :call
c:0003 p:0070 s:0010 b:0010 l:001a70 d:000009 BLOCK  projekt/.rvm/gems/ruby-1.9.3-p448@projekt/gems/simplecov-0.7.1/lib/simplecov/defaults.rb:52
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
c:0001 p:0000 s:0002 b:0002 l:000008 d:000008 TOP   

-- Ruby level backtrace information ----------------------------------------
projekt/.rvm/gems/ruby-1.9.3-p448@projekt/gems/simplecov-0.7.1/lib/simplecov/defaults.rb:52:in `block in <top (required)>'
projekt/.rvm/gems/ruby-1.9.3-p448@projekt/gems/simplecov-0.7.1/lib/simplecov/defaults.rb:52:in `call'
projekt/.rvm/gems/ruby-1.9.3-p448@projekt/gems/simplecov-0.7.1/lib/simplecov/configuration.rb:133:in `block in at_exit'
projekt/.rvm/gems/ruby-1.9.3-p448@projekt/gems/simplecov-0.7.1/lib/simplecov/result.rb:91:in `format!'
projekt/.rvm/gems/ruby-1.9.3-p448@projekt/gems/codeclimate-test-reporter-0.0.9/lib/code_climate/test_reporter/formatter.rb:14:in `format'
projekt/.rvm/gems/ruby-1.9.3-p448@projekt/gems/codeclimate-test-reporter-0.0.9/lib/code_climate/test_reporter/formatter.rb:39:in `to_payload'
projekt/.rvm/gems/ruby-1.9.3-p448@projekt/gems/codeclimate-test-reporter-0.0.9/lib/code_climate/test_reporter/formatter.rb:39:in `map'
projekt/.rvm/gems/ruby-1.9.3-p448@projekt/gems/codeclimate-test-reporter-0.0.9/lib/code_climate/test_reporter/formatter.rb:49:in `block in to_payload'
projekt/.rvm/gems/ruby-1.9.3-p448@projekt/gems/codeclimate-test-reporter-0.0.9/lib/code_climate/test_reporter/formatter.rb:49:in `round'
``

@bf4 bf4 mentioned this pull request Sep 18, 2013
@bf4
Copy link
Contributor Author

bf4 commented Sep 18, 2013

Feel free to remove trailing whitespace. I'm doing this via the web UI. Also, the commit description and included comment mention the wrong issue number.

For a covered percent of Rational(200/10)
covered_percent = Marshal.load("\x04\bU:\rRational[\ai\x01\xC8i\x0F")
covered_percent.round(2) => segfault
Float(covered_percent).round(2) => 20.0

The segfault depends on as yet unknown gems to be required
@bf4
Copy link
Contributor Author

bf4 commented Sep 18, 2013

Rebased off master, fixed a missing rounding case per @noahd1, removed trailing white space, force pushed.

@noahd1 noahd1 merged commit 866ac24 into codeclimate:master Sep 19, 2013
@bf4
Copy link
Contributor Author

bf4 commented Sep 19, 2013

In the meantime, I think I found the bug, 'mathn/rational', though I'm not entirely sure which library was requiring it. Something in my spec_helper. Do you know anything about reporting a bug to ruby?

covered_percent = Marshal.load("\x04\bU:\rRational[\ai\x01\xC8i\x0F")
# or require 'yaml'; covered_percent = YAML.load("--- !ruby/object:Rational\ndenominator: 10\nnumerator: 200\n")
covered_percent.round(2) # => (20/1)
require 'mathn/rational'
covered_percent.round(2) # => segfault

@bf4 bf4 deleted the fix_segfault_round_on_rational branch September 19, 2013 03:56
@bf4
Copy link
Contributor Author

bf4 commented Sep 19, 2013

Found related issue in simplecov simplecov-ruby/simplecov#140 / simplecov-ruby/simplecov#175

@noahd1
Copy link
Contributor

noahd1 commented Sep 19, 2013

Thanks Ben. I merged it because it basically for the same reason they did in simplecov-ruby/simplecov#175

@bf4
Copy link
Contributor Author

bf4 commented Sep 19, 2013

@noahd1 I actually created an issue in MRI but apparently this was very recently fixed and backported to 1.9.3 and 2.0.0.

@noahd1
Copy link
Contributor

noahd1 commented Sep 19, 2013

Awesome Ben. Thanks for digging into this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants