Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cyKGG-00072A-2V for pgsql-hackers@arkaria.postgresql.org; Wed, 12 Apr 2017 15:32:48 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cyKGF-00055g-Lp for pgsql-hackers@arkaria.postgresql.org; Wed, 12 Apr 2017 15:32:47 +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 1cyKEl-0001dS-3l for pgsql-hackers@postgresql.org; Wed, 12 Apr 2017 15:31:15 +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 1cyKEi-000474-3k for pgsql-hackers@postgresql.org; Wed, 12 Apr 2017 15:31:14 +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 v3CFV9wC006998; Wed, 12 Apr 2017 11:31:10 -0400 From: Tom Lane To: Peter Eisentraut cc: Alvaro Herrera , pgsql-hackers Subject: Re: GCC 7 warnings In-reply-to: <600b3625-603a-e400-7881-075830e98ba3@2ndquadrant.com> References: <20170411175708.coshtfzejgaqhar2@alvherre.pgsql> <24498.1491970330@sss.pgh.pa.us> <600b3625-603a-e400-7881-075830e98ba3@2ndquadrant.com> Comments: In-reply-to Peter Eisentraut message dated "Wed, 12 Apr 2017 11:20:42 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <6996.1492011069.1@sss.pgh.pa.us> Date: Wed, 12 Apr 2017 11:31:09 -0400 Message-ID: <6997.1492011069@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) 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 Peter Eisentraut writes: > On 4/12/17 00:12, Tom Lane wrote: >> Now a human can see that saved_timeval.tv_usec must be 0..999999, so >> that the %d format item must always emit exactly 3 characters, which >> means that really 5 bytes would be enough. I wouldn't expect a >> compiler to know that, but if it's making a generic assumption about >> the worst-case width of %d, shouldn't it conclude that we might need >> as many as 13 bytes for the buffer? Why does msbuf[10] satisfy it >> if msbuf[8] doesn't? > Because the /1000 takes off three digits? Huh ... I would not really have expected it to figure that out, but this makes it pretty clear that it did: > test.c:11:15: note: directive argument in the range [-2147483, 2147483] > (This is with -O2. With -O0 it only asks for 5 bytes.) But that reinforces my suspicion that the intelligence brought to bear here will be variable. I'd still go for msbuf[16]; it's not like anybody's going to notice the extra stack consumption. 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