Date: Wed, 15 Mar 2017 21:55:04 -0700 From: "Ngie Cooper (yaneurabeya)" <yaneurabeya@gmail.com> To: Warner Losh <imp@bsdimp.com> Cc: Ngie Cooper <ngie@freebsd.org>, src-committers <src-committers@freebsd.org>, "svn-src-all@freebsd.org" <svn-src-all@freebsd.org>, "svn-src-head@freebsd.org" <svn-src-head@freebsd.org> Subject: Re: svn commit: r315360 - head/lib/libkvm Message-ID: <09597F88-6F43-4A9C-B89B-6B634928C7FC@gmail.com> In-Reply-To: <CANCZdfrV1XezigONuLb1gYOCPzJL_UiT=mb1gDRH%2BdcMofEwPA@mail.gmail.com> References: <201703160231.v2G2VgxK082641@repo.freebsd.org> <CANCZdfqgU8DJTdp4HkVxTU0PNpSGn45wJ0S1su=y2Td_uiVncA@mail.gmail.com> <58A53702-FFF6-45E7-ACCD-9B776530064E@gmail.com> <CANCZdfrV1XezigONuLb1gYOCPzJL_UiT=mb1gDRH%2BdcMofEwPA@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
[-- Attachment #1 --] > On Mar 15, 2017, at 21:53, Warner Losh <imp@bsdimp.com> wrote: > > On Wed, Mar 15, 2017 at 10:44 PM, Ngie Cooper (yaneurabeya) > <yaneurabeya@gmail.com> wrote: >> >>> On Mar 15, 2017, at 21:32, Warner Losh <imp@bsdimp.com> wrote: >>> >>> On Wed, Mar 15, 2017 at 8:31 PM, Ngie Cooper <ngie@freebsd.org> wrote: >>>> Author: ngie >>>> Date: Thu Mar 16 02:31:42 2017 >>>> New Revision: 315360 >>>> URL: https://svnweb.freebsd.org/changeset/base/315360 >>>> >>>> Log: >>>> Return NULL instead of 0 on failure in _kvm_open, kvm_open{,2,files} >>>> >>>> This is being done for the following reasons: >>>> - kvm_open(3), etc says they will return NULL. >>>> - NULL by definition is (void*)0 per POSIX, but can be redefined, >>>> depending on the compiler, etc. >>> >>> No, it can't. The C language requires all integral expressions that >>> evaluate to zero to convert to the NULL pointer. This is independent >>> of the internal representation of the NULL pointer. >>> >>> So this change is an NOP for all compilers. It's a good STYLE change. >> >> Someone made an argument a few weeks ago about NULL being definable as a non-zero value on some esoteric architectures or OSes. > > No. That's confused. NULL must always be 0. A conversion between 0 and > a pointer always must give a null-pointer. Always. You can't defined > NULL to -1 ever. Even if that happens to be the binary representation > of a NULL pointer, it must be 0. > >> I agree though, this is largely stylistic/pedantic for a good cause. If someone set NULL to something non-zero in value, they would be looking for pain :). > > You can never set NULL to non-zero integral value (possibly with a > cast). You can have the internal representation have non-zero bits, > but the compiler must hide that. > > This does mean that M_ZERO and calloc() won't set pointers to null > pointers on such architectures, but this 0 that you replaced is > completely safe. > > I can provide references to the appropriate standards. I made the same > point when someone made that (incorrect) argument. No worries — I’ll take your word :). Thanks :)! -Ngie [-- Attachment #2 --] -----BEGIN PGP SIGNATURE----- Comment: GPGTools - https://gpgtools.org iQIcBAEBCgAGBQJYyhqoAAoJEPWDqSZpMIYVfroP/A7TCDC5ls3ntSS+3uMzN04S Q+4F1clYkgBCz0/T3WHCRixz85qyLUtCK1OS+nTp/HKu8M4N7ffS4Dw49lj+wWt1 Hm+HcGSWmupgwDSSZKRvtTZDP5zOse3tYbC+KR4PmNFtC5kNk7t2dA35RFQU4KdZ dbNnfpPC1I4+YoZ5pwjwTKKnFy9Slm1zaeNPZWNqE+OsUX2DBZLRbrePXbJPx4mb QwmDKcjEcUduRURwtYzlhzMmd0nL6OcGInQmZecLbOQ3AAiLXr2HcxGctZoJbPLe mzrhJIE55m/foQisKruxNVD/UH3k9SuxfvNSQeJwiD6rISiQX+pC6Jyl+ukcEDNA 3qa+FxUE4LULS7OgXYBh+wwNtM1+VBC9LkXBC7fMlcO55iy+dOgREqg0HuumHfTZ RjAQG2CD61oJjwiR1YnrQ0/s5gstnbacCHyAjmFvsxSvtHtl11b9585s9eXGFu33 lOcSRttPLDyzamaT1AyogDxJd1pjr7q3e/fsbtDUfEIrsmVR36sh7hMNIrSIg9qt wXcSIO+/gaA1MePOPggidOw4suwVKXLh+OrsCSo0Z2RkxginNLeLx1e4Oxtu4V3Y 21DlTgSDzpBZ4EwoltYz0Hkx47h8m23YgrAyujSp7DStPTehzTzTpnOrynZHsqoX 7Qw1QlXgUudPcyPccP50 =yg0I -----END PGP SIGNATURE-----
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?09597F88-6F43-4A9C-B89B-6B634928C7FC>
