askrene: trivial changes to avoid -O3 compiler warnings.

The code is a bit too complex for gcc to track it:

```
In file included from ccan/ccan/tal/str/str.h:7,
                 from plugins/askrene/askrene.c:11:
plugins/askrene/askrene.c: In function ‘do_getroutes’:
ccan/ccan/tal/tal.h:324:23: error: ‘routes’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  324 | #define tal_count(p) (tal_bytelen(p) / sizeof(*p))
      |                       ^~~~~~~~~~~
plugins/askrene/askrene.c:476:24: note: ‘routes’ was declared here
  476 |         struct route **routes;
      |                        ^~~~~~
plugins/askrene/askrene.c:475:29: error: ‘amounts’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  475 |         struct amount_msat *amounts;
      |                             ^~~~~~~
plugins/askrene/askrene.c:488:69: error: ‘probability’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  488 |         json_add_u64(response, "probability_ppm", (u64)(probability * 1000000));
      |                                                        ~~~~~~~~~~~~~^~~~~~~~~~
cc plugins/askrene/dijkstra.c
cc1: all warnings being treated as errors
```

On my local machine, it also warns in param_dev_channel, so I fixed that too.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2024-10-04 09:10:53 +09:30
parent 630ec6a566
commit e3c9bc6d3a
2 changed files with 14 additions and 10 deletions

View file

@ -3167,7 +3167,7 @@ static struct command_result *param_dev_channel(struct command *cmd,
const jsmntok_t *tok,
struct channel **channel)
{
struct peer *peer;
struct peer *peer COMPILER_WANTS_INIT("gcc version 12.3.0 -O3");
struct command_result *res;
bool more_than_one;

View file

@ -301,13 +301,13 @@ static const char *get_routes(const tal_t *ctx,
srcnode = gossmap_find_node(askrene->gossmap, source);
if (!srcnode) {
ret = tal_fmt(ctx, "Unknown source node %s", fmt_node_id(tmpctx, source));
goto out;
goto fail;
}
dstnode = gossmap_find_node(askrene->gossmap, dest);
if (!dstnode) {
ret = tal_fmt(ctx, "Unknown destination node %s", fmt_node_id(tmpctx, dest));
goto out;
goto fail;
}
delay_feefactor = 1.0/1000000;
@ -331,7 +331,7 @@ static const char *get_routes(const tal_t *ctx,
mu, delay_feefactor, base_fee_penalty, prob_cost_factor);
if (!flows) {
ret = explain_failure(ctx, rq, srcnode, dstnode, amount);
goto out;
goto fail;
}
/* Too much delay? */
@ -348,7 +348,7 @@ static const char *get_routes(const tal_t *ctx,
mu, delay_feefactor, base_fee_penalty, prob_cost_factor);
if (!flows || delay_feefactor > 10) {
ret = tal_fmt(ctx, "Could not find route without excessive delays");
goto out;
goto fail;
}
}
@ -359,13 +359,13 @@ static const char *get_routes(const tal_t *ctx,
mu, delay_feefactor, base_fee_penalty, prob_cost_factor);
if (!flows || mu == 100) {
ret = tal_fmt(ctx, "Could not find route without excessive cost");
goto out;
goto fail;
}
}
if (finalcltv + flows_worst_delay(flows) > 2016) {
ret = tal_fmt(ctx, "Could not find route without excessive cost or delays");
goto out;
goto fail;
}
/* The above did not take into account the extra funds to pay
@ -374,7 +374,7 @@ static const char *get_routes(const tal_t *ctx,
* still possible */
ret = refine_with_fees_and_limits(ctx, rq, amount, &flows);
if (ret)
goto out;
goto fail;
/* Convert back into routes, with delay and other information fixed */
*routes = tal_arr(ctx, struct route *, tal_count(flows));
@ -412,9 +412,13 @@ static const char *get_routes(const tal_t *ctx,
}
*probability = flowset_probability(flows, rq);
ret = NULL;
gossmap_remove_localmods(askrene->gossmap, localmods);
return NULL;
out:
/* Explicit failure path keeps the compiler (gcc version 12.3.0 -O3) from
* warning about uninitialized variables in the caller */
fail:
assert(ret != NULL);
gossmap_remove_localmods(askrene->gossmap, localmods);
return ret;
}