From 5aea65b4633cfb7542c26d6ca769d00fbfec756a Mon Sep 17 00:00:00 2001 From: lisa neigut Date: Mon, 25 Mar 2019 18:33:29 -0700 Subject: [PATCH] tlv: make message sizes u8 not u16 Suggested-By: @rustyrussell --- tools/generate-wire.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/generate-wire.py b/tools/generate-wire.py index bd1d177ff..7a6ff8fc2 100755 --- a/tools/generate-wire.py +++ b/tools/generate-wire.py @@ -832,28 +832,28 @@ struct {tlv_name} {{ tlv__type_impl_towire_fields = """\tif ({tlv_name}->{name}) {{ \t\ttlv_msg = tal_arr(ctx, u8, 0); -\t\ttowire_u16(p, {enum}); +\t\ttowire_u8(p, {enum}); \t\ttowire_{tlv_name}_{name}(&tlv_msg, {tlv_name}->{name}); \t\tmsg_len = tal_count(tlv_msg); -\t\ttowire_u16(p, msg_len); +\t\ttowire_u8(p, msg_len); \t\ttowire_u8_array(p, tlv_msg, msg_len); \t}} """ tlv__type_impl_towire_template = """static void towire__{tlv_name}(const tal_t *ctx, u8 **p, const struct {tlv_name} *{tlv_name}) {{ -\tu16 msg_len; +\tu8 msg_len; \tu8 *tlv_msg; {fields}}} """ tlv__type_impl_fromwire_template = """static bool fromwire__{tlv_name}(const tal_t *ctx, const u8 **p, size_t *plen, const u16 *len, struct {tlv_name} *{tlv_name}) {{ -\tu16 msg_type, msg_len; +\tu8 msg_type, msg_len; \tif (*plen < *len) \t\treturn false; \twhile (*plen) {{ -\t\tmsg_type = fromwire_u16(p, plen); -\t\tmsg_len = fromwire_u16(p, plen); +\t\tmsg_type = fromwire_u8(p, plen); +\t\tmsg_len = fromwire_u8(p, plen); \t\tif (*plen < msg_len) {{ \t\t\tfromwire_fail(p, plen); \t\t\tbreak;