[U-Boot] [PATCH v2 1/1] malloc: don't compare pointers to 0

Tom Rini trini at konsulko.com
Mon Nov 13 21:29:02 UTC 2017


On Mon, Nov 13, 2017 at 09:04:40PM +0100, Wolfgang Denk wrote:
> Dear Heinrich,
> 
> In message <20171110204634.20515-1-xypron.glpk at gmx.de> you wrote:
> > 0 is not a pointer. So do not compare pointers to 0.
> 
> Who says so?  0 can be the value of a pointer to a valid, existing
> address.  For example a large number of Power Architecture systems
> map the RAM beginning at physical address 0, so if you want to
> wrtite to the very first byte in memory your pointer value is 0.

I think you just proved the point here.  One can write clever code
knowing that on architecture X we can do trick Y (and hey, for well
commented assembly, go reasonably nuts!0.  But in C and as we get more
and better and easier to use static analysis tools we write clear and
consistent code.

> > Do not return 0 from functions with a pointer return
> > type.
> 
> Why?  It could be a valid value - or not.
> 
> > -				if (new_address == 0)
> > +				if (!new_address)
> 
> In which way is "new_address == 0" and "!new_address" different?

And yes, it's not going to change the generated code.

Really, the best argument for not changing anything in this file is that
it brings us further from upstream, and we've neither thrown that notion
out the window nor frequently re-synced with it.

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20171113/5ee5d169/attachment.sig>


More information about the U-Boot mailing list