From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dario Faggioli Subject: Re: [PATCH] xl: convert vcpuid to signed in main_vcpupin() Date: Wed, 3 Sep 2014 18:42:48 +0200 Message-ID: <1409762568.2673.130.camel@Solace.lan> References: <20140820153600.20604.97575.stgit@Solace.lan> <1409752371.23789.22.camel@kazak.uk.xensource.com> <1409757629.2673.77.camel@Solace.lan> <1409760577.15505.13.camel@kazak.uk.xensource.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1413650100044799962==" Return-path: Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XPDeA-0000br-LF for xen-devel@lists.xenproject.org; Wed, 03 Sep 2014 16:43:07 +0000 In-Reply-To: <1409760577.15505.13.camel@kazak.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Ian Campbell Cc: xen-devel , Ian Jackson List-Id: xen-devel@lists.xenproject.org --===============1413650100044799962== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-h7hbNcWKcy7KggW6RxmE" --=-h7hbNcWKcy7KggW6RxmE Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On mer, 2014-09-03 at 17:09 +0100, Ian Campbell wrote: > On Wed, 2014-09-03 at 17:20 +0200, Dario Faggioli wrote: > >=20 > > > > Signed-off-by: Dario Faggioli > > > > --- > > > > tools/libxl/xl_cmdimpl.c | 14 +++++++------- > > > > 1 file changed, 7 insertions(+), 7 deletions(-) > > > >=20 > > > > diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c > > > > index f1c136a..a29a579 100644 > > > > --- a/tools/libxl/xl_cmdimpl.c > > > > +++ b/tools/libxl/xl_cmdimpl.c > > > > @@ -4601,8 +4601,9 @@ int main_vcpupin(int argc, char **argv) > > > > libxl_vcpuinfo *vcpuinfo; > > > > libxl_bitmap cpumap_hard, cpumap_soft;; > > > > libxl_bitmap *soft =3D &cpumap_soft, *hard =3D &cpumap_hard; > > > > - uint32_t vcpuid, domid; > > > > const char *vcpu, *hard_str, *soft_str; > > > > + uint32_t domid; > > > > + long vcpuid; > > >=20 > > > I think an int would be sufficiently large for this. > > >=20 > > The only reason why I used a long is that the function used to do the > > actual conversion is strtol(), which returns a long. >=20 > Can't it use atoi? >=20 =46rom atoi(3): "The behavior is the same as strtol(nptr, NULL, 10); except that atoi() does not detect errors." While the current code uses some of the strtol() error handling capabilities: /* Figure out with which vCPU we are dealing with */ = =20 vcpuid =3D strtoul(vcpu, &endptr, 10); = =20 if (vcpu =3D=3D endptr) { = =20 if (strcmp(vcpu, "all")) { = =20 fprintf(stderr, "Error: Invalid argument.\n"); = =20 goto out; = =20 } = =20 vcpuid =3D -1; = =20 } I can try to reorganize the code a bit but, without being sure that the passed string, if not the string "all", is an actual number (which, AFAIUI, is what strtol() gives me that atoi() doesn't), I don't think we can be as precise in error detection/reporting as we are now (I just double checked, and i=3Datoi("foo") means i becomes 0). I can probably combine atoi() and (something like) isdigit(vcpu[0]) to get to something similar, but at that point, I think I like strtol() better. Let me know. Regards, Dario --=20 <> (Raistlin Majere) ----------------------------------------------------------------- Dario Faggioli, Ph.D, http://about.me/dario.faggioli Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK) --=-h7hbNcWKcy7KggW6RxmE Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iEYEABECAAYFAlQHRQkACgkQk4XaBE3IOsRCgQCgiuQxQDMuBwZBXAOXr6eLFN4Q 5dwAoJlVyNJCX/sCqDUYWRi0IEN9kj0a =B2d8 -----END PGP SIGNATURE----- --=-h7hbNcWKcy7KggW6RxmE-- --===============1413650100044799962== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --===============1413650100044799962==--