Re: [PATCH 2/2] nedmalloc: work around overzealous GCC 6 warning

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



René Scharfe <l.s.r@xxxxxx> writes:

> This version of strdup() is only compiled if nedmalloc is used instead
> of the system allocator.  That means we can't rely on strdup() being
> able to take NULL -- some (most?) platforms won't like it.  Removing
> the NULL check would be a more general and overall easier way out, no?

The callers of this version must be prepared to call a version of
strdup() that does not accept NULL, so in a sense, passing NULL to
this function is already an error in the context of this project.

That sounds like a good rationale to take this more straight-forward
approach.

> But it should check the result of malloc() before copying.
> ---
>  compat/nedmalloc/nedmalloc.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/compat/nedmalloc/nedmalloc.c b/compat/nedmalloc/nedmalloc.c
> index a0a16eb..cc18f0c 100644
> --- a/compat/nedmalloc/nedmalloc.c
> +++ b/compat/nedmalloc/nedmalloc.c
> @@ -955,12 +955,10 @@ void **nedpindependent_comalloc(nedpool *p,
> size_t elems, size_t *sizes, void **
>   */
>  char *strdup(const char *s1)
>  {
> -	char *s2 = 0;
> -	if (s1) {
> -		size_t len = strlen(s1) + 1;
> -		s2 = malloc(len);
> +	size_t len = strlen(s1) + 1;
> +	char *s2 = malloc(len);
> +	if (s2)
>  		memcpy(s2, s1, len);
> -	}
>  	return s2;
>  }
>  #endif
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]