Add extra checks for NULL pointers
This commit is contained in:
parent
5e84e270bc
commit
f11d4481a2
@ -29,6 +29,10 @@ dstr_t *dstr_with_capacity(u64 capacity) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dstr_t *dstr_from_string(const char *str) {
|
dstr_t *dstr_from_string(const char *str) {
|
||||||
|
if (!str) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
u64 length = strlen(str);
|
u64 length = strlen(str);
|
||||||
|
|
||||||
u64 capacity = length * CAPACITY_SCALAR;
|
u64 capacity = length * CAPACITY_SCALAR;
|
||||||
@ -46,7 +50,7 @@ dstr_t *dstr_from_string(const char *str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void dstr_update(dstr_t **dst, const char *src) {
|
void dstr_update(dstr_t **dst, const char *src) {
|
||||||
if (!(*dst)) {
|
if (!dst || !(*dst)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +82,7 @@ void dstr_update(dstr_t **dst, const char *src) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void dstr_free(dstr_t **str) {
|
void dstr_free(dstr_t **str) {
|
||||||
if (!(*str)) {
|
if (!str || !(*str)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +91,7 @@ void dstr_free(dstr_t **str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void dstr_concat(dstr_t **dst, const char *src) {
|
void dstr_concat(dstr_t **dst, const char *src) {
|
||||||
if (!(*dst)) {
|
if (!dst || !(*dst)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +113,7 @@ void dstr_concat(dstr_t **dst, const char *src) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void dstr_append(dstr_t **dst, char c) {
|
void dstr_append(dstr_t **dst, char c) {
|
||||||
if (!(*dst)) {
|
if (!dst || !(*dst)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,6 +129,10 @@ void dstr_append(dstr_t **dst, char c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void dstr_resize(dstr_t **str) {
|
void dstr_resize(dstr_t **str) {
|
||||||
|
if (!str || !(*str)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
u64 capacity = (*str)->size;
|
u64 capacity = (*str)->size;
|
||||||
|
|
||||||
dstr_t *tmp = (dstr_t *)realloc(*str, sizeof(dstr_t) + capacity + 1);
|
dstr_t *tmp = (dstr_t *)realloc(*str, sizeof(dstr_t) + capacity + 1);
|
||||||
|
@ -131,8 +131,16 @@ void free_json(jentity_t **entity) {
|
|||||||
dstr_free(&(entt_ptr->pair.key));
|
dstr_free(&(entt_ptr->pair.key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch (value->type) {
|
switch (value->type) {
|
||||||
case JVAL_COLLECTION:
|
case JVAL_COLLECTION:
|
||||||
|
if (!(value->collection)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (value->collection->begin) {
|
if (value->collection->begin) {
|
||||||
free_json(&(value->collection->begin));
|
free_json(&(value->collection->begin));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user