Skip to content

Commit c15b11c

Browse files
Fixed bug with create_string not creating copy of the string array and having incorrect buffer size
fixup! Fixed bug with create_string not creating copy of the string array
1 parent b6364c5 commit c15b11c

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

custom_string.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
string_t *create_string(char *chars, int buffer_size) {
66
string_t *string = (string_t *) malloc(sizeof(string_t));
7-
string->chars = chars;
7+
string->chars = (char *) malloc(buffer_size * sizeof(char));
8+
strncpy(string->chars, chars, buffer_size);
89
string->length = (int) strlen(chars);
910
string->capacity = buffer_size;
1011
return string;

0 commit comments

Comments
 (0)