Re: Linux "NULL pointer dereferece" in the News...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 07/19/09 22:19, quoth Joel Rees:
> Woops. Didn't intend to mess threading up that much.
> 
>> (Apologies for messing up the threading yet one more time, and for
>> cluttering up the fedora thread with more stuff that is only
>> semi-relevant here.)
> 
> 
> Would it be entirely inappropriate to have a compiler switch that would
> cause the compiler to issue warnings when pointers are used without testing
> after being returned from functions calls?

I would have to say that that is inappropriate. As far as what the compiler
sees is

ptr = fn();

IOW, a value was computed by some function and was stored in ptr. Period. If
ptr had not been previously assigned to, then it is now. If the value that was
returned is not to your liking then you as the programmer are required to
check it. What should you check it for? I'm glad you asked. I once worked on a
machine where testing for NULL was never the right thing to do. Instead, you
had to check to see if the address that was returned was within the partcular
of eight segments of memory that you were executing from AND that if it was a
data access then it was allowed to be in an area of memory that was in a
segment that was greater than the one that you were in, but if it was a
pointer to a function that it could only be in a segment that was equal to or
lower than the current segment. Store out == good. Store in == BAD. Call in ==
GOOD. Call out == BAD.

And, I might add, a function that needs to have its return value checked is
not a big thing to implement.

People do bad things with pointers all the time. Take a look at fclose, just
as a simple example:

int fclose(FILE *fp);

It returns a status code in it's return value. No problem. But! if they would
have taken that extra step

int fclose(FILE **fp);
so that it gets called a la

int status;
status = fclose(&fp);

then fclose could have set the value of fp to NULL if the fclose was
successful and then the first shlub to try to access the descriptor, even
after the file was closed, would more likely get his segfault. The earlier the
better I always say.

So, yes, I would say it is inappropriate.

- --
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.10 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iEYEARECAAYFAkpj5gcACgkQRIVy4fC+NyRE2QCcC2P1wL/BkShgx/1tXBl7gR0b
FcgAn1Tadjt/iT8Ah08MGinRLrhrTg+5
=TJH9
-----END PGP SIGNATURE-----

-- 
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines

[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux