fix: checking incorrect memory adresses

also updated assertions and remove some in place of attributes
This commit is contained in:
2025-04-23 16:51:50 +02:00
parent 9f6f20f36c
commit df249f1c35

View File

@@ -41,17 +41,14 @@ struct proc_buf_dat {
}; };
/* use malloc to append src to the end of dest. /* use malloc to append src to the end of dest.
if dest == NULL, memory is allocated, otherwise it is reallocated. if *dest == NULL, memory is allocated, otherwise it is reallocated.
returns 0 upon success, 1 upon failure. */ returns 0 upon success, 1 upon failure. */
static inline int str_put(char* restrict* restrict dest, size_t dest_len, char const* restrict src, size_t src_len) { __attribute__((nonnull(1, 3))) static inline int str_put(char* restrict* restrict dest, size_t dest_len, char const* restrict src, size_t src_len) {
assert(dest); if (!*dest) {
assert(src);
if (!dest) {
*dest = malloc(src_len + 1); *dest = malloc(src_len + 1);
if (!*dest) return 1; if (!*dest) return 1;
} else { } else {
assert(*dest); assert(src_len > dest_len); // sanity check
assert(src_len > dest_len);
void* ptr = realloc(*dest, src_len + 1); void* ptr = realloc(*dest, src_len + 1);
if (!ptr) return 1; if (!ptr) return 1;
*dest = ptr; *dest = ptr;