Referencing NULL pointers

Pavan Vohra vohra at uts.amdahl.com
Tue Jul 11 17:35:39 AEST 1989


In article <1891 at auspex.auspex.com> guy at auspex.auspex.com (Guy Harris) writes:
>>   Apparantly, on other machines this is perfectly valid, since I see
>>   quite a lot of this in code created on certain non-sun machines.
>
>No, it's not valid, it just happens to work - and only on *some* other

I would say that the code is valid.

Try a rewrite: "x= ((struct somestruct *)0)->somefield".

It can be convenient to make the first page (or whatever unit)
inaccessible to cause errors for structures that are smaller
than that unit.  Maybe Sunos does this.

It looks like in the case of UTS 1.2, at least our copy of it, the
above would not cause an error, but because the default magic
has the code segment read-only, "t->somefield" would probably
cause an error provided that the offset of somefield is small.

Anyway, it is the operating system that makes the action that the
process takes valid or invalid.

KC borrowing vohra.

-- 
---
Pavan Vohra             {..hplabs|ames|ihnp4|decwrl}!amdahl!vohra
Amdahl Corporation
Sunnyvale, CA 94086-3470
---



More information about the Comp.unix.wizards mailing list