Skip to content

Commit 5f02a5b

Browse files
committed
Update to_string
1 parent 165d768 commit 5f02a5b

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/string_buffer.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,17 +271,18 @@ char *string_buffer_to_string(struct StringBuffer *buffer)
271271
return("");
272272
}
273273

274-
size_t string_size = buffer->content_size * sizeof(char);
275-
char *string_copy = malloc(string_size);
274+
size_t content_size = buffer->content_size;
275+
size_t memory_size = content_size * sizeof(char);
276+
char *string_copy = malloc(memory_size);
276277
if (string_copy == NULL)
277278
{
278279
return(NULL);
279280
}
280281

281-
buffer->value[string_size] = 0;
282+
buffer->value[content_size] = 0;
282283

283-
string_copy = strcpy(string_copy, buffer->value);
284-
string_copy[string_size] = 0;
284+
string_copy = strncpy(string_copy, buffer->value, content_size);
285+
string_copy[content_size] = 0;
285286

286287
return(string_copy);
287288
}

0 commit comments

Comments
 (0)