From b07795a0397aa0c816e948e3981efe722a75a2b8 Mon Sep 17 00:00:00 2001 From: Alexander Vdolainen Date: Wed, 3 Dec 2025 02:12:20 +0200 Subject: [PATCH] fixed NREA write functions; made them aware about non-realloc buffer; --- ndbuf.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/ndbuf.c b/ndbuf.c index 89ac862..32b1454 100644 --- a/ndbuf.c +++ b/ndbuf.c @@ -283,12 +283,23 @@ static int __rdb_grow(ndbuf_t *b, uint32_t len) return 0; } +static inline int __ndbuf_is_ro(ndbuf_t *b) +{ + return (b->flags & NDBUF_RORB) ? 1 : 0; +} + +static inline int __ndbuf_is_nrea(ndbuf_t *b) +{ + return (b->flags & NDBUF_NREA) ? 1 : 0; +} + /* write different types, should return the size of the * written data, otherwise error occurs */ uint32_t ndbuf_write_u8(ndbuf_t *b, uint8_t u) { if(!b || !b->raw) return 0; if(b->ulength == b->rlength) { + if(__ndbuf_is_nrea(b)) return 0; /* non reallocatable buffer */ if(__rdb_grow(b, sizeof(uint8_t))) return 0; } @@ -302,6 +313,7 @@ uint32_t ndbuf_write_u16(ndbuf_t *b, uint16_t uu) { if(!b || !b->raw) return 0; if(b->ulength + sizeof(uint16_t) >= b->rlength) { + if(__ndbuf_is_nrea(b)) return 0; /* non reallocatable buffer */ if(__rdb_grow(b, sizeof(uint16_t))) return 0; } @@ -315,6 +327,7 @@ uint32_t ndbuf_write_u32(ndbuf_t *b, uint32_t uu) { if(!b || !b->raw) return 0; if(b->ulength + sizeof(uint32_t) >= b->rlength) { + if(__ndbuf_is_nrea(b)) return 0; /* non reallocatable buffer */ if(__rdb_grow(b, sizeof(uint32_t))) return 0; } @@ -328,6 +341,7 @@ uint32_t ndbuf_write_u64(ndbuf_t *b, uint64_t uu) { if(!b || !b->raw) return 0; if(b->ulength + sizeof(uint64_t) >= b->rlength) { + if(__ndbuf_is_nrea(b)) return 0; /* non reallocatable buffer */ if(__rdb_grow(b, sizeof(uint64_t))) return 0; } @@ -337,16 +351,6 @@ uint32_t ndbuf_write_u64(ndbuf_t *b, uint64_t uu) return sizeof(uint64_t); } -static inline int __ndbuf_is_ro(ndbuf_t *b) -{ - return (b->flags & NDBUF_RORB) ? 1 : 0; -} - -static inline int __ndbuf_is_nrea(ndbuf_t *b) -{ - return (b->flags & NDBUF_NREA) ? 1 : 0; -} - /* write raw data with the given length */ uint32_t ndbuf_write_raw(ndbuf_t *b, void *wi, uint32_t len) {