[PATCH] xstrdup: don't panic on xstrdup(NULL)

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

 



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-koenig@xxxxxxxxxxxxxx>
---
 lib/xfuncs.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lib/xfuncs.c b/lib/xfuncs.c
index aaf078854429..1dc2ea92d84f 100644
--- a/lib/xfuncs.c
+++ b/lib/xfuncs.c
@@ -56,10 +56,15 @@ EXPORT_SYMBOL(xzalloc);
 
 char *xstrdup(const char *s)
 {
-	char *p = strdup(s);
+	char *p;
+
+	if (!s)
+		return NULL;
 
+	p = strdup(s);
 	if (!p)
 		panic("ERROR: out of memory\n");
+
 	return p;
 }
 EXPORT_SYMBOL(xstrdup);
-- 
2.8.1


_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox




[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux