libsheepy

C lib for handling text files, strings and json like data structure with an object oriented system
git clone https://spartatek.se/git/libsheepy.git
Log | Files | Refs | README | LICENSE

commit d87a7c2c90bfc67eae0cdd59614dbdca99b04200
parent d1da7a37b447c6730ca95e18aaf78e9a0bdbd110
Author: Remy Noulin <loader2x@gmail.com>
Date:   Fri,  4 Apr 2025 21:32:39 +0200

fix issue when duplicating btt buffers with len 0, the alloc size was 0 and when alloc is 0, it means readonly buffer. Alloc size is 4 when len is 0

release/libsheepy.h   | 2 +-
release/libsheepyBt.c | 6 +++---
release/libsheepyBt.h | 2 ++
src/libsheepy.h       | 2 +-
src/libsheepyBt.c     | 6 +++---
src/libsheepyBt.h     | 2 ++
6 files changed, 12 insertions(+), 8 deletions(-)

Diffstat:
Mrelease/libsheepy.h | 2+-
Mrelease/libsheepyBt.c | 6+++---
Mrelease/libsheepyBt.h | 2++
Msrc/libsheepy.h | 2+-
Msrc/libsheepyBt.c | 6+++---
Msrc/libsheepyBt.h | 2++
6 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/release/libsheepy.h b/release/libsheepy.h @@ -98,7 +98,7 @@ // version accoring to the version package: Release.Major.minor.patch // https://noulin.net/version/file/README.md.html -#define LIBSHEEPY_VERSION "2.2.18" +#define LIBSHEEPY_VERSION "2.2.18.1" #ifndef SH_PREFIX #define SH_PREFIX(NAME) NAME diff --git a/release/libsheepyBt.c b/release/libsheepyBt.c @@ -47,7 +47,7 @@ btt initB(void *buf, u32 len, bool allocated) { */ btt newB(u32 allocateSize) { btt r = {.len = 0}; - r.b = malloc(allocateSize); + r.b = malloc(allocateSize ? allocateSize : 4/*allocate 4 bytes when len is 0*/); if (!r.b) ret emptybt; r.alloc = allocateSize; ret r; @@ -58,7 +58,7 @@ btt newB(u32 allocateSize) { */ btt *allocNewB(u32 allocateSize) { btt *r = malloc(sizeof(*r)); - *r = newB(allocateSize); + *r = newB(allocateSize ? allocateSize : 4/*allocate 4 bytes when len is 0*/); ret r; } @@ -140,7 +140,7 @@ btt *allocPB(const btt *b) { btt copyB(const btt b) { btt r = b; r.b = malloc(b.len); - r.alloc = b.len; + r.alloc = b.len ? b.len : 4 /*allocate 4 bytes when len is 0*/; memcpy(r.b, b.b, b.len); ret r; } diff --git a/release/libsheepyBt.h b/release/libsheepyBt.h @@ -24,6 +24,8 @@ * u32 alloc; * } btt; * ``` + * when b is on the heap (even len 0), alloc is above 0 + * * The btt structure is managed by the *B functions. * The *B (not b*B) functions don't modify the first btt parameter. * The functions named b*B modify the first bbt pointer parameter and return a btt pointer. diff --git a/src/libsheepy.h b/src/libsheepy.h @@ -98,7 +98,7 @@ // version accoring to the version package: Release.Major.minor.patch // https://noulin.net/version/file/README.md.html -#define LIBSHEEPY_VERSION "2.2.18" +#define LIBSHEEPY_VERSION "2.2.18.1" #ifndef SH_PREFIX #define SH_PREFIX(NAME) NAME diff --git a/src/libsheepyBt.c b/src/libsheepyBt.c @@ -47,7 +47,7 @@ btt initB(void *buf, u32 len, bool allocated) { */ btt newB(u32 allocateSize) { btt r = {.len = 0}; - r.b = malloc(allocateSize); + r.b = malloc(allocateSize ? allocateSize : 4/*allocate 4 bytes when len is 0*/); if (!r.b) ret emptybt; r.alloc = allocateSize; ret r; @@ -58,7 +58,7 @@ btt newB(u32 allocateSize) { */ btt *allocNewB(u32 allocateSize) { btt *r = malloc(sizeof(*r)); - *r = newB(allocateSize); + *r = newB(allocateSize ? allocateSize : 4/*allocate 4 bytes when len is 0*/); ret r; } @@ -140,7 +140,7 @@ btt *allocPB(const btt *b) { btt copyB(const btt b) { btt r = b; r.b = malloc(b.len); - r.alloc = b.len; + r.alloc = b.len ? b.len : 4 /*allocate 4 bytes when len is 0*/; memcpy(r.b, b.b, b.len); ret r; } diff --git a/src/libsheepyBt.h b/src/libsheepyBt.h @@ -24,6 +24,8 @@ * u32 alloc; * } btt; * ``` + * when b is on the heap (even len 0), alloc is above 0 + * * The btt structure is managed by the *B functions. * The *B (not b*B) functions don't modify the first btt parameter. * The functions named b*B modify the first bbt pointer parameter and return a btt pointer.