Received: from eggs.gnu.org ([208.118.235.92]:36477) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tvxuw-00026a-Al for qemu-devel@nongnu.org; Thu, 17 Jan 2013 17:26:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tvxuv-0005bB-8F for qemu-devel@nongnu.org; Thu, 17 Jan 2013 17:26:38 -0500 Received: from mx1.redhat.com ([209.132.183.28]:61953) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tvv4K-0006tv-2w for qemu-devel@nongnu.org; Thu, 17 Jan 2013 14:24:08 -0500 Date: Thu, 17 Jan 2013 17:25:41 -0200 From: Eduardo Habkost Message-ID: <20130117192541.GK20133@otherpad.lan.raisama.net> References: <20130117185042.GQ10683@otherpad.lan.raisama.net> <1358449610-16466-1-git-send-email-ehabkost@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1358449610-16466-1-git-send-email-ehabkost@redhat.com> Subject: Re: [Qemu-devel] [PATCH 1/8 v4] cutils: unsigned int parsing functions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Laszlo Ersek , Chegu Vinod , Anthony Liguori On Thu, Jan 17, 2013 at 05:06:50PM -0200, Eduardo Habkost wrote: > There are lots of duplicate parsing code using strto*() in QEMU, and > most of that code is broken in one way or another. Even the visitors > code have duplicate integer parsing code[1]. This introduces functions > to help parsing unsigned int values: parse_uint() and parse_uint_full(). > > Parsing functions for signed ints and floats will be submitted later. > > parse_uint_full() has all the checks made by opts_type_uint64() at > opts-visitor.c: > > - Check for NULL (returns -EINVAL) > - Check for negative numbers (returns -ERANGE) Oops, I forgot to update the commit message. I hope the commiter can change it before committing, to avoid having to resubmit it again. > - Check for empty string (returns -EINVAL) > - Check for overflow or other errno values set by strtoll() (returns > -errno) > - Check for end of string (reject invalid characters after number) > (returns -EINVAL) > > parse_uint() does everything above except checking for the end of the > string, so callers can continue parsing the remainder of string after > the number. > > Unit tests included. > > [1] string-input-visitor.c:parse_int() could use the same parsing code > used by opts-visitor.c:opts_type_int(), instead of duplicating that > logic. > > Signed-off-by: Eduardo Habkost > --- > Changes v2: > - Trivial whitespace change > - Add 'base' parameter to the functions > > Changes v4: > - Return -EINVAL in case a minus sign is found > - Make endptr point to beginning of string in case -EINVAL > is returned (like the strtoull() behavior) [...] -- Eduardo