Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ayhRu-0007na-6V for pgsql-hackers@arkaria.postgresql.org; Fri, 06 May 2016 15:13:50 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1ayhRt-000788-LL for pgsql-hackers@arkaria.postgresql.org; Fri, 06 May 2016 15:13:49 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ayhRr-00076o-Vx for pgsql-hackers@postgreSQL.org; Fri, 06 May 2016 15:13:48 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ayhRo-0004Ts-Ow for pgsql-hackers@postgreSQL.org; Fri, 06 May 2016 15:13:47 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u46FDemc016452; Fri, 6 May 2016 11:13:41 -0400 From: Tom Lane To: Fabien COELHO cc: PostgreSQL Developers Subject: Re: Poorly-thought-out handling of double variables in pgbench In-reply-to: References: <9188.1462475559@sss.pgh.pa.us> <15599.1462484702@sss.pgh.pa.us> Comments: In-reply-to Fabien COELHO message dated "Fri, 06 May 2016 09:14:01 +0200" Date: Fri, 06 May 2016 11:13:40 -0400 Message-ID: <16451.1462547620@sss.pgh.pa.us> X-Pg-Spam-Score: -4.0 (----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Fabien COELHO writes: > This is a definite improvement. > I like the lazyness between string & numeric forms, and for sorting, that > is what was needed doing to have something clean. > Applied on head, it works for me. OK, pushed. > While testing the patch I found a minor preexisting (mine...) bug: when > string-scanning doubles, whether the whole string is consumed or not is > not checked. This means that -D x=0one is interpreted as double 0. > I came up with the attached check, but maybe there is a cleaner way to do > that. I like the way the zic code does it: else /* type should be double */ { double dv; ! if (sscanf(var->value, "%lf", &dv) != 1) { fprintf(stderr, "malformed variable \"%s\" value: \"%s\"\n", --- 928,936 ---- else /* type should be double */ { double dv; + char xs; ! if (sscanf(var->value, "%lf%c", &dv, &xs) != 1) { fprintf(stderr, "malformed variable \"%s\" value: \"%s\"\n", This relies on the idea that if there is any trailing junk, one character will get assigned into "xs" and then sscanf will say it filled two fields. Otherwise, it'll report filling only one field (or none, if there's no number either). This requires only a minimal amount of code and no extra strlen() calculations. Neither way allows for trailing whitespace, though. I don't see that that's important here. regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers