Jim Meyering wrote:
"Richard W.M. Jones" <rjones@xxxxxxxxxx> wrote:This small patch fixes some bugs in the handling of the field string in virDomainGetSchedulerParameters and makes a similar pre-emptive fix to virDomainSetSchedulerParameters. Also, please don't use !strcmp(a,b), because it confuses me. Better is to write strcmp(a,b) == 0 to mean "strings match" and strcmp(a,b) != 0 to mean "strings don't match".Hi Rich, I agree, but prefer to avoid direct use of strcmp altogether. I use this definition: #define STREQ(a, b) (strcmp (a, b) == 0) Then all uses are either STREQ(a, b) or ! STREQ(a, b)
Let's try this updated patch. Rich. -- Emerging Technologies, Red Hat - http://et.redhat.com/~rjones/ Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SL4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 03798903
Index: src/internal.h =================================================================== RCS file: /data/cvs/libvirt/src/internal.h,v retrieving revision 1.42 diff -u -p -r1.42 internal.h --- src/internal.h 15 Jun 2007 08:18:55 -0000 1.42 +++ src/internal.h 22 Jun 2007 10:01:27 -0000 @@ -31,6 +31,10 @@ extern "C" { #include <ansidecl.h> #endif +/* String equality tests, suggested by Jim Meyering. */ +#define STREQ(a,b) (strcmp((a),(b)) == 0) +#define STRCASEEQ(a,b) (strcasecmp((a),(b)) == 0) + /** * ATTRIBUTE_UNUSED: * Index: src/xen_internal.c =================================================================== RCS file: /data/cvs/libvirt/src/xen_internal.c,v retrieving revision 1.79 diff -u -p -r1.79 xen_internal.c --- src/xen_internal.c 6 Jun 2007 12:24:31 -0000 1.79 +++ src/xen_internal.c 22 Jun 2007 10:01:29 -0000 @@ -1071,8 +1071,6 @@ xenHypervisorGetSchedulerParameters(virD virSchedParameterPtr params, int *nparams) { xenUnifiedPrivatePtr priv; - char str_weight[] ="weight"; - char str_cap[] ="cap"; if ((domain == NULL) || (domain->conn == NULL)) { virXenErrorFunc(VIR_ERR_INTERNAL_ERROR, __FUNCTION__, @@ -1126,11 +1124,13 @@ xenHypervisorGetSchedulerParameters(virD if (ret < 0) return(-1); - strncpy(params[0].field, str_weight, strlen(str_weight)); + strncpy (params[0].field, "weight", VIR_DOMAIN_SCHED_FIELD_LENGTH); + params[0].field[VIR_DOMAIN_SCHED_FIELD_LENGTH-1] = '\0'; params[0].type = VIR_DOMAIN_SCHED_FIELD_UINT; params[0].value.ui = op_dom.u.getschedinfo.u.credit.weight; - strncpy(params[1].field, str_cap, strlen(str_cap)); + strncpy (params[1].field, "cap", VIR_DOMAIN_SCHED_FIELD_LENGTH); + params[1].field[VIR_DOMAIN_SCHED_FIELD_LENGTH-1] = '\0'; params[1].type = VIR_DOMAIN_SCHED_FIELD_UINT; params[1].value.ui = op_dom.u.getschedinfo.u.credit.cap; @@ -1161,8 +1161,6 @@ xenHypervisorSetSchedulerParameters(virD { int i; xenUnifiedPrivatePtr priv; - char str_weight[] ="weight"; - char str_cap[] ="cap"; if ((domain == NULL) || (domain->conn == NULL)) { virXenErrorFunc (VIR_ERR_INTERNAL_ERROR, __FUNCTION__, @@ -1227,11 +1225,11 @@ xenHypervisorSetSchedulerParameters(virD op_dom.u.getschedinfo.u.credit.cap = (uint16_t)~0U; for (i = 0; i < nparams; i++) { - if (!strncmp(params[i].field,str_weight,strlen(str_weight)) && + if (STREQ (params[i].field, "weight") && params[i].type == VIR_DOMAIN_SCHED_FIELD_UINT) { op_dom.u.getschedinfo.u.credit.weight = params[i].value.ui; weight_set = 1; - } else if (!strncmp(params[i].field,str_cap,strlen(str_cap)) && + } else if (STREQ (params[i].field, "cap") && params[i].type == VIR_DOMAIN_SCHED_FIELD_UINT) { op_dom.u.getschedinfo.u.credit.cap = params[i].value.ui; cap_set = 1;
Attachment:
smime.p7s
Description: S/MIME Cryptographic Signature