ia64/xen-unstable
changeset 17816:f769baf14332
tools/python/xen/lowlevel: some cleanups
Mainly:
malloc(n * m) -> calloc(n, m)
sprintf -> snprintf
Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
Mainly:
malloc(n * m) -> calloc(n, m)
sprintf -> snprintf
Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
author | Keir Fraser <keir.fraser@citrix.com> |
---|---|
date | Tue Jun 10 09:17:55 2008 +0100 (2008-06-10) |
parents | 09dd5492651c |
children | fb294e189b73 |
files | tools/python/xen/lowlevel/acm/acm.c tools/python/xen/lowlevel/xc/xc.c tools/python/xen/lowlevel/xs/xs.c |
line diff
1.1 --- a/tools/python/xen/lowlevel/acm/acm.c Mon Jun 09 17:18:27 2008 +0100 1.2 +++ b/tools/python/xen/lowlevel/acm/acm.c Tue Jun 10 09:17:55 2008 +0100 1.3 @@ -29,11 +29,10 @@ 1.4 #include <arpa/inet.h> 1.5 #include <sys/ioctl.h> 1.6 #include <netinet/in.h> 1.7 +#include <xenctrl.h> 1.8 #include <xen/xsm/acm.h> 1.9 #include <xen/xsm/acm_ops.h> 1.10 1.11 -#include <xenctrl.h> 1.12 - 1.13 #define PERROR(_m, _a...) \ 1.14 fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a , \ 1.15 errno, strerror(errno))
2.1 --- a/tools/python/xen/lowlevel/xc/xc.c Mon Jun 09 17:18:27 2008 +0100 2.2 +++ b/tools/python/xen/lowlevel/xc/xc.c Tue Jun 10 09:17:55 2008 +0100 2.3 @@ -298,7 +298,8 @@ static PyObject *pyxc_domain_getinfo(XcO 2.4 &first_dom, &max_doms) ) 2.5 return NULL; 2.6 2.7 - if ( (info = malloc(max_doms * sizeof(xc_dominfo_t))) == NULL ) 2.8 + info = calloc(max_doms, sizeof(xc_dominfo_t)); 2.9 + if (info == NULL) 2.10 return PyErr_NoMemory(); 2.11 2.12 nr_doms = xc_domain_getinfo(self->xc_handle, first_dom, max_doms, info); 2.13 @@ -664,9 +665,9 @@ static PyObject *pyxc_get_device_group(X 2.14 /* Maximum allowed siblings device number per group */ 2.15 max_sdevs = 1024; 2.16 2.17 - if ( (sdev_array = malloc(max_sdevs * sizeof(*sdev_array))) == NULL ) 2.18 + sdev_array = calloc(max_sdevs, sizeof(*sdev_array)); 2.19 + if (sdev_array == NULL) 2.20 return PyErr_NoMemory(); 2.21 - memset(sdev_array, 0, max_sdevs * sizeof(*sdev_array)); 2.22 2.23 bdf |= (bus & 0xff) << 16; 2.24 bdf |= (dev & 0x1f) << 11; 2.25 @@ -687,16 +688,16 @@ static PyObject *pyxc_get_device_group(X 2.26 return Py_BuildValue("s", ""); 2.27 } 2.28 2.29 - if ( (group_str = malloc(num_sdevs * sizeof(dev_str))) == NULL ) 2.30 + group_str = calloc(num_sdevs, sizeof(dev_str)); 2.31 + if (group_str == NULL) 2.32 return PyErr_NoMemory(); 2.33 - memset(group_str, '\0', num_sdevs * sizeof(dev_str)); 2.34 2.35 for ( i = 0; i < num_sdevs; i++ ) 2.36 { 2.37 bus = (sdev_array[i] >> 16) & 0xff; 2.38 dev = (sdev_array[i] >> 11) & 0x1f; 2.39 func = (sdev_array[i] >> 8) & 0x7; 2.40 - sprintf(dev_str, "%02x:%02x.%x,", bus, dev, func); 2.41 + snprintf(dev_str, sizeof(dev_str), "%02x:%02x.%x,", bus, dev, func); 2.42 strcat(group_str, dev_str); 2.43 } 2.44 2.45 @@ -1116,7 +1117,7 @@ static PyObject *pyxc_xeninfo(XcObject * 2.46 if ( xc_version(self->xc_handle, XENVER_platform_parameters, &p_parms) != 0 ) 2.47 return pyxc_error_to_exception(); 2.48 2.49 - sprintf(str, "virt_start=0x%lx", p_parms.virt_start); 2.50 + snprintf(str, sizeof(str), "virt_start=0x%lx", p_parms.virt_start); 2.51 2.52 xen_pagesize = xc_version(self->xc_handle, XENVER_pagesize, NULL); 2.53 if (xen_pagesize < 0 )
3.1 --- a/tools/python/xen/lowlevel/xs/xs.c Mon Jun 09 17:18:27 2008 +0100 3.2 +++ b/tools/python/xen/lowlevel/xs/xs.c Tue Jun 10 09:17:55 2008 +0100 3.3 @@ -415,7 +415,7 @@ static PyObject *xspy_watch(XsHandle *se 3.4 if (i == PyList_Size(self->watches)) 3.5 PyList_Append(self->watches, token); 3.6 3.7 - sprintf(token_str, "%li", (unsigned long)token); 3.8 + snprintf(token_str, sizeof(token_str), "%li", (unsigned long)token); 3.9 Py_BEGIN_ALLOW_THREADS 3.10 result = xs_watch(xh, path, token_str); 3.11 Py_END_ALLOW_THREADS 3.12 @@ -500,7 +500,7 @@ static PyObject *xspy_unwatch(XsHandle * 3.13 if (!PyArg_ParseTuple(args, "sO", &path, &token)) 3.14 return NULL; 3.15 3.16 - sprintf(token_str, "%li", (unsigned long)token); 3.17 + snprintf(token_str, sizeof(token_str), "%li", (unsigned long)token); 3.18 Py_BEGIN_ALLOW_THREADS 3.19 result = xs_unwatch(xh, path, token_str); 3.20 Py_END_ALLOW_THREADS 3.21 @@ -535,7 +535,7 @@ static PyObject *xspy_transaction_start( 3.22 return NULL; 3.23 } 3.24 3.25 - sprintf(thstr, "%lX", (unsigned long)th); 3.26 + snprintf(thstr, sizeof(thstr), "%lX", (unsigned long)th); 3.27 return PyString_FromString(thstr); 3.28 } 3.29