Skip to content

Commit c85c05b

Browse files
committed
Modified fromwire_witscript to return NULL instead of struct w/ NULL ptr.
1 parent c1e1634 commit c85c05b

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

wire/fromwire.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -403,14 +403,13 @@ struct bitcoin_tx_output *fromwire_bitcoin_tx_output(const tal_t *ctx,
403403

404404
struct witscript *fromwire_witscript(const tal_t *ctx, const u8 **cursor, size_t *max)
405405
{
406-
struct witscript *retval = tal(ctx, struct witscript);
406+
struct witscript *retval;
407407
u16 len = fromwire_u16(cursor, max);
408-
if (len == 0) {
409-
retval->ptr = NULL;
410-
} else {
411-
retval->ptr = tal_arr(retval, u8, len);
412-
fromwire_u8_array(cursor, max, retval->ptr, len);
413-
}
408+
if (!len)
409+
return NULL;
410+
retval = tal(ctx, struct witscript);
411+
retval->ptr = tal_arr(retval, u8, len);
412+
fromwire_u8_array(cursor, max, retval->ptr, len);
414413
return retval;
415414
}
416415

wire/towire.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,10 @@ void towire_bitcoin_tx_output(u8 **pptr, const struct bitcoin_tx_output *output)
264264

265265
void towire_witscript(u8 **pptr, const struct witscript *script)
266266
{
267-
if (script == NULL || script->ptr == NULL) {
267+
if (script == NULL) {
268268
towire_u16(pptr, 0);
269269
} else {
270+
assert(script->ptr != NULL);
270271
towire_u16(pptr, tal_count(script->ptr));
271272
towire_u8_array(pptr, script->ptr, tal_count(script->ptr));
272273
}

0 commit comments

Comments
 (0)