From owner-freebsd-hackers@FreeBSD.ORG Tue Jan 4 10:41:09 2011 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4D1C71065670 for ; Tue, 4 Jan 2011 10:41:09 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from igloo.linux.gr (igloo.linux.gr [62.1.205.36]) by mx1.freebsd.org (Postfix) with ESMTP id C04FA8FC0C for ; Tue, 4 Jan 2011 10:41:08 +0000 (UTC) X-Spam-Status: No X-Hellug-MailScanner-From: keramida@ceid.upatras.gr X-Hellug-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=-2.9, required 5, autolearn=not spam, ALL_TRUSTED -1.00, BAYES_00 -1.90) X-Hellug-MailScanner: Found to be clean X-Hellug-MailScanner-ID: p04Aejhl022747 Received: from gkeramidas-glaptop.linux.gr ([74.125.57.36]) (authenticated bits=0) by igloo.linux.gr (8.14.3/8.14.3/Debian-9.4) with ESMTP id p04Aejhl022747 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 4 Jan 2011 12:40:51 +0200 From: Giorgos Keramidas To: Eitan Adler References: <6BEFA669-2E1F-44E6-897A-0A51DA939A74@gmail.com> <20110102101845.GC90883@deviant.kiev.zoral.com.ua> Date: Tue, 04 Jan 2011 11:40:45 +0100 In-Reply-To: (Giorgos Keramidas's message of "Tue, 04 Jan 2011 11:36:38 +0100") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Cc: Kostik Belousov , hackers@freebsd.org Subject: Re: [patch] have rtprio check that arguments are numeric; change atoi to strtol X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Jan 2011 10:41:09 -0000 On Tue, 04 Jan 2011 11:36:38 +0100, Giorgos Keramidas wrote: > On Sun, 2 Jan 2011 18:46:47 -0500, Eitan Adler wrote: >> What about this patch? I incorporated your feedback so I am not going >> to reply inline. > > Since the pattern of converting strings to int-derivative values appears > multiple times, I'd probably prefer something like a new function that > does the parsing *and* error-checking, to avoid duplication of errno > checks, invalidchar checks, and so on, e.g. something like this near the > top of rtprio.c: > > #include > #include > #include > > /* > * Parse an integer from 'string' into 'value'. Return the first > * invalid character in 'endp', if endp is non-NULL. The return value > * of parseint is 0 on success, -1 for any parse error. > */ > > int > parseint(const char *string, const char **endp, int base, int *value) > { > long x; > > errno = 0; > x = strtol(string, endp, base); > if (errno != 0 || endp == str || (endp != NULL && > endp != str && *endp != '\0' && (isdigit(*endp) == 0 || > isspace(*endp) != 0))) > return -1; > if (x >= INT_MAX) { > errno = ERANGE; > return -1; > } > return (int)x; > } instead of `return (int)x' the last bits should be slightly different, of course: if (value != NULL) *value = (int)x; return 0; }