Hi Rasmus, et. al.

On Tue, 2026-04-21 at 09:54 +0200, Rasmus Villemoes wrote:
> With the addition of memdup_nul(), strdup() and strndup() can be
> implemented as one-liners.
> 
> While not required by POSIX or C, do keep the behaviour of gracefully
> accepting a NULL source and simply return NULL.

I bisected this commit to regress on the LicheePi 4A in the sense that the SPL 
is no longer able to
load/execute OpenSBI/U-Boot proper:

U-Boot SPL 2026.10 (Oct 10 2026 - 21:45:55 +0200)
Trying to boot from RAM
=> hangs

My fix reverting this and a second patch [1] got accepted in meta-riscv, see:

https://github.com/riscv/meta-riscv/pull/711

Before I dig deeper, I would welcome any insight anybody could have. Thanks!

Cheers

Marcel

[1] 
https://lore.kernel.org/all/[email protected]

> Reviewed-by: Simon Glass <[email protected]>
> Signed-off-by: Rasmus Villemoes <[email protected]>
> ---
>  lib/string.c | 30 ++----------------------------
>  1 file changed, 2 insertions(+), 28 deletions(-)
> 
> diff --git a/lib/string.c b/lib/string.c
> index 3923cce5561..5ccd1011ab5 100644
> --- a/lib/string.c
> +++ b/lib/string.c
> @@ -360,38 +360,12 @@ void *memdup_nul(const void *src, size_t len)
>  
>  char * strdup(const char *s)
>  {
> -     char *new;
> -
> -     if ((s == NULL) ||
> -         ((new = malloc (strlen(s) + 1)) == NULL) ) {
> -             return NULL;
> -     }
> -
> -     strcpy (new, s);
> -     return new;
> +     return s ? memdup_nul(s, strlen(s)) : NULL;
>  }
>  
>  char * strndup(const char *s, size_t n)
>  {
> -     size_t len;
> -     char *new;
> -
> -     if (s == NULL)
> -             return NULL;
> -
> -     len = strlen(s);
> -
> -     if (n < len)
> -             len = n;
> -
> -     new = malloc(len + 1);
> -     if (new == NULL)
> -             return NULL;
> -
> -     strncpy(new, s, len);
> -     new[len] = '\0';
> -
> -     return new;
> +     return s ? memdup_nul(s, strnlen(s, n)) : NULL;
>  }
>  
>  #ifndef __HAVE_ARCH_STRSPN

Reply via email to