Re: [PATCH] fast-export: avoid NULL pointer arithmetic

2018-05-15 Thread René Scharfe
Am 14.05.2018 um 03:37 schrieb Junio C Hamano: > René Scharfe writes: > >> Storing integer values in pointers is a trick that seems to have worked >> so far for fast-export. A portable way to avoid that trick without >> requiring more memory would be to use a union. >> >> Or we

Re: [PATCH] fast-export: avoid NULL pointer arithmetic

2018-05-13 Thread Junio C Hamano
René Scharfe writes: > Storing integer values in pointers is a trick that seems to have worked > so far for fast-export. A portable way to avoid that trick without > requiring more memory would be to use a union. > > Or we could roll our own custom hash map, as I mused in an

Re: [PATCH] fast-export: avoid NULL pointer arithmetic

2018-05-12 Thread René Scharfe
Am 12.05.2018 um 10:45 schrieb René Scharfe: > Or we could roll our own custom hash map, as I mused in an earlier post. > That would duplicate quite a bit of code; are there reusable pieces > hidden within that could be extracted into common functions? At least it would allow us to save four

Re: [PATCH] fast-export: avoid NULL pointer arithmetic

2018-05-12 Thread René Scharfe
Am 11.05.2018 um 19:42 schrieb Jeff King: > On Fri, May 11, 2018 at 03:34:19PM +0200, Duy Nguyen wrote: > >> On Fri, May 11, 2018 at 03:11:46PM +0200, Duy Nguyen wrote: >>> Back to fast-export, can we just allocate a new int on heap and point >>> it there? Allocating small pieces becomes quite

Re: [PATCH] fast-export: avoid NULL pointer arithmetic

2018-05-11 Thread Jeff King
On Fri, May 11, 2018 at 03:34:19PM +0200, Duy Nguyen wrote: > On Fri, May 11, 2018 at 03:11:46PM +0200, Duy Nguyen wrote: > > Back to fast-export, can we just allocate a new int on heap and point > > it there? Allocating small pieces becomes quite cheap and fast with > > mem-pool.h and we can

Re: [PATCH] fast-export: avoid NULL pointer arithmetic

2018-05-11 Thread Duy Nguyen
On Fri, May 11, 2018 at 03:11:46PM +0200, Duy Nguyen wrote: > Back to fast-export, can we just allocate a new int on heap and point > it there? Allocating small pieces becomes quite cheap and fast with > mem-pool.h and we can avoid this storing integer in pointer business. Something like this

Re: [PATCH] fast-export: avoid NULL pointer arithmetic

2018-05-11 Thread Duy Nguyen
On Fri, May 11, 2018 at 10:56 AM, Jeff King wrote: > On Fri, May 11, 2018 at 08:19:59AM +0200, Duy Nguyen wrote: > >> On Fri, May 11, 2018 at 6:49 AM, Junio C Hamano wrote: >> > Junio C Hamano writes: >> > >> >> René Scharfe

Re: [PATCH] fast-export: avoid NULL pointer arithmetic

2018-05-11 Thread Jeff King
On Fri, May 11, 2018 at 08:19:59AM +0200, Duy Nguyen wrote: > On Fri, May 11, 2018 at 6:49 AM, Junio C Hamano wrote: > > Junio C Hamano writes: > > > >> René Scharfe writes: > >> > But it somehow feels backwards in spirit to me, as the

Re: [PATCH] fast-export: avoid NULL pointer arithmetic

2018-05-11 Thread Duy Nguyen
On Fri, May 11, 2018 at 6:49 AM, Junio C Hamano wrote: > Junio C Hamano writes: > >> René Scharfe writes: >> But it somehow feels backwards in spirit to me, as the reason why we use "void *" there in the decoration field is because

Re: [PATCH] fast-export: avoid NULL pointer arithmetic

2018-05-10 Thread Junio C Hamano
Junio C Hamano writes: > René Scharfe writes: > >>> But it somehow feels backwards in spirit to me, as the reason why we >>> use "void *" there in the decoration field is because we expect that >>> we'd have a pointer to some struture most of the time, and we

Re: [PATCH] fast-export: avoid NULL pointer arithmetic

2018-05-10 Thread Junio C Hamano
René Scharfe writes: >> But it somehow feels backwards in spirit to me, as the reason why we >> use "void *" there in the decoration field is because we expect that >> we'd have a pointer to some struture most of the time, and we have >> to occasionally store a small integer there.

Re: [PATCH] fast-export: avoid NULL pointer arithmetic

2018-05-10 Thread René Scharfe
Am 10.05.2018 um 12:51 schrieb Junio C Hamano: > René Scharfe writes: > >> The standard says about uintptr_t that "any valid pointer to void can >> be converted to this type, then converted back to pointer to void, and >> the result will compare equal to the original pointer". So

Re: [PATCH] fast-export: avoid NULL pointer arithmetic

2018-05-10 Thread Junio C Hamano
René Scharfe writes: > The standard says about uintptr_t that "any valid pointer to void can > be converted to this type, then converted back to pointer to void, and > the result will compare equal to the original pointer". So void * -> > uintptr_t -> void * is a proper roundtrip,

Re: [PATCH] fast-export: avoid NULL pointer arithmetic

2018-05-10 Thread René Scharfe
Am 09.05.2018 um 23:06 schrieb René Scharfe: > 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]

Re: [PATCH] fast-export: avoid NULL pointer arithmetic

2018-05-09 Thread Johannes Schindelin
Hi René, On Wed, 9 May 2018, René Scharfe wrote: > 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

[PATCH] fast-export: avoid NULL pointer arithmetic

2018-05-09 Thread René Scharfe
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;