[#8815] Segfault in libc strlen, via rb_str_new2 — "Sean E. Russell" <ser@...>

Howdy,

12 messages 2006/09/09
[#8817] Re: Segfault in libc strlen, via rb_str_new2 — Eric Hodel <drbrain@...7.net> 2006/09/09

On Sep 8, 2006, at 10:10 PM, Sean E. Russell wrote:

Re: Segfault in libc strlen, via rb_str_new2

From: Marc Haisenko <haisenko@...>
Date: 2006-09-15 15:52:35 UTC
List: ruby-core #8881
On Friday 15 September 2006 16:46, Vincent Fourmond wrote:
> > One is NEVER allowed to assume that a pointer can be stored in an 
> > arithmetic  
> > value, e.g. it's possible that on some architecture arithmetic values are 
> > 32  
> > bit and pointers are 36 bit (IIRC there is an architecture where this is 
> > really true).
> 
>   Unless maybe in when compiling some extension for ruby ?
> 
> ruby.h: (at least in version 1.8.4)
> 
> #if SIZEOF_LONG != SIZEOF_VOIDP
> # error ---->> ruby requires sizeof(void*) == sizeof(long) to be
> compiled. <<----
> 
> 	Vince

The fact that people do this stuff doesn't mean it's correct to do so.

At least someone knew that this is dangerous and added a check so when Ruby 
gets compiled on an architecture where pointers and arithmetic values are of 
different size (AFAIK that boils down to the address registers being of 
different size than "normal" registers) you get a meaningful error instead of 
obscure crashes :-)

I guess the assumption that sizeof(void*) == sizeof(long) is correct on most 
hardware plattforms that float around today, but there's just no guarantee 
that it's true for ALL plattforms. When writing portable software you have to 
keep stuff like this in mind (or at least add checks ;-)

-- 
Marc Haisenko
Comdasys AG

Resheimer Stra゜e 7
D-80686 Mchen
Tel: +49 (0)89 - 548 43 33 21
Fax: +49 (0)89 - 548 43 33 29
e-mail: haisenko@comdasys.com
http://www.comdasys.com

In This Thread