Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YnZ9M-000606-Vj for pgsql-committers@arkaria.postgresql.org; Wed, 29 Apr 2015 21:04:09 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YnZ9M-00030v-Aq for pgsql-committers@arkaria.postgresql.org; Wed, 29 Apr 2015 21:04:08 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YnZ9L-00030o-JB for pgsql-committers@postgresql.org; Wed, 29 Apr 2015 21:04:07 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1YnZ9I-0005aR-Pq for pgsql-committers@postgresql.org; Wed, 29 Apr 2015 21:04:06 +0000 Received: from bruce by momjian.us with local (Exim 4.72) (envelope-from ) id 1YnZ9I-000154-4T; Wed, 29 Apr 2015 17:04:04 -0400 Date: Wed, 29 Apr 2015 17:04:04 -0400 From: Bruce Momjian To: Stephen Frost Cc: pgsql-committers@postgresql.org Subject: Re: pgsql: to_char(): have format 'OF' only show the leading negative sign Message-ID: <20150429210404.GO31727@momjian.us> References: <20150429141102.GX30322@tamriel.snowman.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="3Pql8miugIZX0722" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20150429141102.GX30322@tamriel.snowman.net> User-Agent: Mutt/1.5.20 (2009-06-14) X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-committers Precedence: bulk Sender: pgsql-committers-owner@postgresql.org --3Pql8miugIZX0722 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit On Wed, Apr 29, 2015 at 10:11:02AM -0400, Stephen Frost wrote: > Bruce, > > * Bruce Momjian (bruce@momjian.us) wrote: > > to_char(): have format 'OF' only show the leading negative sign > > > > Previously both hours and minutes displayed as negative. > > > > Report by David Pozsar > > This is causing the following error for me: > > /home/sfrost/git/pg/dev/postgresql/src/backend/utils/adt/formatting.c: In function ‘DCH_to_char’: > /home/sfrost/git/pg/dev/postgresql/src/backend/utils/adt/formatting.c:2510:6: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 3 has type ‘int’ [-Wformat=] > sprintf(s, ":%02ld", abs(tm->tm_gmtoff % SECS_PER_HOUR) / SECS_PER_MINUTE); > ^ > > Since abs() is declared to return just an int. I don't see it anywhere > in our tree and I'm not sure how portable it actually is, but labs() is > supposedly in C89, so perhaps that should be used here instead? OK, I have switched to labs() and will keep an eye on the buildfarm; patch attached. (There is already an uncomfortable amount of red there.) -- Bruce Momjian http://momjian.us EnterpriseDB http://enterprisedb.com + Everyone has their own god. + --3Pql8miugIZX0722 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="to_char.diff" diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c new file mode 100644 index 576db95..dbff94d *** a/src/backend/utils/adt/formatting.c --- b/src/backend/utils/adt/formatting.c *************** DCH_to_char(FormatNode *node, bool is_in *** 2507,2513 **** s += strlen(s); if (tm->tm_gmtoff % SECS_PER_HOUR != 0) { ! sprintf(s, ":%02ld", abs(tm->tm_gmtoff % SECS_PER_HOUR) / SECS_PER_MINUTE); s += strlen(s); } break; --- 2507,2513 ---- s += strlen(s); if (tm->tm_gmtoff % SECS_PER_HOUR != 0) { ! sprintf(s, ":%02ld", labs(tm->tm_gmtoff % SECS_PER_HOUR) / SECS_PER_MINUTE); s += strlen(s); } break; --3Pql8miugIZX0722 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-committers --3Pql8miugIZX0722--