diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2023-05-13 10:58:41 +0200 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2023-05-13 11:37:46 +0200 |
commit | cd917f48454875ad6b7fc69455281d72760c44ee (patch) | |
tree | 70a7a43fe43b7f893468f9120def5513774a242c /src/client.c | |
parent | add command module to handle request-response communications (diff) | |
download | cimple-cd917f48454875ad6b7fc69455281d72760c44ee.tar.gz cimple-cd917f48454875ad6b7fc69455281d72760c44ee.zip |
best practices & coding style fixes
* I don't really need to declare all variables at the top of the
function anymore.
* Default-initialize variables more.
* Don't set the output parameter until the object is completely
constructed.
Diffstat (limited to 'src/client.c')
-rw-r--r-- | src/client.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/client.c b/src/client.c index 14eab14..b321b91 100644 --- a/src/client.c +++ b/src/client.c @@ -18,21 +18,20 @@ struct client { int client_create(struct client **_client, const struct settings *settings) { - struct client *client; int ret = 0; - *_client = malloc(sizeof(struct client)); - if (!*_client) { + struct client *client = malloc(sizeof(struct client)); + if (!client) { log_errno("malloc"); return -1; } - client = *_client; ret = net_connect(settings->host, settings->port); if (ret < 0) goto free; client->fd = ret; + *_client = client; return ret; free: @@ -49,8 +48,7 @@ void client_destroy(struct client *client) int client_main(const struct client *client, const char **argv) { - struct msg *request; - struct msg *response; + struct msg *request = NULL, *response = NULL; int ret = 0; ret = msg_from_argv(&request, argv); @@ -61,8 +59,9 @@ int client_main(const struct client *client, const char **argv) if (ret < 0) goto free_request; - if (msg_is_error(response)) { + if (!msg_is_success(response)) { log_err("Server failed to process the request\n"); + msg_dump(response); ret = -1; goto free_response; } |