From mboxrd@z Thu Jan 1 00:00:00 1970 Delivery-date: Fri, 14 Oct 2022 18:42:16 +0200 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by lore.white.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ojNlJ-008iET-8n for lore@lore.pengutronix.de; Fri, 14 Oct 2022 18:42:16 +0200 Received: from localhost ([127.0.0.1] helo=metis.ext.pengutronix.de) by metis.ext.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1ojNlF-0006Wi-5I; Fri, 14 Oct 2022 18:42:13 +0200 Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ojNlC-0006Gx-1I; Fri, 14 Oct 2022 18:42:10 +0200 Received: from [2a0a:edc0:0:1101:1d::28] (helo=dude02.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1ojNlB-001WUH-CA; Fri, 14 Oct 2022 18:42:09 +0200 Received: from mfe by dude02.red.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1ojNl8-00Fzpj-Q8; Fri, 14 Oct 2022 18:42:06 +0200 From: Marco Felsch To: oss-tools@pengutronix.de Date: Fri, 14 Oct 2022 18:42:01 +0200 Message-Id: <20221014164204.3812506-12-m.felsch@pengutronix.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221014164204.3812506-1-m.felsch@pengutronix.de> References: <20221014164204.3812506-1-m.felsch@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [OSS-Tools] [PATCH dt-utils 11/14] common: xstrdup: don't panic on xstrdup(NULL) X-BeenThere: oss-tools@pengutronix.de X-Mailman-Version: 2.1.29 Precedence: list List-Id: Pengutronix Public Open-Source-Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mfe@pengutronix.de Sender: "OSS-Tools" X-SA-Exim-Connect-IP: 127.0.0.1 X-SA-Exim-Mail-From: oss-tools-bounces@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false This ports the following barebox commit | commit bf6ddd6c4dccf01c4a27761c5f73918db578f8d6 | Author: Uwe Kleine-König | 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 | Signed-off-by: Sascha Hauer It is required to have the same logic for the code shared with barebox. Signed-off-by: Marco Felsch --- 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