This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: kread() and NULL pointers


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]