Skip to content

Commit 9e34145

Browse files
Chandra Prataprustyrussell
authored andcommitted
fuzz-tests: Get rid of magic numbers
Replace instances of 36 with sizeof(outpoint) and 32 with sizeof(chan_id) since that's what they represent. This makes the test more future-proof.
1 parent bc57dc9 commit 9e34145

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

tests/fuzz/fuzz-channel_id.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@ void run(const uint8_t *data, size_t size)
2323
size_t wire_max;
2424
uint8_t *wire_buf;
2525

26-
/* 32 (txid) + 4 (vout) */
27-
if (size < 36)
26+
if (size < sizeof(outpoint))
2827
return;
2928

30-
v1_chunks = get_chunks(NULL, data, size, 36);
29+
v1_chunks = get_chunks(NULL, data, size, sizeof(outpoint));
3130
for (size_t i = 0; i < tal_count(v1_chunks); i++) {
3231
wire_ptr = v1_chunks[i];
33-
wire_max = 36;
32+
wire_max = sizeof(outpoint);
3433
fromwire_bitcoin_outpoint(&wire_ptr, &wire_max, &outpoint);
3534
assert(wire_ptr);
3635
derive_channel_id(&chan_id, &outpoint);
@@ -54,7 +53,7 @@ void run(const uint8_t *data, size_t size)
5453
}
5554
tal_free(v2_chunks);
5655

57-
marshal_chunks = get_chunks(NULL, data, size, 32);
56+
marshal_chunks = get_chunks(NULL, data, size, sizeof(chan_id));
5857
for (size_t i = 0; i < tal_count(marshal_chunks); i++) {
5958
wire_ptr = marshal_chunks[i];
6059
wire_max = tal_count(marshal_chunks[i]);

0 commit comments

Comments
 (0)