From 644bdbcedf17d980107c7a3276f6d3d061820668 Mon Sep 17 00:00:00 2001 From: bufferoverflowin Date: Thu, 16 Feb 2017 13:21:58 +0100 Subject: [PATCH] avoiding ugly nested conditionals --- vector.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/vector.c b/vector.c index 5094842..03fff9f 100644 --- a/vector.c +++ b/vector.c @@ -5,20 +5,23 @@ struct node* node_start = NULL; void vector_push(char* node_path) { - if(node_path != NULL) { - url_t* url_parts = utils_format_url(node_path); - if(url_parts != NULL) { - struct node* node_link = malloc(sizeof(struct node)); - ZERO_BUF(node_link); + if(node_path == NULL) + return; + + url_t* url_parts = utils_format_url(node_path); + + if(url_parts != NULL) + return; + + struct node* node_link = malloc(sizeof(struct node)); + ZERO_BUF(node_link); - node_link->host = url_parts->url_host; - node_link->path = url_parts->url_uri; - node_link->next_ptr = node_start; - - node_start = node_link; - } - free(url_parts); - } + node_link->host = url_parts->url_host; + node_link->path = url_parts->url_uri; + node_link->next_ptr = node_start; + node_start = node_link; + + free(url_parts); } static void vector_destory_element(struct node* element) {