From owner-freebsd-standards@FreeBSD.ORG Thu Jun 30 17:12:47 2011 Return-Path: Delivered-To: standards@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3DD5E1065677 for ; Thu, 30 Jun 2011 17:12:47 +0000 (UTC) (envelope-from se@freebsd.org) Received: from nm16.bullet.mail.sp2.yahoo.com (nm16.bullet.mail.sp2.yahoo.com [98.139.91.86]) by mx1.freebsd.org (Postfix) with SMTP id 1C5858FC1B for ; Thu, 30 Jun 2011 17:12:47 +0000 (UTC) Received: from [98.139.91.61] by nm16.bullet.mail.sp2.yahoo.com with NNFMP; 30 Jun 2011 17:12:46 -0000 Received: from [208.71.42.192] by tm1.bullet.mail.sp2.yahoo.com with NNFMP; 30 Jun 2011 17:12:46 -0000 Received: from [127.0.0.1] by smtp203.mail.gq1.yahoo.com with NNFMP; 30 Jun 2011 17:12:46 -0000 X-Yahoo-Newman-Id: 493635.11874.bm@smtp203.mail.gq1.yahoo.com Received: from [192.168.119.20] (se@81.173.186.241 with plain) by smtp203.mail.gq1.yahoo.com with SMTP; 30 Jun 2011 10:12:46 -0700 PDT X-Yahoo-SMTP: iDf2N9.swBDAhYEh7VHfpgq0lnq. X-YMail-OSG: DUS1HSYVM1mONaYXbrRosb.IOMHctps.pGx6EOc1ZIXX8fX NORcnMFHxeeHSI6UwLo7DKALBnNKotLqPYerfgGfbGrm2aGLVDScn3AZOfNS DbU7hx4LkGGO_fIuBHZgziDvizLrsnWfT8bZHH6m4STJuWVmsEhrE7F1lN1L Mfhnmgj.F4EBQFHch7.Pqb8Q.iuU3uIHNaXIuoDtvjocsawFoGTTm.7tQx00 x7l.KA1TOPdyGsAwh1oX7N5ZEHeFj2aCX2nyTahRhEJ3Obk_VmWlxYryWGUh gfAmoMhp_2S7ITmo2GfkxpYunn0v3gXUgXhiYJvkKDfO1QkVcGOszth8sUOB CXaPhkyIR._auVLpbeINclZB29g-- X-Yahoo-Newman-Property: ymail-3 Message-ID: <4E0CAE8B.6030309@freebsd.org> Date: Thu, 30 Jun 2011 19:12:43 +0200 From: Stefan Esser User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20110624 Thunderbird/5.0 MIME-Version: 1.0 To: Bruce Evans , Alexander Best , Poul-Henning Kamp , standards@freebsd.org, Bruce Evans References: <99048.1309258976@critter.freebsd.dk> <4E0A0774.3090004@freebsd.org> <20110629082103.O1084@besplex.bde.org> <4E0B1C47.4010201@freebsd.org> <20110630073705.P1117@besplex.bde.org> <4E0C2F41.2060302@freebsd.org> <4E0CA55E.2090102@freebsd.org> <20110630165050.GB82980@zim.MIT.EDU> In-Reply-To: <20110630165050.GB82980@zim.MIT.EDU> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: Subject: Re: RESENT with patch ... Re: [RFC] Consistent numeric range for "expr" on all architectures X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Jun 2011 17:12:47 -0000 Am 30.06.2011 18:50, schrieb David Schultz: > On Thu, Jun 30, 2011, Stefan Esser wrote: >> int >> +is_integer(const char *s) >> +{ >> + if (*s == '-') >> + s++; >> + while (isdigit(*s)) >> + s++; >> + return *s == '\0'; >> +} > > I only glanced at the patch for a few seconds, but your > is_integer() routine will accept a bare minus sign ("-") as an > integer. I mentioned in the message, that I do not test for empty numeric operands. I had considered: int is_integer(const char *s) { if (*s == '-') s++; if (!isdigit(*s++) return 0; while (isdigit(*s)) s++; return *s == '\0'; } But this will break script that do while : do i=`expr "$i" + 1` done without first setting i=0. And I assume, such scripts exist in huge numbers. But "-" will not be accepted as operand (neither integer nor string). Didn't I give the example "expr -- - : -" which fails with a syntax error? Therefore, I do not need to check for actual digits in the input (and thus may accept "" as 0 for backwards compatibility), but "-" will not be allowed as parameter to expr by the parser ("syntax error"). Regards, STefan