From 38d229df3d5c1822159fd41d1b2191cd8257e26c Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sun, 17 Nov 2024 16:09:06 +1030 Subject: [PATCH] tools/generate-wire.py: make sure TLV array fields are allocated off TLV. Otherwise the whole thing cannot be tal_steal() onto a different parent. Here's the difference in generated files: --- ./wire/onion_wiregen.c.pre 2024-10-23 12:26:09.023176933 +1030 +++ ./wire/onion_wiregen.c 2024-10-23 12:26:52.434828303 +1030 @@ -128,7 +128,7 @@ blinded_path->path = num_hops ? tal_arr(blinded_path, struct blinded_path_hop *, 0) : NULL; for (size_t i = 0; i < num_hops; i++) { struct blinded_path_hop * tmp; - tmp = fromwire_blinded_path_hop(blinded_path, cursor, plen); + tmp = fromwire_blinded_path_hop(blinded_path->path, cursor, plen); tal_arr_expand(&blinded_path->path, tmp); } --- ./wire/bolt12_wiregen.c.pre 2024-10-23 12:26:09.079176474 +1030 +++ ./wire/bolt12_wiregen.c 2024-10-23 12:26:52.612826902 +1030 @@ -316,7 +316,7 @@ r->offer_paths = *plen ? tal_arr(r, struct blinded_path *, 0) : NULL; while (*plen != 0) { struct blinded_path * tmp; - tmp = fromwire_blinded_path(r, cursor, plen); + tmp = fromwire_blinded_path(r->offer_paths, cursor, plen); tal_arr_expand(&r->offer_paths, tmp); } } @@ -729,7 +729,7 @@ r->offer_paths = *plen ? tal_arr(r, struct blinded_path *, 0) : NULL; while (*plen != 0) { struct blinded_path * tmp; - tmp = fromwire_blinded_path(r, cursor, plen); + tmp = fromwire_blinded_path(r->offer_paths, cursor, plen); tal_arr_expand(&r->offer_paths, tmp); } } @@ -1052,7 +1052,7 @@ r->invreq_paths = *plen ? tal_arr(r, struct blinded_path *, 0) : NULL; while (*plen != 0) { struct blinded_path * tmp; - tmp = fromwire_blinded_path(r, cursor, plen); + tmp = fromwire_blinded_path(r->invreq_paths, cursor, plen); tal_arr_expand(&r->invreq_paths, tmp); } } @@ -1385,7 +1385,7 @@ r->offer_paths = *plen ? tal_arr(r, struct blinded_path *, 0) : NULL; while (*plen != 0) { struct blinded_path * tmp; - tmp = fromwire_blinded_path(r, cursor, plen); + tmp = fromwire_blinded_path(r->offer_paths, cursor, plen); tal_arr_expand(&r->offer_paths, tmp); } } @@ -1708,7 +1708,7 @@ r->invreq_paths = *plen ? tal_arr(r, struct blinded_path *, 0) : NULL; while (*plen != 0) { struct blinded_path * tmp; - tmp = fromwire_blinded_path(r, cursor, plen); + tmp = fromwire_blinded_path(r->invreq_paths, cursor, plen); tal_arr_expand(&r->invreq_paths, tmp); } } @@ -1781,7 +1781,7 @@ r->invoice_paths = *plen ? tal_arr(r, struct blinded_path *, 0) : NULL; while (*plen != 0) { struct blinded_path * tmp; - tmp = fromwire_blinded_path(r, cursor, plen); + tmp = fromwire_blinded_path(r->invoice_paths, cursor, plen); tal_arr_expand(&r->invoice_paths, tmp); } } @@ -1808,7 +1808,7 @@ r->invoice_blindedpay = *plen ? tal_arr(r, struct blinded_payinfo *, 0) : NULL; while (*plen != 0) { struct blinded_payinfo * tmp; - tmp = fromwire_blinded_payinfo(r, cursor, plen); + tmp = fromwire_blinded_payinfo(r->invoice_blindedpay, cursor, plen); tal_arr_expand(&r->invoice_blindedpay, tmp); } } @@ -1927,7 +1927,7 @@ r->invoice_fallbacks = *plen ? tal_arr(r, struct fallback_address *, 0) : NULL; while (*plen != 0) { struct fallback_address * tmp; - tmp = fromwire_fallback_address(r, cursor, plen); + tmp = fromwire_fallback_address(r->invoice_fallbacks, cursor, plen); tal_arr_expand(&r->invoice_fallbacks, tmp); } } Signed-off-by: Rusty Russell --- tools/gen/impl_template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/gen/impl_template b/tools/gen/impl_template index ec6f9d196..a6a166694 100644 --- a/tools/gen/impl_template +++ b/tools/gen/impl_template @@ -98,7 +98,7 @@ ${fieldname} = ${f.size('*plen')} ? tal_arr(${ctx}, ${typename}, 0) : NULL; % if f.type_obj.is_assignable(): tmp = fromwire_${type_}(cursor, plen); % elif f.is_varlen() and f.type_obj.is_varsize(): - tmp = fromwire_${type_}(${ctx}, cursor, plen); + tmp = fromwire_${type_}(${fieldname}, cursor, plen); % else: fromwire_${type_}(cursor, plen, &tmp); % endif