From a07797c166c3008d7520a046982dbf2fbd4fcec5 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Fri, 15 Apr 2022 14:24:09 +0200 Subject: [PATCH] features: Add function to unset a featurebit Needed so we can blank optional bits when comparing channel_types. --- common/features.c | 11 +++++++++++ common/features.h | 2 ++ 2 files changed, 13 insertions(+) diff --git a/common/features.c b/common/features.c index 14c0a3914..5040c39ac 100644 --- a/common/features.c +++ b/common/features.c @@ -516,6 +516,17 @@ u8 *featurebits_or(const tal_t *ctx, const u8 *f1 TAKES, const u8 *f2 TAKES) return result; } +void featurebits_unset(u8 **ptr, size_t bit) +{ + size_t len = tal_count(*ptr); + if (bit / 8 >= len) + return; + + (*ptr)[len - 1 - bit / 8] &= (0 << (bit % 8)); + + trim_features(ptr); +} + bool featurebits_eq(const u8 *f1, const u8 *f2) { size_t len = tal_bytelen(f1); diff --git a/common/features.h b/common/features.h index 58b57c48f..d5da02fdf 100644 --- a/common/features.h +++ b/common/features.h @@ -73,6 +73,8 @@ void set_feature_bit(u8 **ptr, u32 bit); /* Given two featurebit vectors, combine them by applying a logical OR. */ u8 *featurebits_or(const tal_t *ctx, const u8 *f1 TAKES, const u8 *f2 TAKES); +/* Unset a given bit in a featurebits string */ +void featurebits_unset(u8 **ptr, size_t bit); /* Are these two feature bitsets functionally equal (one may have * trailing zeroes)? */