diff options
author | Keir Fraser <keir.fraser@citrix.com> | 2008-06-10 09:17:55 +0100 |
---|---|---|
committer | Keir Fraser <keir.fraser@citrix.com> | 2008-06-10 09:17:55 +0100 |
commit | d32efbebf6592811a52128a64b9706cb1d67557c (patch) | |
tree | 198905d8e2e54c48019e57f1da70ea1ed3eaa357 /tools/python | |
parent | 7139eef57f595d19785b979dfbfb7838853f7e63 (diff) | |
download | xen-d32efbebf6592811a52128a64b9706cb1d67557c.tar.gz xen-d32efbebf6592811a52128a64b9706cb1d67557c.tar.bz2 xen-d32efbebf6592811a52128a64b9706cb1d67557c.zip |
tools/python/xen/lowlevel: some cleanups
Mainly:
malloc(n * m) -> calloc(n, m)
sprintf -> snprintf
Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
Diffstat (limited to 'tools/python')
-rw-r--r-- | tools/python/xen/lowlevel/acm/acm.c | 3 | ||||
-rw-r--r-- | tools/python/xen/lowlevel/xc/xc.c | 15 | ||||
-rw-r--r-- | tools/python/xen/lowlevel/xs/xs.c | 6 |
3 files changed, 12 insertions, 12 deletions
diff --git a/tools/python/xen/lowlevel/acm/acm.c b/tools/python/xen/lowlevel/acm/acm.c index 1daa4e626a..1762aa2fda 100644 --- a/tools/python/xen/lowlevel/acm/acm.c +++ b/tools/python/xen/lowlevel/acm/acm.c @@ -29,11 +29,10 @@ #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 , \ errno, strerror(errno)) diff --git a/tools/python/xen/lowlevel/xc/xc.c b/tools/python/xen/lowlevel/xc/xc.c index 51e3ec79c9..af5ac34cd8 100644 --- a/tools/python/xen/lowlevel/xc/xc.c +++ b/tools/python/xen/lowlevel/xc/xc.c @@ -298,7 +298,8 @@ static PyObject *pyxc_domain_getinfo(XcObject *self, &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(XcObject *self, /* 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(XcObject *self, 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 *self) 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 --git a/tools/python/xen/lowlevel/xs/xs.c b/tools/python/xen/lowlevel/xs/xs.c index d05365cb16..6497126d2d 100644 --- a/tools/python/xen/lowlevel/xs/xs.c +++ b/tools/python/xen/lowlevel/xs/xs.c @@ -415,7 +415,7 @@ static PyObject *xspy_watch(XsHandle *self, PyObject *args) 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 *self, PyObject *args) 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(XsHandle *self) return NULL; } - sprintf(thstr, "%lX", (unsigned long)th); + snprintf(thstr, sizeof(thstr), "%lX", (unsigned long)th); return PyString_FromString(thstr); } |