From: Alexandre Julliard Subject: Re: [PATCH] include: Add and use a global heap_strdupW() helper Message-Id: <87vaf1riir.fsf@winehq.org> Date: Mon, 12 Feb 2018 22:43:24 +0100 In-Reply-To: (Michael Stefaniuc's message of "Mon, 12 Feb 2018 21:28:27 +0100") References: <20180209204421.12241-1-mstefani@winehq.org> <87o9kuo6ac.fsf@winehq.org> Michael Stefaniuc writes: > On 02/12/2018 11:23 AM, Alexandre Julliard wrote: >> Michael Stefaniuc writes: >> >>> +static inline WCHAR *heap_strdupW(const WCHAR *str) >>> +{ >>> + WCHAR *dst; >>> + SIZE_T len; >>> + >>> + if(!str) >>> + return NULL; >>> + >>> + len = (lstrlenW(str) + 1) * sizeof(*str); >>> + dst = heap_alloc(len); >>> + if (dst) >>> + memcpy(dst, str, len); >>> + >>> + return dst; >>> +} >> >> I'm not sure the NULL check is a good idea. > And I disagree with your disagreement! > > I just sent in > [PATCH] wininet: Avoid passing NULL to heap_strdupW() > to show how ugly that would make the code. And that's the stuff that > just crashed due to the tests. > > If you want the NULL check removed for the other strdup variants, > especially the heap_strdupAW(), that would uglify the code even more as > that is used in a ton of A functions that just forward to the W functions. The current usage is clean only because we are not checking for allocation failure, but that's broken. If we add proper handling, then the NULL checks will be needed anyway. -- Alexandre Julliard julliard@winehq.org