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

Segmentation fault sprintf("%05b", -5) #3648

Closed
ksss opened this issue May 7, 2017 · 2 comments
Closed

Segmentation fault sprintf("%05b", -5) #3648

ksss opened this issue May 7, 2017 · 2 comments

Comments

@ksss
Copy link
Contributor

@ksss ksss commented May 7, 2017

mruby: ef30530

$ mruby -e 'sprintf("%0b", -5)'
#=> segmentation fault

build_config.rb

MRuby::Build.new('test') do |conf|
  toolchain :gcc
  enable_debug
  conf.gembox 'default'
end

lldb

frame #5: 0x00000001001aa208 mruby`mrb_str_format(mrb=0x000061400000a440, argc=2, argv=0x000061d00001d6a0, fmt=mrb_value @ 0x00007fff5fbf3120) at sprintf.c:987
   984
   985 	        if (v < 0) {
   986 	          char c = sign_bits(base, p);
-> 987 	          FILL(c, prec - len);
   988 	        }
   989 	        else if ((flags & (FMINUS|FPREC)) != FMINUS) {
   990 	          char c = '0';
(lldb) p prec
(mrb_int) $1 = -3
(lldb) p len
(mrb_int) $2 = 4

FILL(c, prec - len);

@ksss
Copy link
Contributor Author

@ksss ksss commented May 7, 2017

before #3645

$ mruby -e 'sprintf("%05b", -5)'
illegal specifier (ArgumentError)

@ksss
Copy link
Contributor Author

@ksss ksss commented May 8, 2017

expect:

$ ruby -e 'p sprintf("%05b", -5)'
"..1011"

@matz matz closed this as completed in #3649 May 8, 2017
matz added a commit that referenced this issue May 8, 2017
Fix segmentation fault ref: #3648
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

No branches or pull requests

1 participant