kread() and NULL pointers

Mike Mason mmlnx@us.ibm.com
Tue Jul 17 18:05:00 GMT 2007


Stone, Joshua I wrote:
> Mike Mason wrote:
>> So should the following generate an error?  It doesn't.  It just 
>> prints "ptr = 0" and exits.
>>
>> function test_addr:long () %{
>>        void *nullptr = NULL;
>>        THIS->__retvalue = (long) kread(&(nullptr));
> -----------------------------------------^
> 
> You're reading the address *of* your pointer, not the address in the 
> pointer.  Thus kread() is dereferencing an address on the stack, and the 
> value there is NULL.  Drop the '&', and change nullptr to a type that's 
> meaningful to dereference (e.g., long*), and you'll get your error.

You're right.  I fell into the trap of assuming the kread parameter should always have a '&' in front.  Bad assumption on my part.

> 
> The "&(xxx)" pattern you see everywhere is because usually the "xxx" is 
> a struct value, and so you pass kread() a pointer to that value.

Yep, this is what fooled me.

Never mind :-)

Thanks,
Mike

> 
> 
> Josh



More information about the Systemtap mailing list