Skip to content

Commit

Permalink
devtools: fix printing of bigsize fields.
Browse files Browse the repository at this point in the history
printwire_bigsize is not the same as printwire_u64!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell committed Aug 5, 2024
1 parent 4cf81ea commit bb557f5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions devtools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ DEVTOOLS_TOOL_OBJS := $(DEVTOOLS_TOOL_SRC:.c=.o)

# Make sure these depend on everything.
ALL_C_SOURCES += $(DEVTOOLS_TOOL_SRC)
ALL_C_HEADERS +=
ALL_C_HEADERS += devtools/print_wire.h
ALL_PROGRAMS += $(DEVTOOLS)

# Don't include this in ALL_PROGRAMS as we need a special link line for -lz
Expand Down Expand Up @@ -90,7 +90,7 @@ devtools/onion: $(DEVTOOLS_COMMON_OBJS) $(JSMN_OBJS) $(BITCOIN_OBJS) common/onio

devtools/gossipwith: $(DEVTOOLS_COMMON_OBJS) $(JSMN_OBJS) $(BITCOIN_OBJS) wire/fromwire.o wire/towire.o wire/peer_wiregen.o devtools/gossipwith.o common/cryptomsg.o common/cryptomsg.o

$(DEVTOOLS_OBJS) $(DEVTOOLS_TOOL_OBJS): wire/wire.h
$(DEVTOOLS_OBJS) $(DEVTOOLS_TOOL_OBJS): wire/wire.h devtools/print_wire.h

devtools/mkcommit: $(DEVTOOLS_COMMON_OBJS) $(BITCOIN_OBJS) common/derive_basepoints.o common/channel_type.o common/keyset.o common/key_derive.o common/initial_commit_tx.o common/permute_tx.o wire/fromwire.o wire/towire.o devtools/mkcommit.o channeld/full_channel.o common/initial_channel.o common/htlc_state.o common/pseudorand.o common/htlc_tx.o channeld/commit_tx.o common/htlc_trim.o

Expand Down
11 changes: 11 additions & 0 deletions devtools/print_wire.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ bool printwire_u64(const char *fieldname, const u8 **cursor, size_t *plen)
return true;
}

bool printwire_bigsize(const char *fieldname, const u8 **cursor, size_t *plen)
{
u64 v = fromwire_bigsize(cursor, plen);
if (!*cursor) {
printf("**TRUNCATED bigsize %s**\n", fieldname);
return false;
}
printf("%"PRIu64"\n", v);
return true;
}

bool printwire_s8(const char *fieldname, const u8 **cursor, size_t *plen)
{
s8 v = fromwire_s8(cursor, plen);
Expand Down
2 changes: 1 addition & 1 deletion devtools/print_wire.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ struct tlv_print_record_type {
};

typedef u64 bigsize;
#define printwire_bigsize printwire_u64
struct wireaddr;

bool printwire_u8(const char *fieldname, const u8 **cursor, size_t *plen);
bool printwire_u16(const char *fieldname, const u8 **cursor, size_t *plen);
bool printwire_u32(const char *fieldname, const u8 **cursor, size_t *plen);
bool printwire_u64(const char *fieldname, const u8 **cursor, size_t *plen);
bool printwire_bigsize(const char *fieldname, const u8 **cursor, size_t *plen);
bool printwire_s8(const char *fieldname, const u8 **cursor, size_t *plen);
bool printwire_s16(const char *fieldname, const u8 **cursor, size_t *plen);
bool printwire_s32(const char *fieldname, const u8 **cursor, size_t *plen);
Expand Down
1 change: 1 addition & 0 deletions wire/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ WIRE_OBJS := $(WIRE_SRC:.c=.o) common/sciddir_or_pubkey.o
WIRE_PRINT_OBJS := $(WIRE_PRINT_SRC:.c=.o)
WIRE_BOLT12_OBJS := $(WIRE_BOLT12_SRC:.c=.o)
$(WIRE_OBJS) $(WIRE_PRINT_OBJS) $(WIRE_BOLT12_OBJS): $(WIRE_HEADERS) $(WIRE_PRINT_HEADERS)
$(WIRE_PRINT_OBJS): devtools/print_wire.h

ALL_C_SOURCES += $(WIRE_SRC) $(WIRE_BOLT12_SRC) $(WIRE_PRINT_SRC)

Expand Down

0 comments on commit bb557f5

Please sign in to comment.