]> git.proxmox.com Git - mirror_corosync.git/commitdiff
quorumtool: fix some var init and checks
authorFabio M. Di Nitto <fdinitto@redhat.com>
Tue, 7 Feb 2012 10:02:51 +0000 (11:02 +0100)
committerFabio M. Di Nitto <fdinitto@redhat.com>
Thu, 9 Feb 2012 15:49:25 +0000 (16:49 +0100)
Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
Reviewed-by: Steven Dake <sdake@redhat.com>
tools/corosync-quorumtool.c

index 2b8c136dc8910466e447de225f75fbe6440b653e..0f37d3ee340f25d9ceaca2760d3f24d02825d179 100644 (file)
@@ -142,10 +142,9 @@ static void show_usage(const char *name)
 static int get_quorum_type(char *quorum_type, size_t quorum_type_len)
 {
        int err;
-       char *str;
+       char *str = NULL;
 
        if ((!quorum_type) || (quorum_type_len <= 0)) {
-               errno = EINVAL;
                return -1;
        }
 
@@ -157,6 +156,10 @@ static int get_quorum_type(char *quorum_type, size_t quorum_type_len)
                goto out;
        }
 
+       if (!str) {
+               return -1;
+       }
+
        strncpy(quorum_type, str, quorum_type_len - 1);
        free(str);
 
@@ -174,6 +177,8 @@ static int using_votequorum(void)
        char quorumtype[256];
        int using_voteq;
 
+       memset(quorumtype, 0, sizeof(quorumtype));
+
        if (get_quorum_type(quorumtype, sizeof(quorumtype))) {
                return -1;
        }
@@ -311,14 +316,16 @@ static int display_quorum_data(int is_quorate, int loop)
 {
        struct votequorum_info info;
        int err;
-       char quorum_type[256];
+       char quorumtype[256];
+
+       memset(quorumtype, 0, sizeof(quorumtype));
 
        if (!loop) {
                printf("Version:          %s\n", VERSION);
-               if (get_quorum_type(quorum_type, sizeof(quorum_type))) {
-                       strncpy(quorum_type, "Not configured", sizeof(quorum_type) - 1);
+               if (get_quorum_type(quorumtype, sizeof(quorumtype))) {
+                       strncpy(quorumtype, "Not configured", sizeof(quorumtype) - 1);
                }
-               printf("Quorum type:      %s\n", quorum_type);
+               printf("Quorum type:      %s\n", quorumtype);
        }
 
        printf("Nodes:            %d\n", g_view_list_entries);