File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments