From 634c0fd975c181760f9efcd80a6252443e2e9179 Mon Sep 17 00:00:00 2001 From: Bernardo Date: Wed, 22 Mar 2023 20:49:02 -0300 Subject: [PATCH] fixed clone methods --- tps/gabaritos/tp02/TP02Q02 - Classe em C/Q02.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tps/gabaritos/tp02/TP02Q02 - Classe em C/Q02.c b/tps/gabaritos/tp02/TP02Q02 - Classe em C/Q02.c index b07f4e9..7eada1f 100644 --- a/tps/gabaritos/tp02/TP02Q02 - Classe em C/Q02.c +++ b/tps/gabaritos/tp02/TP02Q02 - Classe em C/Q02.c @@ -66,7 +66,7 @@ char* str_substring(const char* const str, const size_t start, const size_t end) } char* str_clone(const char* const str) { - size_t len = str_len(str); + size_t len = str_len(str) + 1; char* copy = (char*)malloc(len * sizeof(char)); for(size_t i = 0; i < len; i++) copy[i] = str[i]; return copy; @@ -208,15 +208,15 @@ SWCharacter SWCharacter_from_file(const char* const path) { SWCharacter swc_clone(const SWCharacter* const self) { SWCharacter other; - other.name = self->name; + other.name = str_clone(self->name); other.height = self->height; other.mass = self->mass; - other.hair_color = self->hair_color; - other.skin_color = self->skin_color; - other.eye_color = self->eye_color; - other.birth_year = self->birth_year; - other.gender = self->gender; - other.homeworld = self->homeworld; + other.hair_color = str_clone(self->hair_color); + other.skin_color = str_clone(self->skin_color); + other.eye_color = str_clone(self->eye_color); + other.birth_year = str_clone(self->birth_year); + other.gender = str_clone(self->gender); + other.homeworld = str_clone(self->homeworld); return other; }