xenstat: some cleanups
authorKeir Fraser <keir.fraser@citrix.com>
Tue, 10 Jun 2008 13:15:53 +0000 (14:15 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Tue, 10 Jun 2008 13:15:53 +0000 (14:15 +0100)
 sprintf -> snprintf
 malloc(n * m) -> calloc(n, m)
 get rid of a cast

Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
tools/xenstat/libxenstat/src/xenstat_linux.c
tools/xenstat/xentop/xentop.c

index 46f8bb76dfecbb683a71122524b150d5e1170d7e..69f483e8edc415aeadf0edc7efb26639f505fe11 100644 (file)
@@ -165,7 +165,8 @@ static int read_attributes_vbd(const char *vbd_directory, const char *what, char
        static char file_name[80];
        int fd, num_read;
 
-       sprintf(file_name, "%s/%s/%s", SYSFS_VBD_PATH, vbd_directory, what);
+       snprintf(file_name, sizeof(file_name), "%s/%s/%s",
+               SYSFS_VBD_PATH, vbd_directory, what);
        fd = open(file_name, O_RDONLY, 0);
        if (fd==-1) return -1;
        num_read = read(fd, ret, cap - 1);
index 52fb343376b65ba3abc96203f544025dbe5d2070..4d85e64ff85bde86f85aec96f84ae6180e74ddc7 100644 (file)
@@ -755,10 +755,11 @@ void do_summary(void)
        unsigned i, num_domains = 0;
        unsigned long long used = 0;
        xenstat_domain *domain;
+       time_t curt;
 
        /* Print program name, current time, and number of domains */
-       strftime(time_str, TIME_STR_LEN, TIME_STR_FORMAT,
-                localtime((const time_t *)&curtime.tv_sec));
+       curt = curtime.tv_sec;
+       strftime(time_str, TIME_STR_LEN, TIME_STR_FORMAT, localtime(&curt));
        num_domains = xenstat_node_num_domains(cur_node);
        ver_str = xenstat_node_xen_version(cur_node);
        print("xentop - %s   Xen %s\n", time_str, ver_str);
@@ -978,7 +979,7 @@ static void top(void)
        /* Count the number of domains for which to report data */
        num_domains = xenstat_node_num_domains(cur_node);
 
-       domains = malloc(num_domains*sizeof(xenstat_domain *));
+       domains = calloc(num_domains, sizeof(xenstat_domain *));
        if(domains == NULL)
                fail("Failed to allocate memory\n");