[Libvir] [PATCH] Fix string handling in virDomain{Get, Set}SchedulerParameters

Jim Meyering jim at meyering.net
Fri Jun 22 10:19:20 UTC 2007


"Richard W.M. Jones" <rjones at redhat.com> wrote:
> Let's try this updated patch.

Hi Rich,

It'd be nice to factor those "cap" and "weight" literal strings all
the way out, so each is defined in exactly one place.
Either with a file-scoped const declaration, e.g.,
  static const char *cap_str = "cap";
or a cpp define:
  #define CAP_STR "cap";

Then, there's no risk (however small) of changing
one of the literal strings without changing its mate.

> 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
...
> +		strncpy (params[0].field, "weight", VIR_DOMAIN_SCHED_FIELD_LENGTH);
...
> +		strncpy (params[1].field, "cap", VIR_DOMAIN_SCHED_FIELD_LENGTH);
...
> +                if (STREQ (params[i].field, "weight") &&
...
> +		} else if (STREQ (params[i].field, "cap") &&




More information about the libvir-list mailing list