I faced segfault on Docker ruby:2.3.3 (Debian Linux) env, but it does not reproduce on OS X.
After investigation, I found that there is compiler-level difference between them.
When buffer(nil) is called, this library raises TypeError from StringValuePtr(nil) call at below code, with llvm (OS X).
# gcc --version
gcc (Debian 4.9.2-10) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# gcc test.c
# ./a.out
3, 4
3
I faced segfault on Docker
ruby:2.3.3
(Debian Linux) env, but it does not reproduce on OS X. After investigation, I found that there is compiler-level difference between them.When
buffer(nil)
is called, this library raisesTypeError
fromStringValuePtr(nil)
call at below code, with llvm (OS X).But with GNU gcc,
RSTRING_LEN(nil)
is evaluated first and causes SEGV.Evaluation order of args is unspecified by C language specification, so it is expected behavior. http://en.cppreference.com/w/c/language/eval_order
This PR fixes it by calling explicitly calling
StringValuePtr()
beforeRSTRING_LEN()
.(Below library passed nil to buffer(), so I also PR is sent to fix
TypeError
itself :) https://github.com/janko-m/shrine/pull/171Reproduction environment (for args order)
Test code:
OS X (llvm)
First one is evaluated first.
Linux (gcc)
Second one is evaluated first...