From 65cc6bbd50d71ec0e46738ca42661b4075f3a4f8 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 22 Jan 2016 06:41:47 +1030 Subject: [PATCH] pkt_err: make it variadic. Signed-off-by: Rusty Russell --- state.h | 2 +- test/test_state_coverage.c | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/state.h b/state.h index 256592806..8f9446d2f 100644 --- a/state.h +++ b/state.h @@ -114,7 +114,7 @@ Pkt *pkt_htlc_routefail(const tal_t *ctx, const struct peer *peer, Pkt *pkt_update_accept(const tal_t *ctx, const struct peer *peer); Pkt *pkt_update_signature(const tal_t *ctx, const struct peer *peer); Pkt *pkt_update_complete(const tal_t *ctx, const struct peer *peer); -Pkt *pkt_err(const tal_t *ctx, const char *msg); +Pkt *pkt_err(const tal_t *ctx, const char *fmt, ...); Pkt *pkt_close(const tal_t *ctx, const struct peer *peer); Pkt *pkt_close_complete(const tal_t *ctx, const struct peer *peer); Pkt *pkt_close_ack(const tal_t *ctx, const struct peer *peer); diff --git a/test/test_state_coverage.c b/test/test_state_coverage.c index 531baec65..209de9722 100644 --- a/test/test_state_coverage.c +++ b/test/test_state_coverage.c @@ -654,9 +654,17 @@ Pkt *pkt_update_complete(const tal_t *ctx, const struct peer *peer) peer->current_htlc.htlc.id); } -Pkt *pkt_err(const tal_t *ctx, const char *msg) +Pkt *pkt_err(const tal_t *ctx, const char *fmt, ...) { - return (Pkt *)tal_fmt(ctx, "PKT_ERROR: %s", msg); + char *str; + va_list ap; + + str = tal_strdup(ctx, "PKT_ERROR: "); + va_start(ap, fmt); + tal_append_vfmt(&str, fmt, ap); + va_end(ap); + + return (Pkt *)str; } Pkt *pkt_close(const tal_t *ctx, const struct peer *peer) @@ -676,8 +684,7 @@ Pkt *pkt_close_ack(const tal_t *ctx, const struct peer *peer) Pkt *pkt_err_unexpected(const tal_t *ctx, const Pkt *pkt) { - return (Pkt *)tal_fmt(ctx, "PKT_ERROR: Unexpected pkt %s", - (const char *)pkt); + return pkt_err("Unexpected pkt %s", (const char *)pkt); } Pkt *accept_pkt_open(const tal_t *ctx,