nostrdb

an unfairly fast embedded nostr database backed by lmdb
git clone git://jb55.com/nostrdb
Log | Files | Refs | Submodules | README | LICENSE

commit 8ec69f4a3c4adfd3f9f51f4eb64242cdc7f65eae
parent b6c0923f12a974e6f2bbc748be1a068d76e4ccb2
Author: Rusty Russell <rusty@rustcorp.com.au>
Date:   Sat, 17 Aug 2024 14:57:06 +0930

bolt11: move utf8_check into local function.

It isn't actually in the CCAN module (though it probably should be!).
So it breaks when we update.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>


Diffstat:
Mccan/ccan/utf8/utf8.c | 19-------------------
Mccan/ccan/utf8/utf8.h | 2--
Msrc/bolt11/bolt11.c | 18++++++++++++++++++
Msrc/bolt11/utf8.h | 2--
Msrc/util.h | 1-
5 files changed, 18 insertions(+), 24 deletions(-)

diff --git a/ccan/ccan/utf8/utf8.c b/ccan/ccan/utf8/utf8.c @@ -178,22 +178,3 @@ size_t utf8_encode(uint32_t point, char dest[UTF8_MAX_LEN]) return 4; } -/* Check for valid UTF-8 */ -bool utf8_check(const void *vbuf, size_t buflen) -{ - const unsigned char *buf = vbuf; - struct utf8_state utf8_state = UTF8_STATE_INIT; - bool need_more = false; - - for (size_t i = 0; i < buflen; i++) { - if (!utf8_decode(&utf8_state, buf[i])) { - need_more = true; - continue; - } - need_more = false; - if (errno != 0) - return false; - } - return !need_more; -} - diff --git a/ccan/ccan/utf8/utf8.h b/ccan/ccan/utf8/utf8.h @@ -52,6 +52,4 @@ bool utf8_decode(struct utf8_state *utf8_state, char c); */ size_t utf8_encode(uint32_t point, char dest[UTF8_MAX_LEN]); -/* Check for valid UTF-8 */ -bool utf8_check(const void *vbuf, size_t buflen); #endif /* CCAN_UTF8_H */ diff --git a/src/bolt11/bolt11.c b/src/bolt11/bolt11.c @@ -178,6 +178,24 @@ static void decode_p(struct bolt11 *b11, *have_p = true; } +/* Check for valid UTF-8 */ +static bool utf8_check(const void *vbuf, size_t buflen) +{ + const u8 *buf = vbuf; + struct utf8_state utf8_state = UTF8_STATE_INIT; + bool need_more = false; + + for (size_t i = 0; i < buflen; i++) { + if (!utf8_decode(&utf8_state, buf[i])) { + need_more = true; + continue; + } + need_more = false; + if (errno != 0) + return false; + } + return !need_more; +} static char *utf8_str(const tal_t *ctx, const u8 *buf TAKES, size_t buflen) { diff --git a/src/bolt11/utf8.h b/src/bolt11/utf8.h @@ -52,6 +52,4 @@ bool utf8_decode(struct utf8_state *utf8_state, char c); */ size_t utf8_encode(uint32_t point, char dest[UTF8_MAX_LEN]); -/* Check for valid UTF-8 */ -bool utf8_check(const void *vbuf, size_t buflen); #endif /* CCAN_UTF8_H */ diff --git a/src/util.h b/src/util.h @@ -28,6 +28,5 @@ static inline char *strdupn(const char *src, size_t size) { dest[size] = '\0'; return dest; } - #endif // NDB_UTIL_H