From: Christoph Egger Subject: [PATCH][TOOLS] xenstat: some cleanups Date: Tue, 10 Jun 2008 14:51:46 +0200 Message-ID: <200806101451.47117.Christoph.Egger@amd.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Boundary-00=_jjnTIvFrx+854gv" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org --Boundary-00=_jjnTIvFrx+854gv Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hi! Attached patch does some cleanups: sprintf -> snprintf malloc(n * m) -> calloc(n, m) get rid of a cast Signed-off-by: Christoph Egger =2D-=20 AMD Saxony, Dresden, Germany Operating System Research Center Legal Information: AMD Saxony Limited Liability Company & Co. KG Sitz (Gesch=E4ftsanschrift): Wilschdorfer Landstr. 101, 01109 Dresden, Deutschland Registergericht Dresden: HRA 4896 vertretungsberechtigter Komplement=E4r: AMD Saxony LLC (Sitz Wilmington, Delaware, USA) Gesch=E4ftsf=FChrer der AMD Saxony LLC: Dr. Hans-R. Deppe, Thomas McCoy --Boundary-00=_jjnTIvFrx+854gv Content-Type: text/x-diff; charset="us-ascii"; name="tools_xenstat.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="tools_xenstat.diff" diff -r 7a0f1bf86516 tools/xenstat/libxenstat/src/xenstat_linux.c --- a/tools/xenstat/libxenstat/src/xenstat_linux.c Tue Jun 10 09:27:01 2008 +0100 +++ b/tools/xenstat/libxenstat/src/xenstat_linux.c Tue Jun 10 14:39:20 2008 +0200 @@ -165,7 +165,8 @@ static int read_attributes_vbd(const cha 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); diff -r 7a0f1bf86516 tools/xenstat/xentop/xentop.c --- a/tools/xenstat/xentop/xentop.c Tue Jun 10 09:27:01 2008 +0100 +++ b/tools/xenstat/xentop/xentop.c Tue Jun 10 14:39:20 2008 +0200 @@ -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"); --Boundary-00=_jjnTIvFrx+854gv Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --Boundary-00=_jjnTIvFrx+854gv--