From 05e88a2cc8ea0878f226d8064cbc8996c86fbdba Mon Sep 17 00:00:00 2001 From: Gabriele Bartolini Date: Thu, 16 Dec 2010 22:21:27 +0100 Subject: [PATCH] removed strncmp improper usage, initialise values asap --- config.c | 6 +++--- dbutils.c | 34 +++++++++++++++++----------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/config.c b/config.c index 4052dd7e..3bedcaff 100644 --- a/config.c +++ b/config.c @@ -30,11 +30,11 @@ parse_config(const char *config_file, char *cluster_name, int *node, char *conni parse_line(buff, name, value); /* Copy into correct entry in parameters struct */ - if (strncmp(name, "cluster", 7) == 0) + if (strcmp(name, "cluster") == 0) strncpy (cluster_name, value, MAXLEN); - else if (strncmp(name, "node", 4) == 0) + else if (strcmp(name, "node") == 0) *node = atoi(value); - else if (strncmp(name, "conninfo", 8) == 0) + else if (strcmp(name, "conninfo") == 0) strncpy (conninfo, value, MAXLEN); else printf ("WARNING: %s/%s: Unknown name/value pair!\n", name, value); diff --git a/dbutils.c b/dbutils.c index 8287e1b0..96a7111d 100644 --- a/dbutils.c +++ b/dbutils.c @@ -11,20 +11,20 @@ PGconn * establishDBConnection(const char *conninfo, const bool exit_on_error) { - PGconn *conn; - /* Make a connection to the database */ - conn = PQconnectdb(conninfo); - /* Check to see that the backend connection was successfully made */ - if ((PQstatus(conn) != CONNECTION_OK)) - { - fprintf(stderr, "Connection to database failed: %s", + /* Make a connection to the database */ + PGconn *conn = PQconnectdb(conninfo); + + /* Check to see that the backend connection was successfully made */ + if ((PQstatus(conn) != CONNECTION_OK)) + { + fprintf(stderr, "Connection to database failed: %s", PQerrorMessage(conn)); if (exit_on_error) { - PQfinish(conn); + PQfinish(conn); exit(1); } - } + } return conn; } @@ -34,17 +34,17 @@ establishDBConnection(const char *conninfo, const bool exit_on_error) bool is_standby(PGconn *conn) { - PGresult *res; + PGresult *res; bool result; - res = PQexec(conn, "SELECT pg_is_in_recovery()"); - if (PQresultStatus(res) != PGRES_TUPLES_OK) - { - fprintf(stderr, "Can't query server mode: %s", PQerrorMessage(conn)); - PQclear(res); - PQfinish(conn); + res = PQexec(conn, "SELECT pg_is_in_recovery()"); + if (PQresultStatus(res) != PGRES_TUPLES_OK) + { + fprintf(stderr, "Can't query server mode: %s", PQerrorMessage(conn)); + PQclear(res); + PQfinish(conn); exit(1); - } + } if (strcmp(PQgetvalue(res, 0, 0), "f") == 0) result = false;