Skip to content

Commit e6990ff

Browse files
authored
Merge pull request #3 from sagiegurari/dev
0.1.2
2 parents 165d768 + 90b7579 commit e6990ff

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## CHANGELOG
22

3+
### v0.1.2 (2020-05-31)
4+
5+
* Memory copy changes to improve stability and performance.
6+
37
### v0.1.1 (2020-04-23)
48

59
* New string_buffer_is_released function.

src/string_buffer.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,17 +271,19 @@ 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;
283+
string_copy[content_size] = 0;
282284

283-
string_copy = strcpy(string_copy, buffer->value);
284-
string_copy[string_size] = 0;
285+
memcpy(string_copy, buffer->value, memory_size);
286+
string_copy[content_size] = 0;
285287

286288
return(string_copy);
287289
}

0 commit comments

Comments
 (0)