> Am 28.10.2015 um 17:05 schrieb Michael McConville <mm...@mykolab.com>:
> 
> Relayd, httpd, and ntpd define the functions get_data() and
> get_string(). Both call calloc and then immediately memcpy. Calloc's
> zeroing isn't optimized out. These functions are called in network data
> paths in at least a couple places, so all this extra writing could have
> a meaningful performance impact.

I think this impact is negligible small and I believe
that you can not even measure it.
So this change makes not so much sense to me.

I wonder if using strndup() would make more 
sense for the first case here?

> ok?
> 
> 
> Index: relayd.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/relayd/relayd.c,v
> retrieving revision 1.144
> diff -u -p -r1.144 relayd.c
> --- relayd.c    14 Oct 2015 07:58:14 -0000    1.144
> +++ relayd.c    28 Oct 2015 15:57:16 -0000
> @@ -1501,9 +1501,10 @@ get_string(u_int8_t *ptr, size_t len)
>            isspace((unsigned char)ptr[i])))
>            break;
> 
> -    if ((str = calloc(1, i + 1)) == NULL)
> +    if ((str = malloc(i + 1)) == NULL)
>        return (NULL);
>    memcpy(str, ptr, i);
> +    str[i] = '\0';
> 
>    return (str);
> }
> @@ -1513,7 +1514,7 @@ get_data(u_int8_t *ptr, size_t len)
> {
>    u_int8_t    *data;
> 
> -    if ((data = calloc(1, len)) == NULL)
> +    if ((data = malloc(len)) == NULL)
>        return (NULL);
>    memcpy(data, ptr, len);
> 
> 

Reply via email to