This ports the following barebox commit

| commit bf6ddd6c4dccf01c4a27761c5f73918db578f8d6
| Author: Uwe Kleine-König <u.kleine-koe...@pengutronix.de>
| Date:   Fri Sep 9 08:37:22 2016 +0200
|
|     xstrdup: don't panic on xstrdup(NULL)
|
|     Instead return just NULL. This matches the behaviour of kstrdup in the
|     kernel and xstrdup in busybox.
|
|     This fixes a panic with CONFIG_CMD_MAGICVAR=y and
|     CONFIG_CMD_MAGICVAR_HELP unset in magicvar_add() where description is
|     always NULL.
|
|     Signed-off-by: Uwe Kleine-König <u.kleine-koe...@pengutronix.de>
|     Signed-off-by: Sascha Hauer <s.ha...@pengutronix.de>

It is required to have the same logic for the code shared with barebox.

Signed-off-by: Marco Felsch <m.fel...@pengutronix.de>
---
 src/dt/common.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/dt/common.h b/src/dt/common.h
index c3c4f53..9b1c169 100644
--- a/src/dt/common.h
+++ b/src/dt/common.h
@@ -209,8 +209,12 @@ static inline char * safe_strncpy(char *dst, const char 
*src, size_t size)
 
 static inline char *xstrdup(const char *s)
 {
-       char *p = strdup(s);
+       char *p;
+
+       if (!s)
+               return NULL;
 
+       p = strdup(s);
        if (!p)
                exit(EXIT_FAILURE);
 
-- 
2.30.2


Reply via email to