From 19d13f17813b35c4cc426bdf2244ef460974e0d9 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 18 Feb 2019 13:13:29 +1030 Subject: [PATCH] type_to_string: return const char *. Always be const if you can. Signed-off-by: Rusty Russell --- common/type_to_string.c | 6 +++--- common/type_to_string.h | 14 +++++++------- lightningd/channel.c | 2 +- lightningd/opening_control.c | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/common/type_to_string.c b/common/type_to_string.c index 13afd7ee9..25d5c3ef3 100644 --- a/common/type_to_string.c +++ b/common/type_to_string.c @@ -13,10 +13,10 @@ REGISTER_TYPE_TO_HEXSTR(ripemd160); /* This one in bitcoin/ but doesn't have its own C file */ REGISTER_TYPE_TO_HEXSTR(preimage); -char *type_to_string_(const tal_t *ctx, const char *typename, - union printable_types u) +const char *type_to_string_(const tal_t *ctx, const char *typename, + union printable_types u) { - char *s = NULL; + const char *s = NULL; size_t i; static size_t num_p; static struct type_to_string **t = NULL; diff --git a/common/type_to_string.h b/common/type_to_string.h index 521a1f931..45a5e125b 100644 --- a/common/type_to_string.h +++ b/common/type_to_string.h @@ -38,12 +38,12 @@ union printable_types { ((void)sizeof((ptr) == (type *)NULL), \ ((union printable_types)((const type *)ptr)))) -char *type_to_string_(const tal_t *ctx, const char *typename, - union printable_types u); +const char *type_to_string_(const tal_t *ctx, const char *typename, + union printable_types u); #define REGISTER_TYPE_TO_STRING(typename, fmtfn) \ - static char *fmt_##typename##_(const tal_t *ctx, \ - union printable_types u) \ + static const char *fmt_##typename##_(const tal_t *ctx, \ + union printable_types u) \ { \ return fmtfn(ctx, u.typename); \ } \ @@ -53,8 +53,8 @@ char *type_to_string_(const tal_t *ctx, const char *typename, AUTODATA(type_to_string, &ttos_##typename) #define REGISTER_TYPE_TO_HEXSTR(typename) \ - static char *fmt_##typename##_(const tal_t *ctx, \ - union printable_types u) \ + static const char *fmt_##typename##_(const tal_t *ctx, \ + union printable_types u) \ { \ return tal_hexstr(ctx, u.typename, sizeof(*u.typename)); \ } \ @@ -65,7 +65,7 @@ char *type_to_string_(const tal_t *ctx, const char *typename, struct type_to_string { const char *typename; - char *(*fmt)(const tal_t *ctx, union printable_types u); + const char *(*fmt)(const tal_t *ctx, union printable_types u); }; AUTODATA_TYPE(type_to_string, struct type_to_string); #endif /* LIGHTNING_COMMON_TYPE_TO_STRING_H */ diff --git a/lightningd/channel.c b/lightningd/channel.c index 109aac274..3d85c527b 100644 --- a/lightningd/channel.c +++ b/lightningd/channel.c @@ -195,7 +195,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid, if (!log) { /* FIXME: update log prefix when we get scid */ /* FIXME: Use minimal unique pubkey prefix for logs! */ - char *idname = type_to_string(peer, struct pubkey, &peer->id); + const char *idname = type_to_string(peer, struct pubkey, &peer->id); channel->log = new_log(channel, peer->log_book, "%s chan #%"PRIu64":", idname, dbid); diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index da9368373..150cdec8e 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -604,7 +604,7 @@ new_uncommitted_channel(struct peer *peer) { struct lightningd *ld = peer->ld; struct uncommitted_channel *uc = tal(ld, struct uncommitted_channel); - char *idname; + const char *idname; uc->peer = peer; assert(!peer->uncommitted_channel);