From: Bill Lear Date: Tue, 26 Jan 2010 20:37:48 GMT Subject: Re: [PATCH 1/4] Add xmallocz() Message-ID: <19295.21148.182245.516321@blake.zopyra.com> In-Reply-To: <1264530255-4682-2-git-send-email-ilari.liusvaara@elisanet.fi> On Tuesday, January 26, 2010 at 20:24:12 (+0200) Ilari Liusvaara writes: >Add routine for allocating NUL-terminated memory block without risking >integer overflow in addition of +1 for NUL byte. >... > void *xmemdupz(const void *data, size_t len) > { >- char *p = xmalloc(len + 1); >+ char *p = xmallocz(len); > memcpy(p, data, len); > p[len] = '\0'; > return p; Do you need the statement p[len] = '\0'; any longer in the above? If not, could you just do this: void *xmemdupz(const void *data, size_t len) { return memcpy(xmallocz(len), data, len); } ?? Bill