From f7bd95173d99299299d061939583bbb9aa715c70 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 6 Jun 2017 12:33:31 +0930 Subject: [PATCH] wire: expose fromwire_fail to allow others to use it to mark failure. Signed-off-by: Rusty Russell --- wire/fromwire.c | 12 ++++++------ wire/wire.h | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/wire/fromwire.c b/wire/fromwire.c index 7cb9c9f32..c60619735 100644 --- a/wire/fromwire.c +++ b/wire/fromwire.c @@ -10,7 +10,7 @@ #include /* Sets *cursor to NULL and returns NULL when extraction fails. */ -static const void *fail_pull(const u8 **cursor, size_t *max) +const void *fromwire_fail(const u8 **cursor, size_t *max) { *cursor = NULL; *max = 0; @@ -25,7 +25,7 @@ const u8 *fromwire(const u8 **cursor, size_t *max, void *copy, size_t n) /* Just make sure we don't leak uninitialized mem! */ if (copy) memset(copy, 0, n); - return fail_pull(cursor, max); + return fromwire_fail(cursor, max); } *cursor += n; *max -= n; @@ -88,7 +88,7 @@ bool fromwire_bool(const u8 **cursor, size_t *max) if (!fromwire(cursor, max, &ret, sizeof(ret))) return false; if (ret != 0 && ret != 1) - fail_pull(cursor, max); + fromwire_fail(cursor, max); return ret; } @@ -103,7 +103,7 @@ void fromwire_pubkey(const u8 **cursor, size_t *max, struct pubkey *pubkey) * See towire_gossip_resolve_channel_reply --RR */ if (!memeqzero(der, sizeof(der)) && !pubkey_from_der(der, sizeof(der), pubkey)) - fail_pull(cursor, max); + fromwire_fail(cursor, max); } void fromwire_secret(const u8 **cursor, size_t *max, struct secret *secret) @@ -126,7 +126,7 @@ void fromwire_secp256k1_ecdsa_signature(const u8 **cursor, if (secp256k1_ecdsa_signature_parse_compact(secp256k1_ctx, sig, compact) != 1) - fail_pull(cursor, max); + fromwire_fail(cursor, max); } void fromwire_channel_id(const u8 **cursor, size_t *max, @@ -182,7 +182,7 @@ void fromwire_ipaddr(const u8 **cursor, size_t *max, struct ipaddr *addr) addr->addrlen = 16; break; default: - fail_pull(cursor, max); + fromwire_fail(cursor, max); return; } fromwire(cursor, max, addr->addr, addr->addrlen); diff --git a/wire/wire.h b/wire/wire.h index 093baa58e..7a0c381d1 100644 --- a/wire/wire.h +++ b/wire/wire.h @@ -49,6 +49,7 @@ void derive_channel_id(struct channel_id *channel_id, /* Read the type; returns -1 if not long enough. cursor is a tal ptr. */ int fromwire_peektype(const u8 *cursor); +const void *fromwire_fail(const u8 **cursor, size_t *max); void towire(u8 **pptr, const void *data, size_t len); void towire_pubkey(u8 **pptr, const struct pubkey *pubkey);