common/utils: add tal_strdup_or_null helper.

It's not that uncommon to want to pass NULL through, for optional strings.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2023-07-22 16:42:57 +09:30
parent b6d347a6d3
commit 981d82c406
7 changed files with 22 additions and 34 deletions

View File

@@ -262,10 +262,7 @@ bool plugin_hook_call_(struct lightningd *ld, const struct plugin_hook *hook,
ph_req->cb_arg = tal_steal(ph_req, cb_arg);
ph_req->db = ld->wallet->db;
ph_req->ld = ld;
if (cmd_id)
ph_req->cmd_id = tal_strdup(ph_req, cmd_id);
else
ph_req->cmd_id = NULL;
ph_req->cmd_id = tal_strdup_or_null(ph_req, cmd_id);
list_head_init(&ph_req->call_chain);
for (size_t i=0; i<tal_count(hook->hooks); i++) {