mailarchive of the pengutronix oss-tools mailing list
 help / color / mirror / Atom feed
From: Marco Felsch <[email protected]>
To: [email protected]
Cc: [email protected]
Subject: [OSS-Tools] [PATCH dt-utils 11/14] common: xstrdup: don't panic on xstrdup(NULL)
Date: Fri, 14 Oct 2022 18:42:01 +0200	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

This ports the following barebox commit

| commit bf6ddd6c4dccf01c4a27761c5f73918db578f8d6
| Author: Uwe Kleine-König <[email protected]>
| 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 <[email protected]>
|     Signed-off-by: Sascha Hauer <[email protected]>

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

Signed-off-by: Marco Felsch <[email protected]>
---
 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




  parent reply	other threads:[~2022-10-14 16:42 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-14 16:41 [OSS-Tools] [PATCH dt-utils 00/14] Sync Barebox-State code base Marco Felsch
2022-10-14 16:41 ` [OSS-Tools] [PATCH dt-utils 01/14] state: Remove duplicate incudes Marco Felsch
2022-10-14 16:41 ` [OSS-Tools] [PATCH dt-utils 02/14] state: backend_raw: fix ignoring unpack failures Marco Felsch
2022-10-14 16:41 ` [OSS-Tools] [PATCH dt-utils 03/14] state: backend_storage: deal gracefully with runtime bucket corruption Marco Felsch
2022-10-14 16:41 ` [OSS-Tools] [PATCH dt-utils 04/14] state: treat state with all-invalid buckets as dirty Marco Felsch
2022-10-14 16:41 ` [OSS-Tools] [PATCH dt-utils 05/14] state: remove param member from struct state_string Marco Felsch
2022-10-14 16:41 ` [OSS-Tools] [PATCH dt-utils 06/14] state: remove param member from state_uint32, state_enum32, state_mac Marco Felsch
2022-10-14 16:41 ` [OSS-Tools] [PATCH dt-utils 07/14] state: remove unused function Marco Felsch
2022-10-14 16:41 ` [OSS-Tools] [PATCH dt-utils 08/14] state: propagate failure to fixup enum32 into DT Marco Felsch
2022-10-14 16:41 ` [OSS-Tools] [PATCH dt-utils 09/14] state: add SPDX-License-Identifier for files without explicit license Marco Felsch
2022-10-14 16:42 ` [OSS-Tools] [PATCH dt-utils 10/14] state: fix typos found with codespell Marco Felsch
2022-10-14 16:42 ` Marco Felsch [this message]
2022-10-14 16:42 ` [OSS-Tools] [PATCH dt-utils 12/14] libdt: add of_property_write_strings support Marco Felsch
2022-10-14 16:42 ` [OSS-Tools] [PATCH dt-utils 13/14] libdt: add partition search function Marco Felsch
2022-10-14 16:42 ` [OSS-Tools] [PATCH dt-utils 14/14] state: sync with barebox to support new backend type Marco Felsch
2022-10-21  7:37 ` [OSS-Tools] [PATCH dt-utils 00/14] Sync Barebox-State code base Marco Felsch
2023-06-05 13:12 ` Ahmad Fatoum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
OSZAR »