some cleanups
PATCH 1/1 some cleanups
Hi!
Attached patch makes some cleanups
in tools/pyton/xen/lowlevel/
Mainly:
malloc(n * m) -> calloc(n, m)
sprintf -> snprintf
Signed-off-by Christoph Egger <[email protected]>
Signature · 12 lines
AMD Saxony, Dresden, Germany Operating System Research Center Legal Information: AMD Saxony Limited Liability Company & Co. KG Sitz (Geschäftsanschrift): Wilschdorfer Landstr. 101, 01109 Dresden, Deutschland Registergericht Dresden: HRA 4896 vertretungsberechtigter Komplementär: AMD Saxony LLC (Sitz Wilmington, Delaware, USA) Geschäftsführer der AMD Saxony LLC: Dr. Hans-R. Deppe, Thomas McCoy
tools/python/xen/lowlevel/acm/acm.c +1 -2
@@ -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 , \
tools/python/xen/lowlevel/xc/xc.c +8 -7
@@ -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(Xreturn 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 )
tools/python/xen/lowlevel/xs/xs.c +3 -3
@@ -415,7 +415,7 @@ static PyObject *xspy_watch(XsHandle *seif (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-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel