mirror of
https://github.com/thepigeongenerator/tetris_clone.git
synced 2025-12-17 05:55:46 +01:00
fix: checking incorrect memory adresses
also updated assertions and remove some in place of attributes
This commit is contained in:
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user