From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53231) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aHawx-00084r-C8 for qemu-devel@nongnu.org; Fri, 08 Jan 2016 12:35:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aHaww-00049x-9n for qemu-devel@nongnu.org; Fri, 08 Jan 2016 12:35:43 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58198) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aHaww-00049W-42 for qemu-devel@nongnu.org; Fri, 08 Jan 2016 12:35:42 -0500 References: <1452242274-8345-1-git-send-email-caoj.fnst@cn.fujitsu.com> <1452242274-8345-2-git-send-email-caoj.fnst@cn.fujitsu.com> From: Eric Blake Message-ID: <568FF368.7080308@redhat.com> Date: Fri, 8 Jan 2016 10:35:36 -0700 MIME-Version: 1.0 In-Reply-To: <1452242274-8345-2-git-send-email-caoj.fnst@cn.fujitsu.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="72fsvlKIAUSoKigqRJ34is7KLKsh9fPxl" Subject: Re: [Qemu-devel] [PATCH v4 1/5] Use qemu_strtoul instead of strtol List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Cao jin , qemu-devel@nongnu.org Cc: stefano.stabellini@eu.citrix.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --72fsvlKIAUSoKigqRJ34is7KLKsh9fPxl Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 01/08/2016 01:37 AM, Cao jin wrote: > strtol() don`t guarantee errno to be ERANGE on overflow. I stand slightly corrected: C99 requires ERANGE on overflow, but not EINVAL; it is POSIX that adds EINVAL, but does not properly require it. At any rate, my main point was that errno is not always properly set by all strtol implementations, and furthermore that you can't rely on it being set to a sane value if you didn't pre-set it to 0. > This wrapper returns either -EINVAL or the errno set by strtol() > function (e.g -ERANGE). The subject line doesn't start with a topic. Maybe a better commit message would be: xen: Use qemu_strtoul instead of strtol No need to roll our own (with slightly incorrect handling of errno), when we can use the common version. >=20 > Signed-off-by: Cao jin > --- > hw/xen/xen-host-pci-device.c | 11 +++-------- > 1 file changed, 3 insertions(+), 8 deletions(-) > buf[rc] =3D 0; > - value =3D strtol(buf, &endptr, base); > - if (endptr =3D=3D buf || *endptr !=3D '\n') { > - rc =3D -1; > - } else if ((value =3D=3D LONG_MIN || value =3D=3D LONG_MAX) && err= no =3D=3D ERANGE) { > - rc =3D -errno; > - } else { > - rc =3D 0; > + rc =3D qemu_strtoul(buf, &endptr, base, &value); Why did you switch from strtol() to qemu_strtoul()? Was signed parsing incorrect, and unsigned parsing a bug fix? If so, please mention it in the commit message as intentional. Otherwise, use qemu_strtol() (and adjust the commit message accordingly). --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --72fsvlKIAUSoKigqRJ34is7KLKsh9fPxl Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJWj/NoAAoJEKeha0olJ0NqA94H/3hfHnKliEQO/BgeNgE5HMmJ Eh+DhHMy6HjjNtk1oh0v8wh8PSmnPfyWQG0ErpAK5olVP1aG6mqceB32fFGE+qkY WgnMQJ+Xx5aAzpaQhTEB2o4Le/3efvYk9jPzO0IrHfSE+vCWXaSyXeREs9KUvUB+ thjMVVDzcEKN0GOW4dz+wNrUwxlDhF9LSSfsmiMy5892mU2TvreiSk72QKO7OuZO uVQVdTSeO0Tf1DS9BL3KJAMV9L8UFLHWj54C0iU2d5suF8d2uU5nTgckJThSvoQD Xt9n7uJgxGhVYnw7DOQ9m4y7l7NZftDFs/kVWuOQKbZx6ZgJyTLYR+Sr+nACiLs= =lN56 -----END PGP SIGNATURE----- --72fsvlKIAUSoKigqRJ34is7KLKsh9fPxl--