Re: [patch] spamd-setup.c
On 03/07/18 18:55, William Ahern wrote: On Wed, Mar 07, 2018 at 05:17:59PM -0600, Edgar Pettijohn wrote: This looks like a good place for reallocarray. Yes? Index: spamd-setup.c === RCS file: /cvs/src/libexec/spamd-setup/spamd-setup.c,v retrieving revision 1.50 diff -u -p -u -r1.50 spamd-setup.c --- spamd-setup.c7 Jul 2017 00:10:15 -1.50 +++ spamd-setup.c7 Mar 2018 23:14:00 - @@ -363,7 +363,7 @@ fix_quoted_colons(char *buf) char *newbuf, last; /* Allocate enough space for a buf of all colons (impossible). */ -newbuf = malloc(2 * strlen(buf) + 1); +newbuf = reallocarray(NULL, 2, strlen(buf) + 1); if (newbuf == NULL) return (NULL); last = '\0'; FWIW, the old code evaluates as (2 * strlen(buf)) + 1 but the new code evaluates as 2 * (strlen(buf) + 1) Those pesky parenthesis. I guess I could argue that the benefits of reallocarray() outweigh the wasted memory. However, that is probably why it hasn't been changed already.
Re: [patch] spamd-setup.c
On Wed, Mar 07, 2018 at 05:17:59PM -0600, Edgar Pettijohn wrote: > This looks like a good place for reallocarray. Yes? > > Index: spamd-setup.c > === > RCS file: /cvs/src/libexec/spamd-setup/spamd-setup.c,v > retrieving revision 1.50 > diff -u -p -u -r1.50 spamd-setup.c > --- spamd-setup.c7 Jul 2017 00:10:15 -1.50 > +++ spamd-setup.c7 Mar 2018 23:14:00 - > @@ -363,7 +363,7 @@ fix_quoted_colons(char *buf) > char *newbuf, last; > > /* Allocate enough space for a buf of all colons (impossible). */ > -newbuf = malloc(2 * strlen(buf) + 1); > +newbuf = reallocarray(NULL, 2, strlen(buf) + 1); > if (newbuf == NULL) > return (NULL); > last = '\0'; FWIW, the old code evaluates as (2 * strlen(buf)) + 1 but the new code evaluates as 2 * (strlen(buf) + 1)
[patch] spamd-setup.c
This looks like a good place for reallocarray. Yes? Index: spamd-setup.c === RCS file: /cvs/src/libexec/spamd-setup/spamd-setup.c,v retrieving revision 1.50 diff -u -p -u -r1.50 spamd-setup.c --- spamd-setup.c7 Jul 2017 00:10:15 -1.50 +++ spamd-setup.c7 Mar 2018 23:14:00 - @@ -363,7 +363,7 @@ fix_quoted_colons(char *buf) char *newbuf, last; /* Allocate enough space for a buf of all colons (impossible). */ -newbuf = malloc(2 * strlen(buf) + 1); +newbuf = reallocarray(NULL, 2, strlen(buf) + 1); if (newbuf == NULL) return (NULL); last = '\0';