utils: make tal_arr_expand safer.

Christian and I both unwittingly used it in form:

	*tal_arr_expand(&x) = tal(x, ...)

Since '=' isn't a sequence point, the compiler can (and does!) cache
the value of x, handing it to tal *after* tal_arr_expand() moves it
due to tal_resize().

The new version is somewhat less convenient to use, but doesn't have
this problem, since the assignment is always evaluated after the
resize.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2019-01-15 14:21:27 +10:30
committed by Christian Decker
parent a5ed98a2ea
commit 26dda57cc0
26 changed files with 170 additions and 151 deletions

View File

@@ -16,7 +16,7 @@ struct msg_queue *msg_queue_new(const tal_t *ctx)
static void do_enqueue(struct msg_queue *q, const u8 *add TAKES)
{
*tal_arr_expand(&q->q) = tal_dup_arr(q, u8, add, tal_count(add), 0);
tal_arr_expand(&q->q, tal_dup_arr(q, u8, add, tal_count(add), 0));
/* In case someone is waiting */
io_wake(q);