Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cyK66-0005nA-Ur for pgsql-hackers@arkaria.postgresql.org; Wed, 12 Apr 2017 15:22:19 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cyK66-0001Kf-7r for pgsql-hackers@arkaria.postgresql.org; Wed, 12 Apr 2017 15:22:18 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cyK4a-0006eq-Ox for pgsql-hackers@postgresql.org; Wed, 12 Apr 2017 15:20:44 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cyK4W-0007a5-0o for pgsql-hackers@postgresql.org; Wed, 12 Apr 2017 15:20:43 +0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 2E00B2111B; Wed, 12 Apr 2017 11:20:39 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute7.internal (MEProxy); Wed, 12 Apr 2017 11:20:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s= fm1; bh=IhJUlUYFcxfqBeXJeOUvud1Gyf0gNydNjOqy8gSUnnQ=; b=POH4+mXI cK/yrS9Cq38X0rJAeECRJzELRV96M8j5QcnbP7kUhCWyQu/6R90HNuxMI87Bvm4D OGcTsr3oIURaNE65ZA75WA90WAtgN1b9iEIvHpGs59Yn2I8ZestR7wIksr3j81RZ VNcPPtSHuY0kPo9pKTQxZFfGljkDYvCQOzCksVEXeQ+o8PXAb+8+4On9Np0iiTwa iAQ58Ts43ZUEgc4bK342e5a/Y9wmebr3CXG3ov/3MD9lGPU31C2wlbO0esLE0tSS dGG1CgAp9ZUlNiCKDZ9NZUp4xiAazu+z0UMYRsOlKfWsYqxutZ32Lb8CsC5gQY9+ 9XClL8vL0stI7w== X-ME-Sender: X-Sasl-enc: Bt+My6zuO25hHYdeyNgNBBGueYUpNNEOPN48zrwBw4Je 1492010438 Received: from april.local (c-73-13-66-39.hsd1.pa.comcast.net [73.13.66.39]) by mail.messagingengine.com (Postfix) with ESMTPA id ACC237E797; Wed, 12 Apr 2017 11:20:38 -0400 (EDT) Subject: Re: GCC 7 warnings To: Tom Lane References: <20170411175708.coshtfzejgaqhar2@alvherre.pgsql> <24498.1491970330@sss.pgh.pa.us> Cc: Alvaro Herrera , pgsql-hackers From: Peter Eisentraut Organization: 2ndQuadrant Message-ID: <600b3625-603a-e400-7881-075830e98ba3@2ndquadrant.com> Date: Wed, 12 Apr 2017 11:20:42 -0400 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <24498.1491970330@sss.pgh.pa.us> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) 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 On 4/12/17 00:12, Tom Lane wrote: > The change in setup_formatted_log_time seems a bit weird: > > - char msbuf[8]; > + char msbuf[10]; > > The associated call is > > sprintf(msbuf, ".%03d", (int) (saved_timeval.tv_usec / 1000)); > > 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? The full message from an isolated test case is test.c: In function 'f': test.c:11:15: warning: '%03d' directive writing between 3 and 8 bytes into a region of size 7 [-Wformat-overflow=] sprintf(buf, ".%03d", (int) (tv.tv_usec / 1000)); ^ test.c:11:15: note: directive argument in the range [-2147483, 2147483] test.c:11:2: note: '__builtin___sprintf_chk' output between 5 and 10 bytes into a destination of size 8 sprintf(buf, ".%03d", (int) (tv.tv_usec / 1000)); ^ (This is with -O2. With -O0 it only asks for 5 bytes.) -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers