Re: [PATCH] fast-export: avoid NULL pointer arithmetic
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- May 9, 2018, 21:43 UTC
- Message-ID
- <nycvar.QRO.7.76.6.1805091743080.77@tvgsbejvaqbjf.bet>
- In-Reply-To
- <d50a4d5d-3b99-453e-1b52-4e733453fb78@web.de>
Hi René,
On Wed, 9 May 2018, René Scharfe wrote:
Show 16 quoted lines
> Clang 6 reports the following warning, which is turned into an error in a > DEVELOPER build: > > builtin/fast-export.c:162:28: error: performing pointer arithmetic on a null pointer has undefined behavior [-Werror,-Wnull-pointer-arithmetic] > return ((uint32_t *)NULL) + mark; > ~~~~~~~~~~~~~~~~~~ ^ > 1 error generated. > > The compiler is correct, and the error message speaks for itself. There > is no need for any undefined operation -- just cast mark to void * or > uint32_t after an intermediate cast to uintptr_t. That encodes the > integer value into a pointer and later decodes it as intended. > > While at it remove an outdated comment -- intptr_t has been used since > ffe659f94d (parse-options: make some arguments optional, add callbacks), > committed in October 2007.
ACK.
Thanks, Dscho