[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen-unstable] tools/python/xen/lowlevel: some cleanups
# HG changeset patch # User Keir Fraser <keir.fraser@xxxxxxxxxx> # Date 1213085875 -3600 # Node ID f769baf14332a1eeea30b1403917626979ea2eb8 # Parent 09dd5492651c34f7cf863683f2ddbca868340eef tools/python/xen/lowlevel: some cleanups Mainly: malloc(n * m) -> calloc(n, m) sprintf -> snprintf Signed-off-by: Christoph Egger <Christoph.Egger@xxxxxxx> --- tools/python/xen/lowlevel/acm/acm.c | 3 +-- tools/python/xen/lowlevel/xc/xc.c | 15 ++++++++------- tools/python/xen/lowlevel/xs/xs.c | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff -r 09dd5492651c -r f769baf14332 tools/python/xen/lowlevel/acm/acm.c --- a/tools/python/xen/lowlevel/acm/acm.c Mon Jun 09 17:18:27 2008 +0100 +++ b/tools/python/xen/lowlevel/acm/acm.c Tue Jun 10 09:17:55 2008 +0100 @@ -29,10 +29,9 @@ #include <arpa/inet.h> #include <sys/ioctl.h> #include <netinet/in.h> +#include <xenctrl.h> #include <xen/xsm/acm.h> #include <xen/xsm/acm_ops.h> - -#include <xenctrl.h> #define PERROR(_m, _a...) \ fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a , \ diff -r 09dd5492651c -r f769baf14332 tools/python/xen/lowlevel/xc/xc.c --- a/tools/python/xen/lowlevel/xc/xc.c Mon Jun 09 17:18:27 2008 +0100 +++ b/tools/python/xen/lowlevel/xc/xc.c Tue Jun 10 09:17:55 2008 +0100 @@ -298,7 +298,8 @@ static PyObject *pyxc_domain_getinfo(XcO &first_dom, &max_doms) ) return NULL; - if ( (info = malloc(max_doms * sizeof(xc_dominfo_t))) == NULL ) + info = calloc(max_doms, sizeof(xc_dominfo_t)); + if (info == NULL) return PyErr_NoMemory(); nr_doms = xc_domain_getinfo(self->xc_handle, first_dom, max_doms, info); @@ -664,9 +665,9 @@ static PyObject *pyxc_get_device_group(X /* Maximum allowed siblings device number per group */ max_sdevs = 1024; - if ( (sdev_array = malloc(max_sdevs * sizeof(*sdev_array))) == NULL ) + sdev_array = calloc(max_sdevs, sizeof(*sdev_array)); + if (sdev_array == NULL) return PyErr_NoMemory(); - memset(sdev_array, 0, max_sdevs * sizeof(*sdev_array)); bdf |= (bus & 0xff) << 16; bdf |= (dev & 0x1f) << 11; @@ -687,16 +688,16 @@ static PyObject *pyxc_get_device_group(X return Py_BuildValue("s", ""); } - if ( (group_str = malloc(num_sdevs * sizeof(dev_str))) == NULL ) + group_str = calloc(num_sdevs, sizeof(dev_str)); + if (group_str == NULL) return PyErr_NoMemory(); - memset(group_str, '\0', num_sdevs * sizeof(dev_str)); for ( i = 0; i < num_sdevs; i++ ) { bus = (sdev_array[i] >> 16) & 0xff; dev = (sdev_array[i] >> 11) & 0x1f; func = (sdev_array[i] >> 8) & 0x7; - sprintf(dev_str, "%02x:%02x.%x,", bus, dev, func); + snprintf(dev_str, sizeof(dev_str), "%02x:%02x.%x,", bus, dev, func); strcat(group_str, dev_str); } @@ -1116,7 +1117,7 @@ static PyObject *pyxc_xeninfo(XcObject * if ( xc_version(self->xc_handle, XENVER_platform_parameters, &p_parms) != 0 ) return pyxc_error_to_exception(); - sprintf(str, "virt_start=0x%lx", p_parms.virt_start); + snprintf(str, sizeof(str), "virt_start=0x%lx", p_parms.virt_start); xen_pagesize = xc_version(self->xc_handle, XENVER_pagesize, NULL); if (xen_pagesize < 0 ) diff -r 09dd5492651c -r f769baf14332 tools/python/xen/lowlevel/xs/xs.c --- a/tools/python/xen/lowlevel/xs/xs.c Mon Jun 09 17:18:27 2008 +0100 +++ b/tools/python/xen/lowlevel/xs/xs.c Tue Jun 10 09:17:55 2008 +0100 @@ -415,7 +415,7 @@ static PyObject *xspy_watch(XsHandle *se if (i == PyList_Size(self->watches)) PyList_Append(self->watches, token); - sprintf(token_str, "%li", (unsigned long)token); + snprintf(token_str, sizeof(token_str), "%li", (unsigned long)token); Py_BEGIN_ALLOW_THREADS result = xs_watch(xh, path, token_str); Py_END_ALLOW_THREADS @@ -500,7 +500,7 @@ static PyObject *xspy_unwatch(XsHandle * if (!PyArg_ParseTuple(args, "sO", &path, &token)) return NULL; - sprintf(token_str, "%li", (unsigned long)token); + snprintf(token_str, sizeof(token_str), "%li", (unsigned long)token); Py_BEGIN_ALLOW_THREADS result = xs_unwatch(xh, path, token_str); Py_END_ALLOW_THREADS @@ -535,7 +535,7 @@ static PyObject *xspy_transaction_start( return NULL; } - sprintf(thstr, "%lX", (unsigned long)th); + snprintf(thstr, sizeof(thstr), "%lX", (unsigned long)th); return PyString_FromString(thstr); } _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |