]> granicus.if.org Git - postgresql/commitdiff
Fix new warnings from GCC 7
authorPeter Eisentraut <peter_e@gmx.net>
Tue, 11 Apr 2017 18:13:31 +0000 (14:13 -0400)
committerPeter Eisentraut <peter_e@gmx.net>
Mon, 15 May 2017 17:31:38 +0000 (13:31 -0400)
This addresses the new warning types -Wformat-truncation
-Wformat-overflow that are part of -Wall, via -Wformat, in GCC 7.

17 files changed:
contrib/pg_archivecleanup/pg_archivecleanup.c
contrib/pg_standby/pg_standby.c
contrib/pg_upgrade/relfilenode.c
src/backend/access/transam/xlog.c
src/backend/postmaster/pgstat.c
src/backend/replication/basebackup.c
src/backend/storage/file/copydir.c
src/backend/storage/file/fd.c
src/backend/storage/file/reinit.c
src/backend/utils/adt/dbsize.c
src/backend/utils/cache/relcache.c
src/backend/utils/error/elog.c
src/backend/utils/time/snapmgr.c
src/bin/initdb/initdb.c
src/bin/pg_basebackup/pg_receivexlog.c
src/bin/pg_resetxlog/pg_resetxlog.c
src/timezone/pgtz.c

index ee7cba6b707e857ed054f8954fe8b6a5079f4ef0..c21c0dac6d1def63605b42c7eb5c23ed2b365074 100644 (file)
@@ -41,7 +41,7 @@ char     *additional_ext = NULL;              /* Extension to remove from filenames */
 
 char      *archiveLocation;    /* where to find the archive? */
 char      *restartWALFileName; /* the file from which we can restart restore */
-char           WALFilePath[MAXPGPATH];         /* the file path including archive */
+char           WALFilePath[MAXPGPATH * 2];             /* the file path including archive */
 char           exclusiveCleanupFileName[MAXPGPATH];            /* the oldest file we
                                                                                                                 * want to remain in
                                                                                                                 * archive */
@@ -144,7 +144,7 @@ CleanupPriorWALFiles(void)
                                 * extension that might have been chopped off before testing
                                 * the sequence.
                                 */
-                               snprintf(WALFilePath, MAXPGPATH, "%s/%s",
+                               snprintf(WALFilePath, sizeof(WALFilePath), "%s/%s",
                                                 archiveLocation, xlde->d_name);
 
                                if (dryrun)
index 8be544bf70d714ffd79b84d2cedf70ba2e0e7947..2fb9b2bcac013a193d2fc706424ae95896e078ed 100644 (file)
@@ -66,7 +66,7 @@ char     *xlogFilePath;               /* where we are going to restore to */
 char      *nextWALFileName;    /* the file we need to get from archive */
 char      *restartWALFileName; /* the file from which we can restart restore */
 char      *priorWALFileName;   /* the file we need to get from archive */
-char           WALFilePath[MAXPGPATH];         /* the file path including archive */
+char           WALFilePath[MAXPGPATH * 2];             /* the file path including archive */
 char           restoreCommand[MAXPGPATH];      /* run this to restore */
 char           exclusiveCleanupFileName[MAXPGPATH];            /* the file we need to
                                                                                                                 * get from archive */
@@ -277,9 +277,9 @@ CustomizableCleanupPriorWALFiles(void)
                                  strcmp(xlde->d_name + 8, exclusiveCleanupFileName + 8) < 0)
                                {
 #ifdef WIN32
-                                       snprintf(WALFilePath, MAXPGPATH, "%s\\%s", archiveLocation, xlde->d_name);
+                                       snprintf(WALFilePath, sizeof(WALFilePath), "%s\\%s", archiveLocation, xlde->d_name);
 #else
-                                       snprintf(WALFilePath, MAXPGPATH, "%s/%s", archiveLocation, xlde->d_name);
+                                       snprintf(WALFilePath, sizeof(WALFilePath), "%s/%s", archiveLocation, xlde->d_name);
 #endif
 
                                        if (debug)
index 4cc9782da0fc7002edd8e9b64780fbe7e1dbb428..e39a44ab4291a3e6bda30720ad0fd599e3e5dcf4 100644 (file)
@@ -215,8 +215,8 @@ transfer_relfile(pageCnvCtx *pageConverter, FileNameMap *map,
                                 const char *type_suffix)
 {
        const char *msg;
-       char            old_file[MAXPGPATH];
-       char            new_file[MAXPGPATH];
+       char            old_file[MAXPGPATH * 3];
+       char            new_file[MAXPGPATH * 3];
        int                     fd;
        int                     segno;
        char            extent_suffix[65];
index 2d514eca1043f2a59a27859c549525fc6b42bd04..33af2f629143e55bf9978e8473455d50fc75623f 100644 (file)
@@ -3099,7 +3099,7 @@ CleanupBackupHistory(void)
 {
        DIR                *xldir;
        struct dirent *xlde;
-       char            path[MAXPGPATH];
+       char            path[MAXPGPATH + sizeof(XLOGDIR)];
 
        xldir = AllocateDir(XLOGDIR);
        if (xldir == NULL)
@@ -3120,7 +3120,7 @@ CleanupBackupHistory(void)
                                ereport(DEBUG2,
                                (errmsg("removing transaction log backup history file \"%s\"",
                                                xlde->d_name)));
-                               snprintf(path, MAXPGPATH, XLOGDIR "/%s", xlde->d_name);
+                               snprintf(path, sizeof(path), XLOGDIR "/%s", xlde->d_name);
                                unlink(path);
                                XLogArchiveCleanup(xlde->d_name);
                        }
index f9de610434ff64e41133ebfce719caf9deea4b0f..fc8709bbc1e6e6621bd5942f9929ad1b30861efd 100644 (file)
@@ -559,7 +559,7 @@ pgstat_reset_remove_files(const char *directory)
 {
        DIR                *dir;
        struct dirent *entry;
-       char            fname[MAXPGPATH];
+       char            fname[MAXPGPATH * 2];
 
        dir = AllocateDir(directory);
        while ((entry = ReadDir(dir, directory)) != NULL)
@@ -589,7 +589,7 @@ pgstat_reset_remove_files(const char *directory)
                        strcmp(entry->d_name + nchars, "stat") != 0)
                        continue;
 
-               snprintf(fname, MAXPGPATH, "%s/%s", directory,
+               snprintf(fname, sizeof(fname), "%s/%s", directory,
                                 entry->d_name);
                unlink(fname);
        }
index 4f4686d92530ebe429f2b8742113d2e0882fd9e1..587d7d61c2a34cd021241bc292095b85a7bf07b8 100644 (file)
@@ -122,7 +122,7 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir)
                /* Collect information about all tablespaces */
                while ((de = ReadDir(tblspcdir, "pg_tblspc")) != NULL)
                {
-                       char            fullpath[MAXPGPATH];
+                       char            fullpath[MAXPGPATH + 10];
                        char            linkpath[MAXPGPATH];
                        char       *relpath = NULL;
                        int                     rllen;
@@ -831,7 +831,7 @@ sendDir(char *path, int basepathlen, bool sizeonly, List *tablespaces)
 {
        DIR                *dir;
        struct dirent *de;
-       char            pathbuf[MAXPGPATH];
+       char            pathbuf[MAXPGPATH * 2];
        struct stat statbuf;
        int64           size = 0;
 
@@ -873,7 +873,7 @@ sendDir(char *path, int basepathlen, bool sizeonly, List *tablespaces)
                                                 "and should not be used. "
                                                 "Try taking another online backup.")));
 
-               snprintf(pathbuf, MAXPGPATH, "%s/%s", path, de->d_name);
+               snprintf(pathbuf, sizeof(pathbuf), "%s/%s", path, de->d_name);
 
                /* Skip postmaster.pid and postmaster.opts in the data directory */
                if (strcmp(pathbuf, "./postmaster.pid") == 0 ||
index 427a0df7182de5a00d7b807dec6aa8d4e66dce24..6460410df7bf3ceab4da7b55c2aaad3347f721e7 100644 (file)
@@ -38,8 +38,8 @@ copydir(char *fromdir, char *todir, bool recurse)
 {
        DIR                *xldir;
        struct dirent *xlde;
-       char            fromfile[MAXPGPATH];
-       char            tofile[MAXPGPATH];
+       char            fromfile[MAXPGPATH * 2];
+       char            tofile[MAXPGPATH * 2];
 
        if (mkdir(todir, S_IRWXU) != 0)
                ereport(ERROR,
@@ -63,8 +63,8 @@ copydir(char *fromdir, char *todir, bool recurse)
                        strcmp(xlde->d_name, "..") == 0)
                        continue;
 
-               snprintf(fromfile, MAXPGPATH, "%s/%s", fromdir, xlde->d_name);
-               snprintf(tofile, MAXPGPATH, "%s/%s", todir, xlde->d_name);
+               snprintf(fromfile, sizeof(fromfile), "%s/%s", fromdir, xlde->d_name);
+               snprintf(tofile, sizeof(tofile), "%s/%s", todir, xlde->d_name);
 
                if (lstat(fromfile, &fst) < 0)
                        ereport(ERROR,
@@ -103,7 +103,7 @@ copydir(char *fromdir, char *todir, bool recurse)
                        strcmp(xlde->d_name, "..") == 0)
                        continue;
 
-               snprintf(tofile, MAXPGPATH, "%s/%s", todir, xlde->d_name);
+               snprintf(tofile, sizeof(tofile), "%s/%s", todir, xlde->d_name);
 
                /*
                 * We don't need to sync subdirectories here since the recursive
index c269436800bf4537c4add9b052e7b8500eae1951..0c8dd78bacd703adbe910bca86456dfcb992a71a 100644 (file)
@@ -2460,7 +2460,7 @@ CleanupTempFiles(bool isProcExit)
 void
 RemovePgTempFiles(void)
 {
-       char            temp_path[MAXPGPATH];
+       char            temp_path[MAXPGPATH + 10 + sizeof(TABLESPACE_VERSION_DIRECTORY) + sizeof(PG_TEMP_FILES_DIR)];
        DIR                *spc_dir;
        struct dirent *spc_de;
 
@@ -2508,7 +2508,7 @@ RemovePgTempFilesInDir(const char *tmpdirname)
 {
        DIR                *temp_dir;
        struct dirent *temp_de;
-       char            rm_path[MAXPGPATH];
+       char            rm_path[MAXPGPATH * 2];
 
        temp_dir = AllocateDir(tmpdirname);
        if (temp_dir == NULL)
@@ -2549,7 +2549,7 @@ RemovePgTempRelationFiles(const char *tsdirname)
 {
        DIR                *ts_dir;
        struct dirent *de;
-       char            dbspace_path[MAXPGPATH];
+       char            dbspace_path[MAXPGPATH * 2];
 
        ts_dir = AllocateDir(tsdirname);
        if (ts_dir == NULL)
@@ -2590,7 +2590,7 @@ RemovePgTempRelationFilesInDbspace(const char *dbspacedirname)
 {
        DIR                *dbspace_dir;
        struct dirent *de;
-       char            rm_path[MAXPGPATH];
+       char            rm_path[MAXPGPATH * 2];
 
        dbspace_dir = AllocateDir(dbspacedirname);
        if (dbspace_dir == NULL)
@@ -2777,7 +2777,7 @@ walkdir(const char *path,
 
        while ((de = ReadDirExtended(dir, path, elevel)) != NULL)
        {
-               char            subpath[MAXPGPATH];
+               char            subpath[MAXPGPATH * 2];
                struct stat fst;
                int                     sret;
 
@@ -2787,7 +2787,7 @@ walkdir(const char *path,
                        strcmp(de->d_name, "..") == 0)
                        continue;
 
-               snprintf(subpath, MAXPGPATH, "%s/%s", path, de->d_name);
+               snprintf(subpath, sizeof(subpath), "%s/%s", path, de->d_name);
 
                if (process_symlinks)
                        sret = stat(subpath, &fst);
index 93172b0dddc8c682ae894a9350e976ba964b3730..3c8742cc29f9dfb96db8f6b57e7fc33c47a3b944 100644 (file)
@@ -48,7 +48,7 @@ typedef struct
 void
 ResetUnloggedRelations(int op)
 {
-       char            temp_path[MAXPGPATH];
+       char            temp_path[MAXPGPATH + 10 + sizeof(TABLESPACE_VERSION_DIRECTORY)];
        DIR                *spc_dir;
        struct dirent *spc_de;
        MemoryContext tmpctx,
@@ -106,7 +106,7 @@ ResetUnloggedRelationsInTablespaceDir(const char *tsdirname, int op)
 {
        DIR                *ts_dir;
        struct dirent *de;
-       char            dbspace_path[MAXPGPATH];
+       char            dbspace_path[MAXPGPATH * 2];
 
        ts_dir = AllocateDir(tsdirname);
        if (ts_dir == NULL)
@@ -147,7 +147,7 @@ ResetUnloggedRelationsInDbspaceDir(const char *dbspacedirname, int op)
 {
        DIR                *dbspace_dir;
        struct dirent *de;
-       char            rm_path[MAXPGPATH];
+       char            rm_path[MAXPGPATH * 2];
 
        /* Caller must specify at least one operation. */
        Assert((op & (UNLOGGED_RELATION_CLEANUP | UNLOGGED_RELATION_INIT)) != 0);
@@ -310,7 +310,7 @@ ResetUnloggedRelationsInDbspaceDir(const char *dbspacedirname, int op)
                        ForkNumber      forkNum;
                        int                     oidchars;
                        char            oidbuf[OIDCHARS + 1];
-                       char            srcpath[MAXPGPATH];
+                       char            srcpath[MAXPGPATH * 2];
                        char            dstpath[MAXPGPATH];
 
                        /* Skip anything that doesn't look like a relation data file. */
index 3d32dcad8d19570c7f09a06e18cb2e9b6b089127..6c69a01294af0cb805d9b2fcc6838ccb171ba078 100644 (file)
@@ -39,7 +39,7 @@ db_dir_size(const char *path)
        int64           dirsize = 0;
        struct dirent *direntry;
        DIR                *dirdesc;
-       char            filename[MAXPGPATH];
+       char            filename[MAXPGPATH * 2];
 
        dirdesc = AllocateDir(path);
 
@@ -56,7 +56,7 @@ db_dir_size(const char *path)
                        strcmp(direntry->d_name, "..") == 0)
                        continue;
 
-               snprintf(filename, MAXPGPATH, "%s/%s", path, direntry->d_name);
+               snprintf(filename, sizeof(filename), "%s/%s", path, direntry->d_name);
 
                if (stat(filename, &fst) < 0)
                {
@@ -84,7 +84,7 @@ calculate_database_size(Oid dbOid)
        DIR                *dirdesc;
        struct dirent *direntry;
        char            dirpath[MAXPGPATH];
-       char            pathname[MAXPGPATH];
+       char            pathname[MAXPGPATH + 12 + sizeof(TABLESPACE_VERSION_DIRECTORY)];
        AclResult       aclresult;
 
        /* User must have connect privilege for target database */
@@ -96,7 +96,7 @@ calculate_database_size(Oid dbOid)
        /* Shared storage in pg_global is not counted */
 
        /* Include pg_default storage */
-       snprintf(pathname, MAXPGPATH, "base/%u", dbOid);
+       snprintf(pathname, sizeof(pathname), "base/%u", dbOid);
        totalsize = db_dir_size(pathname);
 
        /* Scan the non-default tablespaces */
@@ -116,7 +116,7 @@ calculate_database_size(Oid dbOid)
                        strcmp(direntry->d_name, "..") == 0)
                        continue;
 
-               snprintf(pathname, MAXPGPATH, "pg_tblspc/%s/%s/%u",
+               snprintf(pathname, sizeof(pathname), "pg_tblspc/%s/%s/%u",
                                 direntry->d_name, TABLESPACE_VERSION_DIRECTORY, dbOid);
                totalsize += db_dir_size(pathname);
        }
@@ -164,7 +164,7 @@ static int64
 calculate_tablespace_size(Oid tblspcOid)
 {
        char            tblspcPath[MAXPGPATH];
-       char            pathname[MAXPGPATH];
+       char            pathname[MAXPGPATH * 2];
        int64           totalsize = 0;
        DIR                *dirdesc;
        struct dirent *direntry;
@@ -206,7 +206,7 @@ calculate_tablespace_size(Oid tblspcOid)
                        strcmp(direntry->d_name, "..") == 0)
                        continue;
 
-               snprintf(pathname, MAXPGPATH, "%s/%s", tblspcPath, direntry->d_name);
+               snprintf(pathname, sizeof(pathname), "%s/%s", tblspcPath, direntry->d_name);
 
                if (stat(pathname, &fst) < 0)
                {
index 79b0993b81ff6417399b1729e6e68fc2881783eb..799e9aebe9218a7432da1afe4e74a44840d33390 100644 (file)
@@ -4869,7 +4869,7 @@ RelationCacheInitFileRemove(void)
        const char *tblspcdir = "pg_tblspc";
        DIR                *dir;
        struct dirent *de;
-       char            path[MAXPGPATH];
+       char            path[MAXPGPATH + 10 + sizeof(TABLESPACE_VERSION_DIRECTORY)];
 
        /*
         * We zap the shared cache file too.  In theory it can't get out of sync
@@ -4911,7 +4911,7 @@ RelationCacheInitFileRemoveInDir(const char *tblspcpath)
 {
        DIR                *dir;
        struct dirent *de;
-       char            initfilename[MAXPGPATH];
+       char            initfilename[MAXPGPATH * 2];
 
        /* Scan the tablespace directory to find per-database directories */
        dir = AllocateDir(tblspcpath);
index 526b5bb8fc75090c7679d8b21a3ee426c4bab27c..fcb5f180b23885fb6b99c111be72b399140bc00e 100644 (file)
@@ -2013,7 +2013,7 @@ setup_formatted_log_time(void)
 {
        struct timeval tv;
        pg_time_t       stamp_time;
-       char            msbuf[8];
+       char            msbuf[13];
 
        gettimeofday(&tv, NULL);
        stamp_time = (pg_time_t) tv.tv_sec;
index 3bf42423313748e18c63e104c3da530e15e7e45b..1cdf624287947f74d92fdfc0f549999c4ccb6368 100644 (file)
@@ -1155,7 +1155,7 @@ XactHasExportedSnapshots(void)
 void
 DeleteAllExportedSnapshotFiles(void)
 {
-       char            buf[MAXPGPATH];
+       char            buf[MAXPGPATH + sizeof(SNAPSHOT_EXPORT_DIR)];
        DIR                *s_dir;
        struct dirent *s_de;
 
@@ -1176,7 +1176,7 @@ DeleteAllExportedSnapshotFiles(void)
                        strcmp(s_de->d_name, "..") == 0)
                        continue;
 
-               snprintf(buf, MAXPGPATH, SNAPSHOT_EXPORT_DIR "/%s", s_de->d_name);
+               snprintf(buf, sizeof(buf), SNAPSHOT_EXPORT_DIR "/%s", s_de->d_name);
                /* Again, unlink failure is not worthy of FATAL */
                if (unlink(buf))
                        elog(LOG, "could not unlink file \"%s\": %m", buf);
index 07890d67bed7df873bf7a118d5e44811d583fb6b..47a4c617769b49fc3fa1ed6d93a6498d59711b0f 100644 (file)
@@ -556,7 +556,7 @@ walkdir(const char *path,
 
        while (errno = 0, (de = readdir(dir)) != NULL)
        {
-               char            subpath[MAXPGPATH];
+               char            subpath[MAXPGPATH * 2];
                struct stat fst;
                int                     sret;
 
@@ -564,7 +564,7 @@ walkdir(const char *path,
                        strcmp(de->d_name, "..") == 0)
                        continue;
 
-               snprintf(subpath, MAXPGPATH, "%s/%s", path, de->d_name);
+               snprintf(subpath, sizeof(subpath), "%s/%s", path, de->d_name);
 
                if (process_symlinks)
                        sret = stat(subpath, &fst);
index 240544f6f9b3ce8a62bf470ac55ddf7ee27986fa..8430d784500b7bc4fd3f91c00378ddae1bf91c20 100644 (file)
@@ -178,7 +178,7 @@ FindStreamingStart(uint32 *tli)
                if (!ispartial)
                {
                        struct stat statbuf;
-                       char            fullpath[MAXPGPATH];
+                       char            fullpath[MAXPGPATH * 2];
 
                        snprintf(fullpath, sizeof(fullpath), "%s/%s", basedir, dirent->d_name);
                        if (stat(fullpath, &statbuf) != 0)
index 8a066b46012584b09830f775731546000785e7cb..cc6b2540a8927eecb56409dcd6c9e2db1dea18ef 100644 (file)
@@ -836,7 +836,7 @@ KillExistingXLOG(void)
 {
        DIR                *xldir;
        struct dirent *xlde;
-       char            path[MAXPGPATH];
+       char            path[MAXPGPATH + sizeof(XLOGDIR)];
 
        xldir = opendir(XLOGDIR);
        if (xldir == NULL)
@@ -851,7 +851,7 @@ KillExistingXLOG(void)
                if (strlen(xlde->d_name) == 24 &&
                        strspn(xlde->d_name, "0123456789ABCDEF") == 24)
                {
-                       snprintf(path, MAXPGPATH, "%s/%s", XLOGDIR, xlde->d_name);
+                       snprintf(path, sizeof(path), "%s/%s", XLOGDIR, xlde->d_name);
                        if (unlink(path) < 0)
                        {
                                fprintf(stderr, _("%s: could not delete file \"%s\": %s\n"),
@@ -889,11 +889,11 @@ KillExistingXLOG(void)
 static void
 KillExistingArchiveStatus(void)
 {
+#define ARCHSTATDIR XLOGDIR "/archive_status"
+
        DIR                *xldir;
        struct dirent *xlde;
-       char            path[MAXPGPATH];
-
-#define ARCHSTATDIR XLOGDIR "/archive_status"
+       char            path[MAXPGPATH + sizeof(ARCHSTATDIR)];
 
        xldir = opendir(ARCHSTATDIR);
        if (xldir == NULL)
@@ -909,7 +909,7 @@ KillExistingArchiveStatus(void)
                        (strcmp(xlde->d_name + 24, ".ready") == 0 ||
                         strcmp(xlde->d_name + 24, ".done") == 0))
                {
-                       snprintf(path, MAXPGPATH, "%s/%s", ARCHSTATDIR, xlde->d_name);
+                       snprintf(path, sizeof(path), "%s/%s", ARCHSTATDIR, xlde->d_name);
                        if (unlink(path) < 0)
                        {
                                fprintf(stderr, _("%s: could not delete file \"%s\": %s\n"),
index d44458ae51abc9d68c9fb2a892b404a9a5b4d531..667fda3a637d4b44124a078a009f4c8829988c22 100644 (file)
@@ -437,7 +437,7 @@ pg_tzenumerate_next(pg_tzenum *dir)
        while (dir->depth >= 0)
        {
                struct dirent *direntry;
-               char            fullname[MAXPGPATH];
+               char            fullname[MAXPGPATH * 2];
                struct stat statbuf;
 
                direntry = ReadDir(dir->dirdesc[dir->depth], dir->dirname[dir->depth]);
@@ -454,7 +454,7 @@ pg_tzenumerate_next(pg_tzenum *dir)
                if (direntry->d_name[0] == '.')
                        continue;
 
-               snprintf(fullname, MAXPGPATH, "%s/%s",
+               snprintf(fullname, sizeof(fullname), "%s/%s",
                                 dir->dirname[dir->depth], direntry->d_name);
                if (stat(fullname, &statbuf) != 0)
                        ereport(ERROR,