Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cy9f7-0002yT-Sn for pgsql-hackers@arkaria.postgresql.org; Wed, 12 Apr 2017 04:13:45 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cy9f7-0003yx-Fy for pgsql-hackers@arkaria.postgresql.org; Wed, 12 Apr 2017 04:13:45 +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 1cy9dd-0001L3-UR for pgsql-hackers@postgresql.org; Wed, 12 Apr 2017 04:12:14 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cy9db-0002xV-IS for pgsql-hackers@postgresql.org; Wed, 12 Apr 2017 04:12:12 +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 v3C4CAtS024499; Wed, 12 Apr 2017 00:12:10 -0400 From: Tom Lane To: Peter Eisentraut cc: Alvaro Herrera , pgsql-hackers Subject: Re: GCC 7 warnings In-reply-to: References: <20170411175708.coshtfzejgaqhar2@alvherre.pgsql> Comments: In-reply-to Peter Eisentraut message dated "Tue, 11 Apr 2017 23:46:30 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <24497.1491970330.1@sss.pgh.pa.us> Date: Wed, 12 Apr 2017 00:12:10 -0400 Message-ID: <24498.1491970330@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: > Attached is a more refined patch that I propose for PG10 now. Compared > to the previous rushed version, this one uses some more precise > arithmetic to size some of the buffers. Generally +1 for switching the snprintf calls to use sizeof() rather than repeating the declared sizes of the arrays. 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? IOW, if we're going to touch this at all, I'd be inclined to go with msbuf[16] or so, as being more likely to satisfy compilers that have decided to try to warn about this. And maybe we should use snprintf, just for luck. 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