From b6a3f93b755c5719f22b0a8a96ba0dcb09114a4d Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sat, 1 Apr 2023 14:13:23 +1030 Subject: [PATCH] channeld: don't asort(NULL). It's defined to be nonull: ``` channeld/channeld.c:2381:2: runtime error: null pointer passed as argument 1, which is declared to never be null /usr/include/stdlib.h:856:3: note: nonnull attribute specified here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior channeld/channeld.c:2381:2 in ``` Signed-off-by: Rusty Russell --- channeld/channeld.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/channeld/channeld.c b/channeld/channeld.c index dfda4fe65..a1bd75c11 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -2368,7 +2368,8 @@ static void resend_commitment(struct peer *peer, struct changed_htlc *last) * is to sort them all into ascending ID order here (we could do * this when we save them in channel_sending_commit, but older versions * won't have them sorted in the db, so doing it here is better). */ - asort(last, tal_count(last), cmp_changed_htlc_id, NULL); + if (last) + asort(last, tal_count(last), cmp_changed_htlc_id, NULL); /* BOLT #2: *