From 9e823f892c4e52ccaccd9e99650d6c9a0b225bb1 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Fri, 5 Jun 2020 23:31:19 +0900 Subject: [PATCH] Refactor sv_init --- src/main.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main.c b/src/main.c index 00503a4..00bdc97 100644 --- a/src/main.c +++ b/src/main.c @@ -9,11 +9,10 @@ typedef struct SimpleVector { } SimpleVector; void sv_init(SimpleVector *sv, unsigned int capacity) { - if(!sv->data) { - sv->data = (int*)malloc(capacity * sizeof(int)); - sv->capacity = capacity; - sv->size = 0; - } + memset(sv, 0, sizeof(SimpleVector)); + sv->data = (int*)malloc(capacity * sizeof(int)); + sv->capacity = capacity; + sv->size = 0; } void sv_cleanup(SimpleVector *sv) { @@ -74,7 +73,6 @@ int is_digit_sum_equal(int a, int b) { int main(int argc, char **argv) { SimpleVector sv; - memset(&sv, 0, sizeof(SimpleVector)); sv_init(&sv, 32); int temp_i;