Hi Michael,

Michael McConville wrote on Thu, Nov 05, 2015 at 09:09:51PM -0500:

> Apparently the programmer didn't know that you could pass it NULL.
> However, including the function name seems more informative.

For malloc failure, including a function name is not necessary
because the message

  netgroup_mkdb: Cannot allocate memory

is already completely clear, and it doesn't matter whether it was
malloc or realloc or calloc that failed.  Citing a private function
name like "emalloc" is potentially confusing because the user might
wonder whether the fact that a non-standard function failed might
somehow be relevant to the problem, which it is not.

So just err(1, NULL) seem to be best here, and after malloc
failure in general.

Yours,
  Ingo


> Index: usr.sbin/netgroup_mkdb/util.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/netgroup_mkdb/util.c,v
> retrieving revision 1.6
> diff -u -p -r1.6 util.c
> --- usr.sbin/netgroup_mkdb/util.c     4 Mar 2012 04:05:15 -0000       1.6
> +++ usr.sbin/netgroup_mkdb/util.c     6 Nov 2015 02:01:24 -0000
> @@ -43,7 +43,7 @@ emalloc(size_t s)
>  {
>       void *ptr = malloc(s);
>       if (ptr == NULL)
> -             err(1, "%s", "");
> +             err(1, "emalloc");
>       return ptr;
>  }
>  
> @@ -56,7 +56,7 @@ erealloc(void *p, size_t s)
>  {
>       void *ptr = realloc(p, s);
>       if (ptr == NULL)
> -             err(1, "%s", "");
> +             err(1, "emalloc");
>       return ptr;
>  }

  • err(3) trivia Michael McConville
    • Re: err(3) trivia Ingo Schwarze

Reply via email to