Skip to content

Commit

Permalink
Minor fix to avoid ZVector to add NULL pointers to the array
Browse files Browse the repository at this point in the history
  • Loading branch information
pzaino committed Nov 26, 2023
1 parent 2580f34 commit 487b2ec
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/zvector.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ static void *safe_strncpy(const char * const str_src,
char tmp_dst[max_len];
tmp_dst[sizeof(tmp_dst) - 1] = 0;

strncpy(tmp_dst, str_src, sizeof(tmp_dst));
strncpy(tmp_dst, str_src, sizeof(tmp_dst) - 1);

tmp_dst[sizeof(tmp_dst) - 1] = 0;

Expand All @@ -298,7 +298,7 @@ static void *safe_strncpy(const char * const str_src,
{
log_msg(ZVLP_ERROR, "Error: %*i, %s\n", 8, -1000, "Out of memory!");
} else {
strncpy((char *)str_dst, tmp_dst, sizeof(tmp_dst));
strncpy((char *)str_dst, tmp_dst, sizeof(tmp_dst) - 1);
((char *)str_dst)[sizeof(tmp_dst)] = 0;
}
return str_dst;
Expand Down Expand Up @@ -1131,6 +1131,10 @@ static zvect_retval p_vect_put_at(ivector v, const void *value,
// inline implementation for all add(s):
static inline zvect_retval p_vect_add_at(ivector v, const void *value,
const zvect_index i) {
// Check if the item is NULL:
if (value == NULL)
return 0;

zvect_index idx = i;

// Get vector size:
Expand Down

0 comments on commit 487b2ec

Please sign in to comment.