MCPcopy Create free account
hub / github.com/ElementsProject/lightning / run

Function run

tests/fuzz/fuzz-amount.c:11–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9}
10
11void run(const uint8_t *data, size_t size)
12{
13 struct amount_msat msat;
14 struct amount_sat sat;
15 char *string;
16 uint8_t *buf;
17 const char *fmt_msat, *fmt_msatbtc, *fmt_sat, *fmt_satbtc;
18
19
20 /* We should not crash when parsing any string. */
21
22 string = to_string(NULL, data, size);
23 parse_amount_msat(&msat, string, tal_count(string));
24 parse_amount_sat(&sat, string, tal_count(string));
25 tal_free(string);
26
27
28 /* Same with the wire primitives. */
29
30 buf = tal_arr(NULL, uint8_t, 8);
31
32 msat = fromwire_amount_msat(&data, &size);
33 towire_amount_msat(&buf, msat);
34 sat = fromwire_amount_sat(&data, &size);
35 towire_amount_sat(&buf, sat);
36
37 tal_free(buf);
38
39
40 /* Format should inconditionally produce valid amount strings according to our
41 * parser */
42
43 fmt_msat = fmt_amount_msat(NULL, msat);
44 fmt_msatbtc = fmt_amount_msat_btc(NULL, msat, true);
45 assert(parse_amount_msat(&msat, fmt_msat, tal_count(fmt_msat)));
46 assert(parse_amount_msat(&msat, fmt_msatbtc, tal_count(fmt_msatbtc)));
47 tal_free(fmt_msat);
48 tal_free(fmt_msatbtc);
49
50 fmt_sat = fmt_amount_sat(NULL, sat);
51 fmt_satbtc = fmt_amount_sat_btc(NULL, sat, true);
52 assert(parse_amount_sat(&sat, fmt_sat, tal_count(fmt_sat)));
53 assert(parse_amount_sat(&sat, fmt_satbtc, tal_count(fmt_satbtc)));
54 tal_free(fmt_sat);
55 tal_free(fmt_satbtc);
56}

Callers

nothing calls this directly

Calls 12

tal_freeFunction · 0.85
fmt_amount_msat_btcFunction · 0.85
fmt_amount_sat_btcFunction · 0.85
to_stringFunction · 0.70
parse_amount_msatFunction · 0.50
parse_amount_satFunction · 0.50
fromwire_amount_msatFunction · 0.50
towire_amount_msatFunction · 0.50
fromwire_amount_satFunction · 0.50
towire_amount_satFunction · 0.50
fmt_amount_msatFunction · 0.50
fmt_amount_satFunction · 0.50

Tested by

no test coverage detected