From f3094920a567cde6c86adf36a1a033d7431b11ff Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 19 Oct 2016 18:55:52 -0400 Subject: Sync our copy of the timezone library with IANA release tzcode2016g. This is mostly to absorb some corner-case fixes in zic for year-2037 timestamps. The other changes that have been made are unlikely to affect our usage, but nonetheless we may as well take 'em. --- src/timezone/strftime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/timezone/strftime.c') diff --git a/src/timezone/strftime.c b/src/timezone/strftime.c index 5630619321..4a0a01db65 100644 --- a/src/timezone/strftime.c +++ b/src/timezone/strftime.c @@ -128,7 +128,7 @@ pg_strftime(char *s, size_t maxsize, const char *format, int warn; warn = IN_NONE; - p = _fmt(((format == NULL) ? "%c" : format), t, s, s + maxsize, &warn); + p = _fmt(format, t, s, s + maxsize, &warn); if (p == s + maxsize) return 0; *p = '\0'; -- cgit v1.2.3 From 9e3755ecb2d058f7d123dd35a2e1784006190962 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sat, 25 Feb 2017 16:12:24 -0500 Subject: Remove useless duplicate inclusions of system header files. c.h #includes a number of core libc header files, such as . There's no point in re-including these after having read postgres.h, postgres_fe.h, or c.h; so remove code that did so. While at it, also fix some places that were ignoring our standard pattern of "include postgres[_fe].h, then system header files, then other Postgres header files". While there's not any great magic in doing it that way rather than system headers last, it's silly to have just a few files deviating from the general pattern. (But I didn't attempt to enforce this globally, only in files I was touching anyway.) I'd be the first to say that this is mostly compulsive neatnik-ism, but over time it might save enough compile cycles to be useful. --- contrib/fuzzystrmatch/dmetaphone.c | 12 +++++++----- contrib/ltree/crc32.c | 4 ---- contrib/pgcrypto/px.h | 1 - src/backend/access/transam/timeline.c | 1 - src/backend/access/transam/twophase.c | 1 - src/backend/access/transam/xlogarchive.c | 1 - src/backend/commands/dbcommands.c | 1 - src/backend/commands/tablespace.c | 1 - src/backend/libpq/ifaddr.c | 1 - src/backend/port/atomics.c | 1 - src/backend/port/dynloader/freebsd.h | 1 - src/backend/port/dynloader/netbsd.h | 1 - src/backend/port/dynloader/openbsd.h | 1 - src/backend/port/win32/crashdump.c | 3 +-- src/backend/postmaster/autovacuum.c | 1 - src/backend/replication/basebackup.c | 1 - src/backend/replication/logical/snapbuild.c | 1 - src/backend/replication/walreceiverfuncs.c | 1 - src/backend/storage/ipc/dsm.c | 1 - src/backend/storage/ipc/dsm_impl.c | 1 - src/backend/storage/ipc/latch.c | 1 - src/backend/utils/adt/cash.c | 1 - src/backend/utils/adt/dbsize.c | 1 - src/backend/utils/adt/inet_cidr_ntop.c | 1 - src/backend/utils/adt/inet_net_pton.c | 1 - src/backend/utils/adt/pg_locale.c | 1 - src/backend/utils/init/miscinit.c | 1 - src/bin/initdb/initdb.c | 1 - src/bin/pg_basebackup/pg_basebackup.c | 1 - src/bin/pg_basebackup/pg_receivewal.c | 1 - src/bin/pg_basebackup/streamutil.c | 3 --- src/bin/pg_ctl/pg_ctl.c | 11 ++++------- src/bin/pg_dump/parallel.c | 14 ++++++-------- src/bin/pg_dump/pg_backup_archiver.c | 16 +++++++--------- src/bin/pg_dump/pg_dump.c | 3 --- src/bin/pg_dump/pg_dumpall.c | 4 ---- src/bin/pg_dump/pg_restore.c | 15 +++++---------- src/bin/pg_resetwal/pg_resetwal.c | 1 - src/bin/pg_rewind/copy_fetch.c | 2 -- src/bin/pg_rewind/fetch.c | 1 - src/bin/pg_rewind/file_ops.c | 1 - src/bin/pg_rewind/filemap.c | 1 - src/bin/pg_rewind/libpq_fetch.c | 1 - src/bin/pg_upgrade/dump.c | 1 - src/bin/pg_upgrade/exec.c | 5 ++--- src/bin/pg_upgrade/option.c | 11 +++++------ src/bin/pg_upgrade/parallel.c | 9 +++------ src/bin/pg_upgrade/tablespace.c | 2 -- src/bin/pgevent/pgevent.c | 6 ------ src/bin/psql/command.c | 2 -- src/bin/psql/crosstabview.c | 2 -- src/bin/psql/help.c | 1 - src/bin/psql/startup.c | 4 ---- src/common/ip.c | 1 - src/common/username.c | 2 -- src/common/wait_error.c | 2 -- src/fe_utils/print.c | 1 - src/include/libpq/libpq.h | 1 - src/include/port/atomics/generic-msvc.h | 1 - src/include/utils/pg_locale.h | 1 - src/interfaces/ecpg/ecpglib/data.c | 2 -- src/interfaces/ecpg/ecpglib/execute.c | 1 - src/interfaces/ecpg/ecpglib/typename.c | 1 - src/interfaces/ecpg/preproc/ecpg.c | 2 +- src/interfaces/ecpg/preproc/pgc.l | 1 - src/interfaces/libpq/fe-connect.c | 1 - src/interfaces/libpq/libpq-int.h | 1 - src/interfaces/libpq/pthread-win32.c | 1 - src/pl/plperl/plperl.c | 1 - src/port/chklocale.c | 5 ----- src/port/dirmod.c | 1 - src/port/inet_net_ntop.c | 1 - src/port/open.c | 1 - src/port/system.c | 1 - src/test/isolation/isolationtester.c | 3 --- src/timezone/strftime.c | 1 - src/timezone/zic.c | 1 - 77 files changed, 41 insertions(+), 155 deletions(-) (limited to 'src/timezone/strftime.c') diff --git a/contrib/fuzzystrmatch/dmetaphone.c b/contrib/fuzzystrmatch/dmetaphone.c index 147c8501ee..f210869acb 100644 --- a/contrib/fuzzystrmatch/dmetaphone.c +++ b/contrib/fuzzystrmatch/dmetaphone.c @@ -93,9 +93,6 @@ The remaining code is authored by Andrew Dunstan and ***********************************************************************/ - - - /* include these first, according to the docs */ #ifndef DMETAPHONE_MAIN @@ -105,14 +102,19 @@ The remaining code is authored by Andrew Dunstan and /* turn off assertions for embedded function */ #define NDEBUG -#endif +#else /* DMETAPHONE_MAIN */ + +/* we need these if we didn't get them from postgres.h */ #include -#include #include #include #include + +#endif /* DMETAPHONE_MAIN */ + #include +#include /* prototype for the main function we got from the perl module */ static void DoubleMetaphone(char *, char **); diff --git a/contrib/ltree/crc32.c b/contrib/ltree/crc32.c index 403dae0d7d..447e4b2960 100644 --- a/contrib/ltree/crc32.c +++ b/contrib/ltree/crc32.c @@ -9,10 +9,6 @@ #include "postgres.h" -#include -#include -#include - #ifdef LOWER_NODE #include #define TOLOWER(x) tolower((unsigned char) (x)) diff --git a/contrib/pgcrypto/px.h b/contrib/pgcrypto/px.h index 00fc6f0c01..e68a95a058 100644 --- a/contrib/pgcrypto/px.h +++ b/contrib/pgcrypto/px.h @@ -32,7 +32,6 @@ #ifndef __PX_H #define __PX_H -#include #include /* keep debug messages? */ diff --git a/src/backend/access/transam/timeline.c b/src/backend/access/transam/timeline.c index c8240b112d..1fdc59190c 100644 --- a/src/backend/access/transam/timeline.c +++ b/src/backend/access/transam/timeline.c @@ -32,7 +32,6 @@ #include "postgres.h" #include -#include #include #include "access/timeline.h" diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c index 50c70b2920..0a8edb9e58 100644 --- a/src/backend/access/transam/twophase.c +++ b/src/backend/access/transam/twophase.c @@ -54,7 +54,6 @@ #include #include -#include #include #include diff --git a/src/backend/access/transam/xlogarchive.c b/src/backend/access/transam/xlogarchive.c index 7e91e8f81a..7afb73579b 100644 --- a/src/backend/access/transam/xlogarchive.c +++ b/src/backend/access/transam/xlogarchive.c @@ -14,7 +14,6 @@ #include "postgres.h" -#include #include #include #include diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c index 1ebacbc24f..5a63b1abcb 100644 --- a/src/backend/commands/dbcommands.c +++ b/src/backend/commands/dbcommands.c @@ -20,7 +20,6 @@ #include "postgres.h" #include -#include #include #include diff --git a/src/backend/commands/tablespace.c b/src/backend/commands/tablespace.c index 80515bae19..f9c26201d9 100644 --- a/src/backend/commands/tablespace.c +++ b/src/backend/commands/tablespace.c @@ -48,7 +48,6 @@ #include #include -#include #include #include "access/heapam.h" diff --git a/src/backend/libpq/ifaddr.c b/src/backend/libpq/ifaddr.c index 7692881c8b..f81003f7c8 100644 --- a/src/backend/libpq/ifaddr.c +++ b/src/backend/libpq/ifaddr.c @@ -20,7 +20,6 @@ #include "postgres.h" #include -#include #include #include #include diff --git a/src/backend/port/atomics.c b/src/backend/port/atomics.c index 86b5308214..756a2ef997 100644 --- a/src/backend/port/atomics.c +++ b/src/backend/port/atomics.c @@ -21,7 +21,6 @@ #ifdef WIN32 #error "barriers are required (and provided) on WIN32 platforms" #endif -#include #include #endif diff --git a/src/backend/port/dynloader/freebsd.h b/src/backend/port/dynloader/freebsd.h index 78dda69922..6116d3f83f 100644 --- a/src/backend/port/dynloader/freebsd.h +++ b/src/backend/port/dynloader/freebsd.h @@ -13,7 +13,6 @@ #ifndef PORT_PROTOS_H #define PORT_PROTOS_H -#include #include #include #include diff --git a/src/backend/port/dynloader/netbsd.h b/src/backend/port/dynloader/netbsd.h index 688b7fb793..0bd406850d 100644 --- a/src/backend/port/dynloader/netbsd.h +++ b/src/backend/port/dynloader/netbsd.h @@ -14,7 +14,6 @@ #ifndef PORT_PROTOS_H #define PORT_PROTOS_H -#include #include #include #include diff --git a/src/backend/port/dynloader/openbsd.h b/src/backend/port/dynloader/openbsd.h index 34d2724615..25d5439633 100644 --- a/src/backend/port/dynloader/openbsd.h +++ b/src/backend/port/dynloader/openbsd.h @@ -13,7 +13,6 @@ #ifndef PORT_PROTOS_H #define PORT_PROTOS_H -#include #include #include #include diff --git a/src/backend/port/win32/crashdump.c b/src/backend/port/win32/crashdump.c index 64969df73d..ff44b6033e 100644 --- a/src/backend/port/win32/crashdump.c +++ b/src/backend/port/win32/crashdump.c @@ -39,8 +39,7 @@ #include "postgres.h" #define WIN32_LEAN_AND_MEAN -#include -#include + /* * Some versions of the MS SDK contain "typedef enum { ... } ;" which the MS * compiler quite sanely complains about. Well done, Microsoft. diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c index 0c5ffa086c..e8de9a3ced 100644 --- a/src/backend/postmaster/autovacuum.c +++ b/src/backend/postmaster/autovacuum.c @@ -62,7 +62,6 @@ #include "postgres.h" #include -#include #include #include diff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.c index 643a17943a..7414048f4e 100644 --- a/src/backend/replication/basebackup.c +++ b/src/backend/replication/basebackup.c @@ -12,7 +12,6 @@ */ #include "postgres.h" -#include #include #include #include diff --git a/src/backend/replication/logical/snapbuild.c b/src/backend/replication/logical/snapbuild.c index c0f28ddc09..6f19cdca8c 100644 --- a/src/backend/replication/logical/snapbuild.c +++ b/src/backend/replication/logical/snapbuild.c @@ -107,7 +107,6 @@ #include "postgres.h" #include -#include #include #include "miscadmin.h" diff --git a/src/backend/replication/walreceiverfuncs.c b/src/backend/replication/walreceiverfuncs.c index df113b86e8..8bf1fe8565 100644 --- a/src/backend/replication/walreceiverfuncs.c +++ b/src/backend/replication/walreceiverfuncs.c @@ -16,7 +16,6 @@ */ #include "postgres.h" -#include #include #include #include diff --git a/src/backend/storage/ipc/dsm.c b/src/backend/storage/ipc/dsm.c index 07af16622c..54378bcea9 100644 --- a/src/backend/storage/ipc/dsm.c +++ b/src/backend/storage/ipc/dsm.c @@ -27,7 +27,6 @@ #include "postgres.h" #include -#include #include #ifndef WIN32 #include diff --git a/src/backend/storage/ipc/dsm_impl.c b/src/backend/storage/ipc/dsm_impl.c index 7078f68c35..b2c9cdc6ed 100644 --- a/src/backend/storage/ipc/dsm_impl.c +++ b/src/backend/storage/ipc/dsm_impl.c @@ -49,7 +49,6 @@ #include "postgres.h" #include -#include #include #ifndef WIN32 #include diff --git a/src/backend/storage/ipc/latch.c b/src/backend/storage/ipc/latch.c index 0079ba567f..ea7f930866 100644 --- a/src/backend/storage/ipc/latch.c +++ b/src/backend/storage/ipc/latch.c @@ -40,7 +40,6 @@ #include #include #include -#include #ifdef HAVE_SYS_EPOLL_H #include #endif diff --git a/src/backend/utils/adt/cash.c b/src/backend/utils/adt/cash.c index ac8f74fee6..5afadb65d1 100644 --- a/src/backend/utils/adt/cash.c +++ b/src/backend/utils/adt/cash.c @@ -21,7 +21,6 @@ #include #include #include -#include #include "libpq/pqformat.h" #include "utils/builtins.h" diff --git a/src/backend/utils/adt/dbsize.c b/src/backend/utils/adt/dbsize.c index ec3a28cd0d..8cdd1dc4f7 100644 --- a/src/backend/utils/adt/dbsize.c +++ b/src/backend/utils/adt/dbsize.c @@ -11,7 +11,6 @@ #include "postgres.h" -#include #include #include "access/heapam.h" diff --git a/src/backend/utils/adt/inet_cidr_ntop.c b/src/backend/utils/adt/inet_cidr_ntop.c index d33534ec17..d5d1289d7d 100644 --- a/src/backend/utils/adt/inet_cidr_ntop.c +++ b/src/backend/utils/adt/inet_cidr_ntop.c @@ -23,7 +23,6 @@ static const char rcsid[] = "Id: inet_net_ntop.c,v 1.1.2.2 2004/03/09 09:17:27 m #include "postgres.h" -#include #include #include #include diff --git a/src/backend/utils/adt/inet_net_pton.c b/src/backend/utils/adt/inet_net_pton.c index b8fa7d2bcc..be788d37cd 100644 --- a/src/backend/utils/adt/inet_net_pton.c +++ b/src/backend/utils/adt/inet_net_pton.c @@ -23,7 +23,6 @@ static const char rcsid[] = "Id: inet_net_pton.c,v 1.4.2.3 2004/03/17 00:40:11 m #include "postgres.h" -#include #include #include #include diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c index 4c7f1dad50..ab197025f8 100644 --- a/src/backend/utils/adt/pg_locale.c +++ b/src/backend/utils/adt/pg_locale.c @@ -51,7 +51,6 @@ #include "postgres.h" -#include #include #include "access/htup_details.h" diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c index e984e79c60..e0298ee35f 100644 --- a/src/backend/utils/init/miscinit.c +++ b/src/backend/utils/init/miscinit.c @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index 540427a892..1ed0d20504 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -52,7 +52,6 @@ #include #include #include -#include #include #include diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c index 9020fb14d3..bc997dc997 100644 --- a/src/bin/pg_basebackup/pg_basebackup.c +++ b/src/bin/pg_basebackup/pg_basebackup.c @@ -16,7 +16,6 @@ #include #include #include -#include #include #include #include diff --git a/src/bin/pg_basebackup/pg_receivewal.c b/src/bin/pg_basebackup/pg_receivewal.c index e8d0e8984e..15348ada58 100644 --- a/src/bin/pg_basebackup/pg_receivewal.c +++ b/src/bin/pg_basebackup/pg_receivewal.c @@ -17,7 +17,6 @@ #include #include #include -#include #include #include "libpq-fe.h" diff --git a/src/bin/pg_basebackup/streamutil.c b/src/bin/pg_basebackup/streamutil.c index 90d93cbed1..1fe42efc21 100644 --- a/src/bin/pg_basebackup/streamutil.c +++ b/src/bin/pg_basebackup/streamutil.c @@ -13,10 +13,7 @@ #include "postgres_fe.h" -#include -#include #include -#include #include /* for ntohl/htonl */ diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c index 93e5891950..c63819b88b 100644 --- a/src/bin/pg_ctl/pg_ctl.c +++ b/src/bin/pg_ctl/pg_ctl.c @@ -19,16 +19,9 @@ #include "postgres_fe.h" -#include "catalog/pg_control.h" -#include "common/controldata_utils.h" -#include "libpq-fe.h" -#include "pqexpbuffer.h" - #include -#include #include #include -#include #include #include #include @@ -38,8 +31,12 @@ #include #endif +#include "catalog/pg_control.h" +#include "common/controldata_utils.h" #include "getopt_long.h" +#include "libpq-fe.h" #include "miscadmin.h" +#include "pqexpbuffer.h" /* PID can be negative for standalone backend */ typedef long pgpid_t; diff --git a/src/bin/pg_dump/parallel.c b/src/bin/pg_dump/parallel.c index 775a7f858c..be8e018a96 100644 --- a/src/bin/pg_dump/parallel.c +++ b/src/bin/pg_dump/parallel.c @@ -51,6 +51,12 @@ #include "postgres_fe.h" +#ifndef WIN32 +#include +#include +#include +#include +#endif #ifdef HAVE_SYS_SELECT_H #include #endif @@ -59,14 +65,6 @@ #include "pg_backup_utils.h" #include "fe_utils/string_utils.h" -#ifndef WIN32 -#include -#include -#include "signal.h" -#include -#include -#endif - /* Mnemonic macros for indexing the fd array returned by pipe(2) */ #define PIPE_READ 0 #define PIPE_WRITE 1 diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c index 929f1b592b..7e2bed38b3 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -21,24 +21,22 @@ */ #include "postgres_fe.h" -#include "parallel.h" -#include "pg_backup_archiver.h" -#include "pg_backup_db.h" -#include "pg_backup_utils.h" -#include "dumputils.h" -#include "fe_utils/string_utils.h" - #include #include #include #include -#include #include - #ifdef WIN32 #include #endif +#include "parallel.h" +#include "pg_backup_archiver.h" +#include "pg_backup_db.h" +#include "pg_backup_utils.h" +#include "dumputils.h" +#include "fe_utils/string_utils.h" + #include "libpq/libpq-fs.h" #define TEXT_DUMP_HEADER "--\n-- PostgreSQL database dump\n--\n\n" diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 89db3103bc..7273ec8fe2 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -33,9 +33,6 @@ #include #include -#ifdef ENABLE_NLS -#include -#endif #ifdef HAVE_TERMIOS_H #include #endif diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index 6895d02bfc..f4b4d7bd9b 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -18,10 +18,6 @@ #include #include -#ifdef ENABLE_NLS -#include -#endif - #include "getopt_long.h" #include "dumputils.h" diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c index 497677494b..5f61fb2764 100644 --- a/src/bin/pg_dump/pg_restore.c +++ b/src/bin/pg_dump/pg_restore.c @@ -40,21 +40,16 @@ */ #include "postgres_fe.h" -#include "getopt_long.h" - -#include "dumputils.h" -#include "parallel.h" -#include "pg_backup_utils.h" - #include - #ifdef HAVE_TERMIOS_H #include #endif -#ifdef ENABLE_NLS -#include -#endif +#include "getopt_long.h" + +#include "dumputils.h" +#include "parallel.h" +#include "pg_backup_utils.h" static void usage(const char *progname); diff --git a/src/bin/pg_resetwal/pg_resetwal.c b/src/bin/pg_resetwal/pg_resetwal.c index 502ea5b290..27bd9b04e7 100644 --- a/src/bin/pg_resetwal/pg_resetwal.c +++ b/src/bin/pg_resetwal/pg_resetwal.c @@ -39,7 +39,6 @@ #include #include -#include #include #include #include diff --git a/src/bin/pg_rewind/copy_fetch.c b/src/bin/pg_rewind/copy_fetch.c index d48424bfb4..f8d3dfecfa 100644 --- a/src/bin/pg_rewind/copy_fetch.c +++ b/src/bin/pg_rewind/copy_fetch.c @@ -9,12 +9,10 @@ */ #include "postgres_fe.h" -#include #include #include #include #include -#include #include "datapagemap.h" #include "fetch.h" diff --git a/src/bin/pg_rewind/fetch.c b/src/bin/pg_rewind/fetch.c index 08a296d7d4..e9353d8866 100644 --- a/src/bin/pg_rewind/fetch.c +++ b/src/bin/pg_rewind/fetch.c @@ -16,7 +16,6 @@ */ #include "postgres_fe.h" -#include #include #include diff --git a/src/bin/pg_rewind/file_ops.c b/src/bin/pg_rewind/file_ops.c index f8ca4c925d..4229f0e056 100644 --- a/src/bin/pg_rewind/file_ops.c +++ b/src/bin/pg_rewind/file_ops.c @@ -14,7 +14,6 @@ */ #include "postgres_fe.h" -#include #include #include #include diff --git a/src/bin/pg_rewind/filemap.c b/src/bin/pg_rewind/filemap.c index 151930234c..e5b254069d 100644 --- a/src/bin/pg_rewind/filemap.c +++ b/src/bin/pg_rewind/filemap.c @@ -10,7 +10,6 @@ #include "postgres_fe.h" -#include #include #include diff --git a/src/bin/pg_rewind/libpq_fetch.c b/src/bin/pg_rewind/libpq_fetch.c index d2374201c6..d86ecd3660 100644 --- a/src/bin/pg_rewind/libpq_fetch.c +++ b/src/bin/pg_rewind/libpq_fetch.c @@ -9,7 +9,6 @@ */ #include "postgres_fe.h" -#include #include #include #include diff --git a/src/bin/pg_upgrade/dump.c b/src/bin/pg_upgrade/dump.c index f18be22c16..2e621b027c 100644 --- a/src/bin/pg_upgrade/dump.c +++ b/src/bin/pg_upgrade/dump.c @@ -11,7 +11,6 @@ #include "pg_upgrade.h" -#include #include "fe_utils/string_utils.h" diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index b6a3ef791e..91fa71728e 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -9,10 +9,9 @@ #include "postgres_fe.h" -#include "pg_upgrade.h" - #include -#include + +#include "pg_upgrade.h" static void check_data_dir(ClusterInfo *cluster); static void check_bin_dir(ClusterInfo *cluster); diff --git a/src/bin/pg_upgrade/option.c b/src/bin/pg_upgrade/option.c index 82d2443bcd..5007ce53cf 100644 --- a/src/bin/pg_upgrade/option.c +++ b/src/bin/pg_upgrade/option.c @@ -9,17 +9,16 @@ #include "postgres_fe.h" -#include "miscadmin.h" -#include "getopt_long.h" - -#include "pg_upgrade.h" - #include -#include #ifdef WIN32 #include #endif +#include "miscadmin.h" +#include "getopt_long.h" + +#include "pg_upgrade.h" + static void usage(void); static void check_required_directory(char **dirpath, char **configpath, diff --git a/src/bin/pg_upgrade/parallel.c b/src/bin/pg_upgrade/parallel.c index d35015f52a..7c85a13a99 100644 --- a/src/bin/pg_upgrade/parallel.c +++ b/src/bin/pg_upgrade/parallel.c @@ -9,17 +9,14 @@ #include "postgres_fe.h" -#include "pg_upgrade.h" - -#include -#include -#include #include - #ifdef WIN32 #include #endif +#include "pg_upgrade.h" + + static int parallel_jobs; #ifdef WIN32 diff --git a/src/bin/pg_upgrade/tablespace.c b/src/bin/pg_upgrade/tablespace.c index 24f7bd960c..4938bc2de2 100644 --- a/src/bin/pg_upgrade/tablespace.c +++ b/src/bin/pg_upgrade/tablespace.c @@ -11,8 +11,6 @@ #include "pg_upgrade.h" -#include - static void get_tablespace_paths(void); static void set_tablespace_directory_suffix(ClusterInfo *cluster); diff --git a/src/bin/pgevent/pgevent.c b/src/bin/pgevent/pgevent.c index 5332a13256..f68f987c17 100644 --- a/src/bin/pgevent/pgevent.c +++ b/src/bin/pgevent/pgevent.c @@ -10,15 +10,9 @@ * *------------------------------------------------------------------------- */ - - #include "postgres_fe.h" -#include #include -#include -#include -#include /* Global variables */ HANDLE g_module = NULL; /* hModule of DLL */ diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index f17f610717..a28f5134b9 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -18,7 +18,6 @@ #include #endif #ifndef WIN32 -#include /* for umask() */ #include /* for stat() */ #include /* open() flags */ #include /* for geteuid(), getpid(), stat() */ @@ -27,7 +26,6 @@ #include #include #include -#include /* for umask() */ #include /* for stat() */ #endif diff --git a/src/bin/psql/crosstabview.c b/src/bin/psql/crosstabview.c index bf48d2f406..2794eb6b87 100644 --- a/src/bin/psql/crosstabview.c +++ b/src/bin/psql/crosstabview.c @@ -7,8 +7,6 @@ */ #include "postgres_fe.h" -#include - #include "common.h" #include "crosstabview.h" #include "pqexpbuffer.h" diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c index 3e3cab4941..91cf0be46a 100644 --- a/src/bin/psql/help.c +++ b/src/bin/psql/help.c @@ -8,7 +8,6 @@ #include "postgres_fe.h" #ifndef WIN32 -#include /* (ditto) */ #include /* for geteuid() */ #else #include diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c index 88d686a5b7..694f0ef257 100644 --- a/src/bin/psql/startup.c +++ b/src/bin/psql/startup.c @@ -7,8 +7,6 @@ */ #include "postgres_fe.h" -#include - #ifndef WIN32 #include #else /* WIN32 */ @@ -18,8 +16,6 @@ #include "getopt_long.h" -#include - #include "command.h" #include "common.h" #include "describe.h" diff --git a/src/common/ip.c b/src/common/ip.c index d981dbcac9..80711dbb98 100644 --- a/src/common/ip.c +++ b/src/common/ip.c @@ -24,7 +24,6 @@ #endif #include -#include #include #include #include diff --git a/src/common/username.c b/src/common/username.c index d6abac8281..487eacfe73 100644 --- a/src/common/username.c +++ b/src/common/username.c @@ -18,10 +18,8 @@ #include "postgres_fe.h" #endif -#include #include #include -#include #include "common/username.h" diff --git a/src/common/wait_error.c b/src/common/wait_error.c index 7ac545c67a..f824a5f2af 100644 --- a/src/common/wait_error.c +++ b/src/common/wait_error.c @@ -21,8 +21,6 @@ #endif #include -#include -#include #include /* diff --git a/src/fe_utils/print.c b/src/fe_utils/print.c index 5ca27a93e0..9180b90004 100644 --- a/src/fe_utils/print.c +++ b/src/fe_utils/print.c @@ -18,7 +18,6 @@ #include "postgres_fe.h" #include -#include #include #include #include diff --git a/src/include/libpq/libpq.h b/src/include/libpq/libpq.h index 538066e106..d4885a5e28 100644 --- a/src/include/libpq/libpq.h +++ b/src/include/libpq/libpq.h @@ -14,7 +14,6 @@ #ifndef LIBPQ_H #define LIBPQ_H -#include #include #include "lib/stringinfo.h" diff --git a/src/include/port/atomics/generic-msvc.h b/src/include/port/atomics/generic-msvc.h index c7caf04d57..d5ee6e1bcb 100644 --- a/src/include/port/atomics/generic-msvc.h +++ b/src/include/port/atomics/generic-msvc.h @@ -17,7 +17,6 @@ *------------------------------------------------------------------------- */ #include -#include /* intentionally no include guards, should only be included by atomics.h */ #ifndef INSIDE_ATOMICS_H diff --git a/src/include/utils/pg_locale.h b/src/include/utils/pg_locale.h index be91f9b88c..cb509e2b6b 100644 --- a/src/include/utils/pg_locale.h +++ b/src/include/utils/pg_locale.h @@ -12,7 +12,6 @@ #ifndef _PG_LOCALE_ #define _PG_LOCALE_ -#include #if defined(LOCALE_T_IN_XLOCALE) || defined(WCSTOMBS_L_IN_XLOCALE) #include #endif diff --git a/src/interfaces/ecpg/ecpglib/data.c b/src/interfaces/ecpg/ecpglib/data.c index 23646a9579..499a4c1780 100644 --- a/src/interfaces/ecpg/ecpglib/data.c +++ b/src/interfaces/ecpg/ecpglib/data.c @@ -3,8 +3,6 @@ #define POSTGRES_ECPG_INTERNAL #include "postgres_fe.h" -#include -#include #include #include diff --git a/src/interfaces/ecpg/ecpglib/execute.c b/src/interfaces/ecpg/ecpglib/execute.c index d5a463d940..bd9b86be49 100644 --- a/src/interfaces/ecpg/ecpglib/execute.c +++ b/src/interfaces/ecpg/ecpglib/execute.c @@ -16,7 +16,6 @@ #define POSTGRES_ECPG_INTERNAL #include "postgres_fe.h" -#include #include #include diff --git a/src/interfaces/ecpg/ecpglib/typename.c b/src/interfaces/ecpg/ecpglib/typename.c index db65ec10f1..f90279cf81 100644 --- a/src/interfaces/ecpg/ecpglib/typename.c +++ b/src/interfaces/ecpg/ecpglib/typename.c @@ -3,7 +3,6 @@ #define POSTGRES_ECPG_INTERNAL #include "postgres_fe.h" -#include #include "ecpgtype.h" #include "ecpglib.h" #include "extern.h" diff --git a/src/interfaces/ecpg/preproc/ecpg.c b/src/interfaces/ecpg/preproc/ecpg.c index fa80bb289e..aaecbf8122 100644 --- a/src/interfaces/ecpg/preproc/ecpg.c +++ b/src/interfaces/ecpg/preproc/ecpg.c @@ -6,7 +6,7 @@ #include "postgres_fe.h" #include -#include + #include "getopt_long.h" #include "extern.h" diff --git a/src/interfaces/ecpg/preproc/pgc.l b/src/interfaces/ecpg/preproc/pgc.l index b894a33e53..6b58dd5afe 100644 --- a/src/interfaces/ecpg/preproc/pgc.l +++ b/src/interfaces/ecpg/preproc/pgc.l @@ -19,7 +19,6 @@ #include "postgres_fe.h" #include -#include #include #include "extern.h" diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index 65b7c31dc0..685f355ab3 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -15,7 +15,6 @@ #include "postgres_fe.h" -#include #include #include #include diff --git a/src/interfaces/libpq/libpq-int.h b/src/interfaces/libpq/libpq-int.h index e9b73a925e..24242da221 100644 --- a/src/interfaces/libpq/libpq-int.h +++ b/src/interfaces/libpq/libpq-int.h @@ -25,7 +25,6 @@ #include "libpq-events.h" #include -#include #ifndef WIN32 #include #endif diff --git a/src/interfaces/libpq/pthread-win32.c b/src/interfaces/libpq/pthread-win32.c index e63432d822..0e0d3eeb88 100644 --- a/src/interfaces/libpq/pthread-win32.c +++ b/src/interfaces/libpq/pthread-win32.c @@ -12,7 +12,6 @@ #include "postgres_fe.h" -#include #include "pthread-win32.h" DWORD diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c index fc10d30f45..00979cba74 100644 --- a/src/pl/plperl/plperl.c +++ b/src/pl/plperl/plperl.c @@ -13,7 +13,6 @@ #include #include #include -#include #include /* postgreSQL stuff */ diff --git a/src/port/chklocale.c b/src/port/chklocale.c index 54ce9410f0..c6ec929702 100644 --- a/src/port/chklocale.c +++ b/src/port/chklocale.c @@ -19,11 +19,6 @@ #include "postgres_fe.h" #endif -#if defined(WIN32) && (_MSC_VER >= 1900) -#include -#endif - -#include #ifdef HAVE_LANGINFO_H #include #endif diff --git a/src/port/dirmod.c b/src/port/dirmod.c index 08835962be..84039ff38a 100644 --- a/src/port/dirmod.c +++ b/src/port/dirmod.c @@ -34,7 +34,6 @@ #ifndef __CYGWIN__ #include #else -#include #include #endif #endif diff --git a/src/port/inet_net_ntop.c b/src/port/inet_net_ntop.c index 047895e4f4..cebcda0e61 100644 --- a/src/port/inet_net_ntop.c +++ b/src/port/inet_net_ntop.c @@ -27,7 +27,6 @@ static const char rcsid[] = "Id: inet_net_ntop.c,v 1.1.2.2 2004/03/09 09:17:27 m #include "postgres_fe.h" #endif -#include #include #include #include diff --git a/src/port/open.c b/src/port/open.c index db7abdbe03..aa31342261 100644 --- a/src/port/open.c +++ b/src/port/open.c @@ -19,7 +19,6 @@ #include "postgres_fe.h" #endif -#include #include #include diff --git a/src/port/system.c b/src/port/system.c index 8651187890..3d99c7985f 100644 --- a/src/port/system.c +++ b/src/port/system.c @@ -44,7 +44,6 @@ #include "postgres_fe.h" #endif -#include #include #undef system diff --git a/src/test/isolation/isolationtester.c b/src/test/isolation/isolationtester.c index db2b55982b..f77f465751 100644 --- a/src/test/isolation/isolationtester.c +++ b/src/test/isolation/isolationtester.c @@ -7,9 +7,6 @@ #include "postgres_fe.h" -#ifdef WIN32 -#include -#endif #include #ifdef HAVE_SYS_SELECT_H #include diff --git a/src/timezone/strftime.c b/src/timezone/strftime.c index 4a0a01db65..acaba86881 100644 --- a/src/timezone/strftime.c +++ b/src/timezone/strftime.c @@ -41,7 +41,6 @@ #include "postgres.h" #include -#include #include "private.h" #include "tzfile.h" diff --git a/src/timezone/zic.c b/src/timezone/zic.c index a83cea12dd..e1875585df 100644 --- a/src/timezone/zic.c +++ b/src/timezone/zic.c @@ -9,7 +9,6 @@ #include "postgres_fe.h" #include -#include #include #include #include -- cgit v1.2.3 From e18b2c480da478f62781e06488cda56fe1b4e919 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 30 Apr 2017 15:13:51 -0400 Subject: Sync our copy of the timezone library with IANA release tzcode2017b. zic no longer mishandles some transitions in January 2038 when it attempts to work around Qt bug 53071. This fixes a bug affecting Pacific/Tongatapu that was introduced in zic 2016e. localtime.c now contains a workaround, useful when loading a file generated by a buggy zic. There are assorted cosmetic changes as well, notably relocation of a bunch of #defines. --- src/timezone/README | 2 +- src/timezone/localtime.c | 73 +++++++++++++++++++++++++++++++++++----------- src/timezone/pgtz.c | 9 +++--- src/timezone/private.h | 76 ++++++++++++++++++++++++++++++++++++------------ src/timezone/strftime.c | 11 +++++-- src/timezone/tzfile.h | 52 --------------------------------- src/timezone/zic.c | 15 ++++++++-- 7 files changed, 139 insertions(+), 99 deletions(-) (limited to 'src/timezone/strftime.c') diff --git a/src/timezone/README b/src/timezone/README index a82d77c7ba..2544230c4c 100644 --- a/src/timezone/README +++ b/src/timezone/README @@ -50,7 +50,7 @@ match properly on the old version. Time Zone code ============== -The code in this directory is currently synced with tzcode release 2016j. +The code in this directory is currently synced with tzcode release 2017b. There are many cosmetic (and not so cosmetic) differences from the original tzcode library, but diffs in the upstream version should usually be propagated to our version. Here are some notes about that. diff --git a/src/timezone/localtime.c b/src/timezone/localtime.c index e6c1beaf96..154124e49c 100644 --- a/src/timezone/localtime.c +++ b/src/timezone/localtime.c @@ -17,8 +17,9 @@ #include #include "datatype/timestamp.h" -#include "private.h" #include "pgtz.h" + +#include "private.h" #include "tzfile.h" @@ -414,10 +415,10 @@ tzloadbody(char const * name, char *canonname, struct state * sp, bool doextend, { /* * Attempt to reuse existing abbreviations. Without this, - * America/Anchorage would stop working after 2037 when - * TZ_MAX_CHARS is 50, as sp->charcnt equals 42 (for LMT CAT CAWT - * CAPT AHST AHDT YST AKDT AKST) and ts->charcnt equals 10 (for - * AKST AKDT). Reusing means sp->charcnt can stay 42 in this + * America/Anchorage would be right on the edge after 2037 when + * TZ_MAX_CHARS is 50, as sp->charcnt equals 40 (for LMT AST AWT + * APT AHST AHDT YST AKDT AKST) and ts->charcnt equals 10 (for + * AKST AKDT). Reusing means sp->charcnt can stay 40 in this * example. */ int gotabbr = 0; @@ -451,6 +452,17 @@ tzloadbody(char const * name, char *canonname, struct state * sp, bool doextend, if (gotabbr == 2) { sp->charcnt = charcnt; + + /* + * Ignore any trailing, no-op transitions generated by zic as + * they don't help here and can run afoul of bugs in zic 2016j + * or earlier. + */ + while (1 < sp->timecnt + && (sp->types[sp->timecnt - 1] + == sp->types[sp->timecnt - 2])) + sp->timecnt--; + for (i = 0; i < ts->timecnt; i++) if (sp->ats[sp->timecnt - 1] < ts->ats[i]) break; @@ -974,6 +986,8 @@ tzparse(const char *name, struct state * sp, bool lastditch) int yearlim; int timecnt; pg_time_t janfirst; + int32 janoffset = 0; + int yearbeg; ++name; if ((name = getrule(name, &start)) == NULL) @@ -994,8 +1008,23 @@ tzparse(const char *name, struct state * sp, bool lastditch) sp->defaulttype = 0; timecnt = 0; janfirst = 0; - yearlim = EPOCH_YEAR + YEARSPERREPEAT; - for (year = EPOCH_YEAR; year < yearlim; year++) + yearbeg = EPOCH_YEAR; + + do + { + int32 yearsecs + = year_lengths[isleap(yearbeg - 1)] * SECSPERDAY; + + yearbeg--; + if (increment_overflow_time(&janfirst, -yearsecs)) + { + janoffset = -yearsecs; + break; + } + } while (EPOCH_YEAR - YEARSPERREPEAT / 2 < yearbeg); + + yearlim = yearbeg + YEARSPERREPEAT + 1; + for (year = yearbeg; year < yearlim; year++) { int32 starttime = transtime(year, &start, stdoffset), @@ -1020,24 +1049,34 @@ tzparse(const char *name, struct state * sp, bool lastditch) { if (TZ_MAX_TIMES - 2 < timecnt) break; - yearlim = year + YEARSPERREPEAT + 1; sp->ats[timecnt] = janfirst; - if (increment_overflow_time - (&sp->ats[timecnt], starttime)) - break; - sp->types[timecnt++] = reversed; + if (!increment_overflow_time + (&sp->ats[timecnt], + janoffset + starttime)) + sp->types[timecnt++] = reversed; + else if (janoffset) + sp->defaulttype = reversed; sp->ats[timecnt] = janfirst; - if (increment_overflow_time - (&sp->ats[timecnt], endtime)) - break; - sp->types[timecnt++] = !reversed; + if (!increment_overflow_time + (&sp->ats[timecnt], + janoffset + endtime)) + { + sp->types[timecnt++] = !reversed; + yearlim = year + YEARSPERREPEAT + 1; + } + else if (janoffset) + sp->defaulttype = !reversed; } - if (increment_overflow_time(&janfirst, yearsecs)) + if (increment_overflow_time + (&janfirst, janoffset + yearsecs)) break; + janoffset = 0; } sp->timecnt = timecnt; if (!timecnt) sp->typecnt = 1; /* Perpetual DST. */ + else if (YEARSPERREPEAT < year - yearbeg) + sp->goback = sp->goahead = true; } else { diff --git a/src/timezone/pgtz.c b/src/timezone/pgtz.c index b7cfc5f5ac..13ce399033 100644 --- a/src/timezone/pgtz.c +++ b/src/timezone/pgtz.c @@ -17,6 +17,7 @@ #include #include +#include "datatype/timestamp.h" #include "miscadmin.h" #include "pgtz.h" #include "storage/fd.h" @@ -308,14 +309,14 @@ pg_tzset_offset(long gmtoffset) char tzname[128]; snprintf(offsetstr, sizeof(offsetstr), - "%02ld", absoffset / SECSPERHOUR); - absoffset %= SECSPERHOUR; + "%02ld", absoffset / SECS_PER_HOUR); + absoffset %= SECS_PER_HOUR; if (absoffset != 0) { snprintf(offsetstr + strlen(offsetstr), sizeof(offsetstr) - strlen(offsetstr), - ":%02ld", absoffset / SECSPERMIN); - absoffset %= SECSPERMIN; + ":%02ld", absoffset / SECS_PER_MINUTE); + absoffset %= SECS_PER_MINUTE; if (absoffset != 0) snprintf(offsetstr + strlen(offsetstr), sizeof(offsetstr) - strlen(offsetstr), diff --git a/src/timezone/private.h b/src/timezone/private.h index b8533d51e8..f031b17b7e 100644 --- a/src/timezone/private.h +++ b/src/timezone/private.h @@ -67,14 +67,8 @@ extern int unlink(const char *filename); * Finally, some convenience items. */ -#ifndef TYPE_BIT #define TYPE_BIT(type) (sizeof (type) * CHAR_BIT) -#endif /* !defined TYPE_BIT */ - -#ifndef TYPE_SIGNED #define TYPE_SIGNED(type) (((type) -1) < 0) -#endif /* !defined TYPE_SIGNED */ - #define TWOS_COMPLEMENT(t) ((t) ~ (t) 0 < 0) /* @@ -88,7 +82,6 @@ extern int unlink(const char *filename); #define MINVAL(t, b) \ ((t) (TYPE_SIGNED(t) ? - TWOS_COMPLEMENT(t) - MAXVAL(t, b) : 0)) -#ifndef INT_STRLEN_MAXIMUM /* * 302 / 1000 is log10(2.0) rounded up. * Subtract one for the sign bit if the type is signed; @@ -98,7 +91,6 @@ extern int unlink(const char *filename); #define INT_STRLEN_MAXIMUM(type) \ ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \ 1 + TYPE_SIGNED(type)) -#endif /* !defined INT_STRLEN_MAXIMUM */ /* * INITIALIZE(x) @@ -108,24 +100,70 @@ extern int unlink(const char *filename); #undef _ #define _(msgid) (msgid) -#ifndef YEARSPERREPEAT +/* Handy macros that are independent of tzfile implementation. */ + #define YEARSPERREPEAT 400 /* years before a Gregorian repeat */ -#endif /* !defined YEARSPERREPEAT */ + +#define SECSPERMIN 60 +#define MINSPERHOUR 60 +#define HOURSPERDAY 24 +#define DAYSPERWEEK 7 +#define DAYSPERNYEAR 365 +#define DAYSPERLYEAR 366 +#define SECSPERHOUR (SECSPERMIN * MINSPERHOUR) +#define SECSPERDAY ((int32) SECSPERHOUR * HOURSPERDAY) +#define MONSPERYEAR 12 + +#define TM_SUNDAY 0 +#define TM_MONDAY 1 +#define TM_TUESDAY 2 +#define TM_WEDNESDAY 3 +#define TM_THURSDAY 4 +#define TM_FRIDAY 5 +#define TM_SATURDAY 6 + +#define TM_JANUARY 0 +#define TM_FEBRUARY 1 +#define TM_MARCH 2 +#define TM_APRIL 3 +#define TM_MAY 4 +#define TM_JUNE 5 +#define TM_JULY 6 +#define TM_AUGUST 7 +#define TM_SEPTEMBER 8 +#define TM_OCTOBER 9 +#define TM_NOVEMBER 10 +#define TM_DECEMBER 11 + +#define TM_YEAR_BASE 1900 + +#define EPOCH_YEAR 1970 +#define EPOCH_WDAY TM_THURSDAY + +#define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0)) /* - * The Gregorian year averages 365.2425 days, which is 31556952 seconds. + * Since everything in isleap is modulo 400 (or a factor of 400), we know that + * isleap(y) == isleap(y % 400) + * and so + * isleap(a + b) == isleap((a + b) % 400) + * or + * isleap(a + b) == isleap(a % 400 + b % 400) + * This is true even if % means modulo rather than Fortran remainder + * (which is allowed by C89 but not C99). + * We use this to avoid addition overflow problems. */ -#ifndef AVGSECSPERYEAR -#define AVGSECSPERYEAR 31556952L -#endif /* !defined AVGSECSPERYEAR */ +#define isleap_sum(a, b) isleap((a) % 400 + (b) % 400) -#ifndef SECSPERREPEAT -#define SECSPERREPEAT ((int64) YEARSPERREPEAT * (int64) AVGSECSPERYEAR) -#endif /* !defined SECSPERREPEAT */ -#ifndef SECSPERREPEAT_BITS +/* + * The Gregorian year averages 365.2425 days, which is 31556952 seconds. + */ + +#define AVGSECSPERYEAR 31556952L +#define SECSPERREPEAT \ + ((int64) YEARSPERREPEAT * (int64) AVGSECSPERYEAR) #define SECSPERREPEAT_BITS 34 /* ceil(log2(SECSPERREPEAT)) */ -#endif /* !defined SECSPERREPEAT_BITS */ #endif /* !defined PRIVATE_H */ diff --git a/src/timezone/strftime.c b/src/timezone/strftime.c index acaba86881..d9a18d49a8 100644 --- a/src/timezone/strftime.c +++ b/src/timezone/strftime.c @@ -1,4 +1,4 @@ -/* Convert a broken-down time stamp to a string. */ +/* Convert a broken-down timestamp to a string. */ /* * Copyright 1989 The Regents of the University of California. @@ -43,7 +43,6 @@ #include #include "private.h" -#include "tzfile.h" struct lc_time_T @@ -451,11 +450,17 @@ _fmt(const char *format, const struct pg_tm * t, char *pt, const char *ptlim, { long diff; char const *sign; + bool negative; if (t->tm_isdst < 0) continue; diff = t->tm_gmtoff; - if (diff < 0) + negative = diff < 0; + if (diff == 0) + { + negative = t->tm_zone[0] == '-'; + } + if (negative) { sign = "-"; diff = -diff; diff --git a/src/timezone/tzfile.h b/src/timezone/tzfile.h index 32d237b827..56a5b43472 100644 --- a/src/timezone/tzfile.h +++ b/src/timezone/tzfile.h @@ -100,56 +100,4 @@ struct tzhead #define TZ_MAX_LEAPS 50 /* Maximum number of leap second corrections */ -#define SECSPERMIN 60 -#define MINSPERHOUR 60 -#define HOURSPERDAY 24 -#define DAYSPERWEEK 7 -#define DAYSPERNYEAR 365 -#define DAYSPERLYEAR 366 -#define SECSPERHOUR (SECSPERMIN * MINSPERHOUR) -#define SECSPERDAY ((int32) SECSPERHOUR * HOURSPERDAY) -#define MONSPERYEAR 12 - -#define TM_SUNDAY 0 -#define TM_MONDAY 1 -#define TM_TUESDAY 2 -#define TM_WEDNESDAY 3 -#define TM_THURSDAY 4 -#define TM_FRIDAY 5 -#define TM_SATURDAY 6 - -#define TM_JANUARY 0 -#define TM_FEBRUARY 1 -#define TM_MARCH 2 -#define TM_APRIL 3 -#define TM_MAY 4 -#define TM_JUNE 5 -#define TM_JULY 6 -#define TM_AUGUST 7 -#define TM_SEPTEMBER 8 -#define TM_OCTOBER 9 -#define TM_NOVEMBER 10 -#define TM_DECEMBER 11 - -#define TM_YEAR_BASE 1900 - -#define EPOCH_YEAR 1970 -#define EPOCH_WDAY TM_THURSDAY - -#define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0)) - -/* - * Since everything in isleap is modulo 400 (or a factor of 400), we know that - * isleap(y) == isleap(y % 400) - * and so - * isleap(a + b) == isleap((a + b) % 400) - * or - * isleap(a + b) == isleap(a % 400 + b % 400) - * This is true even if % means modulo rather than Fortran remainder - * (which is allowed by C89 but not C99). - * We use this to avoid addition overflow problems. - */ - -#define isleap_sum(a, b) isleap((a) % 400 + (b) % 400) - #endif /* !defined TZFILE_H */ diff --git a/src/timezone/zic.c b/src/timezone/zic.c index e1875585df..5fa0a81262 100644 --- a/src/timezone/zic.c +++ b/src/timezone/zic.c @@ -2671,6 +2671,9 @@ outzone(const struct zone * zpfirst, ptrdiff_t zonecount) bool do_extend; char version; ptrdiff_t lastatmax = -1; + zic_t one = 1; + zic_t y2038_boundary = one << 31; + zic_t max_year0; max_abbr_len = 2 + max_format_len + max_abbrvar_len; max_envvar_len = 2 * max_abbr_len + 5 * 9; @@ -2780,12 +2783,13 @@ outzone(const struct zone * zpfirst, ptrdiff_t zonecount) } /* - * For the benefit of older systems, generate data from 1900 through 2037. + * For the benefit of older systems, generate data from 1900 through 2038. */ if (min_year > 1900) min_year = 1900; - if (max_year < 2037) - max_year = 2037; + max_year0 = max_year; + if (max_year < 2038) + max_year = 2038; for (i = 0; i < zonecount; ++i) { /* @@ -2835,7 +2839,12 @@ outzone(const struct zone * zpfirst, ptrdiff_t zonecount) year <= rp->r_hiyear && yearistype(year, rp->r_yrtype); if (rp->r_todo) + { rp->r_temp = rpytime(rp, year); + rp->r_todo + = (rp->r_temp < y2038_boundary + || year <= max_year0); + } } for (;;) { -- cgit v1.2.3 From a54d5875fe0bc19d05236b85e1e1bf0af9fa2902 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 7 May 2017 12:33:12 -0400 Subject: Guard against null t->tm_zone in strftime.c. The upstream IANA code does not guard against null TM_ZONE pointers in this function, but in our code there is such a check in the other pre-existing use of t->tm_zone. We do have some places that set pg_tm.tm_zone to NULL. I'm not entirely sure it's possible to reach strftime with such a value, but I'm not sure it isn't either, so be safe. Per Coverity complaint. --- src/timezone/strftime.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/timezone/strftime.c') diff --git a/src/timezone/strftime.c b/src/timezone/strftime.c index d9a18d49a8..3f6ba395c6 100644 --- a/src/timezone/strftime.c +++ b/src/timezone/strftime.c @@ -458,7 +458,8 @@ _fmt(const char *format, const struct pg_tm * t, char *pt, const char *ptlim, negative = diff < 0; if (diff == 0) { - negative = t->tm_zone[0] == '-'; + if (t->tm_zone != NULL) + negative = t->tm_zone[0] == '-'; } if (negative) { -- cgit v1.2.3