Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 47b4913

Browse files
committed
Fix new warnings from GCC 7
This addresses the new warning types -Wformat-truncation -Wformat-overflow that are part of -Wall, via -Wformat, in GCC 7.
1 parent 21c2c3d commit 47b4913

File tree

22 files changed

+65
-65
lines changed

22 files changed

+65
-65
lines changed

contrib/pg_standby/pg_standby.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ char *xlogFilePath; /* where we are going to restore to */
5757
char *nextWALFileName; /* the file we need to get from archive */
5858
char *restartWALFileName; /* the file from which we can restart restore */
5959
char *priorWALFileName; /* the file we need to get from archive */
60-
char WALFilePath[MAXPGPATH]; /* the file path including archive */
60+
char WALFilePath[MAXPGPATH * 2]; /* the file path including archive */
6161
char restoreCommand[MAXPGPATH]; /* run this to restore */
6262
char exclusiveCleanupFileName[MAXFNAMELEN]; /* the file we need to
6363
* get from archive */
@@ -259,9 +259,9 @@ CustomizableCleanupPriorWALFiles(void)
259259
strcmp(xlde->d_name + 8, exclusiveCleanupFileName + 8) < 0)
260260
{
261261
#ifdef WIN32
262-
snprintf(WALFilePath, MAXPGPATH, "%s\\%s", archiveLocation, xlde->d_name);
262+
snprintf(WALFilePath, sizeof(WALFilePath), "%s\\%s", archiveLocation, xlde->d_name);
263263
#else
264-
snprintf(WALFilePath, MAXPGPATH, "%s/%s", archiveLocation, xlde->d_name);
264+
snprintf(WALFilePath, sizeof(WALFilePath), "%s/%s", archiveLocation, xlde->d_name);
265265
#endif
266266

267267
if (debug)

src/backend/access/heap/rewriteheap.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,7 @@ CheckPointLogicalRewriteHeap(void)
11941194
XLogRecPtr redo;
11951195
DIR *mappings_dir;
11961196
struct dirent *mapping_de;
1197-
char path[MAXPGPATH];
1197+
char path[MAXPGPATH + 20];
11981198

11991199
/*
12001200
* We start of with a minimum of the last redo pointer. No new decoding
@@ -1225,7 +1225,7 @@ CheckPointLogicalRewriteHeap(void)
12251225
strcmp(mapping_de->d_name, "..") == 0)
12261226
continue;
12271227

1228-
snprintf(path, MAXPGPATH, "pg_logical/mappings/%s", mapping_de->d_name);
1228+
snprintf(path, sizeof(path), "pg_logical/mappings/%s", mapping_de->d_name);
12291229
if (lstat(path, &statbuf) == 0 && !S_ISREG(statbuf.st_mode))
12301230
continue;
12311231

src/backend/access/transam/xlog.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -3941,7 +3941,7 @@ CleanupBackupHistory(void)
39413941
{
39423942
DIR *xldir;
39433943
struct dirent *xlde;
3944-
char path[MAXPGPATH];
3944+
char path[MAXPGPATH + sizeof(XLOGDIR)];
39453945

39463946
xldir = AllocateDir(XLOGDIR);
39473947
if (xldir == NULL)
@@ -3959,7 +3959,7 @@ CleanupBackupHistory(void)
39593959
ereport(DEBUG2,
39603960
(errmsg("removing transaction log backup history file \"%s\"",
39613961
xlde->d_name)));
3962-
snprintf(path, MAXPGPATH, XLOGDIR "/%s", xlde->d_name);
3962+
snprintf(path, sizeof(path), XLOGDIR "/%s", xlde->d_name);
39633963
unlink(path);
39643964
XLogArchiveCleanup(xlde->d_name);
39653965
}
@@ -10061,7 +10061,7 @@ do_pg_start_backup(const char *backupidstr, bool fast, TimeLineID *starttli_p,
1006110061
/* Collect information about all tablespaces */
1006210062
while ((de = ReadDir(tblspcdir, "pg_tblspc")) != NULL)
1006310063
{
10064-
char fullpath[MAXPGPATH];
10064+
char fullpath[MAXPGPATH + 10];
1006510065
char linkpath[MAXPGPATH];
1006610066
char *relpath = NULL;
1006710067
int rllen;

src/backend/postmaster/pgstat.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ pgstat_reset_remove_files(const char *directory)
569569
{
570570
DIR *dir;
571571
struct dirent *entry;
572-
char fname[MAXPGPATH];
572+
char fname[MAXPGPATH * 2];
573573

574574
dir = AllocateDir(directory);
575575
while ((entry = ReadDir(dir, directory)) != NULL)
@@ -599,7 +599,7 @@ pgstat_reset_remove_files(const char *directory)
599599
strcmp(entry->d_name + nchars, "stat") != 0)
600600
continue;
601601

602-
snprintf(fname, MAXPGPATH, "%s/%s", directory,
602+
snprintf(fname, sizeof(fname), "%s/%s", directory,
603603
entry->d_name);
604604
unlink(fname);
605605
}

src/backend/replication/basebackup.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ sendDir(char *path, int basepathlen, bool sizeonly, List *tablespaces,
888888
{
889889
DIR *dir;
890890
struct dirent *de;
891-
char pathbuf[MAXPGPATH];
891+
char pathbuf[MAXPGPATH * 2];
892892
struct stat statbuf;
893893
int64 size = 0;
894894

@@ -940,7 +940,7 @@ sendDir(char *path, int basepathlen, bool sizeonly, List *tablespaces,
940940
"and should not be used. "
941941
"Try taking another online backup.")));
942942

943-
snprintf(pathbuf, MAXPGPATH, "%s/%s", path, de->d_name);
943+
snprintf(pathbuf, sizeof(pathbuf), "%s/%s", path, de->d_name);
944944

945945
/* Skip postmaster.pid and postmaster.opts in the data directory */
946946
if (strcmp(pathbuf, "./postmaster.pid") == 0 ||

src/backend/replication/logical/reorderbuffer.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2650,7 +2650,7 @@ StartupReorderBuffer(void)
26502650
while ((logical_de = ReadDir(logical_dir, "pg_replslot")) != NULL)
26512651
{
26522652
struct stat statbuf;
2653-
char path[MAXPGPATH];
2653+
char path[MAXPGPATH * 2 + 12];
26542654

26552655
if (strcmp(logical_de->d_name, ".") == 0 ||
26562656
strcmp(logical_de->d_name, "..") == 0)

src/backend/replication/logical/snapbuild.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1831,7 +1831,7 @@ CheckPointSnapBuild(void)
18311831
XLogRecPtr redo;
18321832
DIR *snap_dir;
18331833
struct dirent *snap_de;
1834-
char path[MAXPGPATH];
1834+
char path[MAXPGPATH + 21];
18351835

18361836
/*
18371837
* We start of with a minimum of the last redo pointer. No new replication
@@ -1858,7 +1858,7 @@ CheckPointSnapBuild(void)
18581858
strcmp(snap_de->d_name, "..") == 0)
18591859
continue;
18601860

1861-
snprintf(path, MAXPGPATH, "pg_logical/snapshots/%s", snap_de->d_name);
1861+
snprintf(path, sizeof(path), "pg_logical/snapshots/%s", snap_de->d_name);
18621862

18631863
if (lstat(path, &statbuf) == 0 && !S_ISREG(statbuf.st_mode))
18641864
{

src/backend/replication/slot.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -918,13 +918,13 @@ StartupReplicationSlots(void)
918918
while ((replication_de = ReadDir(replication_dir, "pg_replslot")) != NULL)
919919
{
920920
struct stat statbuf;
921-
char path[MAXPGPATH];
921+
char path[MAXPGPATH + 12];
922922

923923
if (strcmp(replication_de->d_name, ".") == 0 ||
924924
strcmp(replication_de->d_name, "..") == 0)
925925
continue;
926926

927-
snprintf(path, MAXPGPATH, "pg_replslot/%s", replication_de->d_name);
927+
snprintf(path, sizeof(path), "pg_replslot/%s", replication_de->d_name);
928928

929929
/* we're only creating directories here, skip if it's not our's */
930930
if (lstat(path, &statbuf) == 0 && !S_ISDIR(statbuf.st_mode))
@@ -1148,7 +1148,7 @@ RestoreSlotFromDisk(const char *name)
11481148
{
11491149
ReplicationSlotOnDisk cp;
11501150
int i;
1151-
char path[MAXPGPATH];
1151+
char path[MAXPGPATH + 22];
11521152
int fd;
11531153
bool restored = false;
11541154
int readBytes;

src/backend/storage/file/copydir.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ copydir(char *fromdir, char *todir, bool recurse)
3838
{
3939
DIR *xldir;
4040
struct dirent *xlde;
41-
char fromfile[MAXPGPATH];
42-
char tofile[MAXPGPATH];
41+
char fromfile[MAXPGPATH * 2];
42+
char tofile[MAXPGPATH * 2];
4343

4444
if (mkdir(todir, S_IRWXU) != 0)
4545
ereport(ERROR,
@@ -63,8 +63,8 @@ copydir(char *fromdir, char *todir, bool recurse)
6363
strcmp(xlde->d_name, "..") == 0)
6464
continue;
6565

66-
snprintf(fromfile, MAXPGPATH, "%s/%s", fromdir, xlde->d_name);
67-
snprintf(tofile, MAXPGPATH, "%s/%s", todir, xlde->d_name);
66+
snprintf(fromfile, sizeof(fromfile), "%s/%s", fromdir, xlde->d_name);
67+
snprintf(tofile, sizeof(tofile), "%s/%s", todir, xlde->d_name);
6868

6969
if (lstat(fromfile, &fst) < 0)
7070
ereport(ERROR,
@@ -103,7 +103,7 @@ copydir(char *fromdir, char *todir, bool recurse)
103103
strcmp(xlde->d_name, "..") == 0)
104104
continue;
105105

106-
snprintf(tofile, MAXPGPATH, "%s/%s", todir, xlde->d_name);
106+
snprintf(tofile, sizeof(tofile), "%s/%s", todir, xlde->d_name);
107107

108108
/*
109109
* We don't need to sync subdirectories here since the recursive

src/backend/storage/file/fd.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -2654,7 +2654,7 @@ CleanupTempFiles(bool isProcExit)
26542654
void
26552655
RemovePgTempFiles(void)
26562656
{
2657-
char temp_path[MAXPGPATH];
2657+
char temp_path[MAXPGPATH + 10 + sizeof(TABLESPACE_VERSION_DIRECTORY) + sizeof(PG_TEMP_FILES_DIR)];
26582658
DIR *spc_dir;
26592659
struct dirent *spc_de;
26602660

@@ -2702,7 +2702,7 @@ RemovePgTempFilesInDir(const char *tmpdirname)
27022702
{
27032703
DIR *temp_dir;
27042704
struct dirent *temp_de;
2705-
char rm_path[MAXPGPATH];
2705+
char rm_path[MAXPGPATH * 2];
27062706

27072707
temp_dir = AllocateDir(tmpdirname);
27082708
if (temp_dir == NULL)
@@ -2743,7 +2743,7 @@ RemovePgTempRelationFiles(const char *tsdirname)
27432743
{
27442744
DIR *ts_dir;
27452745
struct dirent *de;
2746-
char dbspace_path[MAXPGPATH];
2746+
char dbspace_path[MAXPGPATH * 2];
27472747

27482748
ts_dir = AllocateDir(tsdirname);
27492749
if (ts_dir == NULL)
@@ -2784,7 +2784,7 @@ RemovePgTempRelationFilesInDbspace(const char *dbspacedirname)
27842784
{
27852785
DIR *dbspace_dir;
27862786
struct dirent *de;
2787-
char rm_path[MAXPGPATH];
2787+
char rm_path[MAXPGPATH * 2];
27882788

27892789
dbspace_dir = AllocateDir(dbspacedirname);
27902790
if (dbspace_dir == NULL)
@@ -2971,7 +2971,7 @@ walkdir(const char *path,
29712971

29722972
while ((de = ReadDirExtended(dir, path, elevel)) != NULL)
29732973
{
2974-
char subpath[MAXPGPATH];
2974+
char subpath[MAXPGPATH * 2];
29752975
struct stat fst;
29762976
int sret;
29772977

@@ -2981,7 +2981,7 @@ walkdir(const char *path,
29812981
strcmp(de->d_name, "..") == 0)
29822982
continue;
29832983

2984-
snprintf(subpath, MAXPGPATH, "%s/%s", path, de->d_name);
2984+
snprintf(subpath, sizeof(subpath), "%s/%s", path, de->d_name);
29852985

29862986
if (process_symlinks)
29872987
sret = stat(subpath, &fst);

src/backend/storage/file/reinit.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ typedef struct
4848
void
4949
ResetUnloggedRelations(int op)
5050
{
51-
char temp_path[MAXPGPATH];
51+
char temp_path[MAXPGPATH + 10 + sizeof(TABLESPACE_VERSION_DIRECTORY)];
5252
DIR *spc_dir;
5353
struct dirent *spc_de;
5454
MemoryContext tmpctx,
@@ -104,7 +104,7 @@ ResetUnloggedRelationsInTablespaceDir(const char *tsdirname, int op)
104104
{
105105
DIR *ts_dir;
106106
struct dirent *de;
107-
char dbspace_path[MAXPGPATH];
107+
char dbspace_path[MAXPGPATH * 2];
108108

109109
ts_dir = AllocateDir(tsdirname);
110110
if (ts_dir == NULL)
@@ -145,7 +145,7 @@ ResetUnloggedRelationsInDbspaceDir(const char *dbspacedirname, int op)
145145
{
146146
DIR *dbspace_dir;
147147
struct dirent *de;
148-
char rm_path[MAXPGPATH];
148+
char rm_path[MAXPGPATH * 2];
149149

150150
/* Caller must specify at least one operation. */
151151
Assert((op & (UNLOGGED_RELATION_CLEANUP | UNLOGGED_RELATION_INIT)) != 0);
@@ -308,7 +308,7 @@ ResetUnloggedRelationsInDbspaceDir(const char *dbspacedirname, int op)
308308
ForkNumber forkNum;
309309
int oidchars;
310310
char oidbuf[OIDCHARS + 1];
311-
char srcpath[MAXPGPATH];
311+
char srcpath[MAXPGPATH * 2];
312312
char dstpath[MAXPGPATH];
313313

314314
/* Skip anything that doesn't look like a relation data file. */

src/backend/storage/ipc/dsm.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,9 @@ dsm_cleanup_for_mmap(void)
306306
if (strncmp(dent->d_name, PG_DYNSHMEM_MMAP_FILE_PREFIX,
307307
strlen(PG_DYNSHMEM_MMAP_FILE_PREFIX)) == 0)
308308
{
309-
char buf[MAXPGPATH];
309+
char buf[MAXPGPATH + sizeof(PG_DYNSHMEM_DIR)];
310310

311-
snprintf(buf, MAXPGPATH, PG_DYNSHMEM_DIR "/%s", dent->d_name);
311+
snprintf(buf, sizeof(buf), PG_DYNSHMEM_DIR "/%s", dent->d_name);
312312

313313
elog(DEBUG2, "removing file \"%s\"", buf);
314314

src/backend/utils/adt/dbsize.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ db_dir_size(const char *path)
4141
int64 dirsize = 0;
4242
struct dirent *direntry;
4343
DIR *dirdesc;
44-
char filename[MAXPGPATH];
44+
char filename[MAXPGPATH * 2];
4545

4646
dirdesc = AllocateDir(path);
4747

@@ -58,7 +58,7 @@ db_dir_size(const char *path)
5858
strcmp(direntry->d_name, "..") == 0)
5959
continue;
6060

61-
snprintf(filename, MAXPGPATH, "%s/%s", path, direntry->d_name);
61+
snprintf(filename, sizeof(filename), "%s/%s", path, direntry->d_name);
6262

6363
if (stat(filename, &fst) < 0)
6464
{
@@ -86,7 +86,7 @@ calculate_database_size(Oid dbOid)
8686
DIR *dirdesc;
8787
struct dirent *direntry;
8888
char dirpath[MAXPGPATH];
89-
char pathname[MAXPGPATH];
89+
char pathname[MAXPGPATH + 12 + sizeof(TABLESPACE_VERSION_DIRECTORY)];
9090
AclResult aclresult;
9191

9292
/* User must have connect privilege for target database */
@@ -98,7 +98,7 @@ calculate_database_size(Oid dbOid)
9898
/* Shared storage in pg_global is not counted */
9999

100100
/* Include pg_default storage */
101-
snprintf(pathname, MAXPGPATH, "base/%u", dbOid);
101+
snprintf(pathname, sizeof(pathname), "base/%u", dbOid);
102102
totalsize = db_dir_size(pathname);
103103

104104
/* Scan the non-default tablespaces */
@@ -118,7 +118,7 @@ calculate_database_size(Oid dbOid)
118118
strcmp(direntry->d_name, "..") == 0)
119119
continue;
120120

121-
snprintf(pathname, MAXPGPATH, "pg_tblspc/%s/%s/%u",
121+
snprintf(pathname, sizeof(pathname), "pg_tblspc/%s/%s/%u",
122122
direntry->d_name, TABLESPACE_VERSION_DIRECTORY, dbOid);
123123
totalsize += db_dir_size(pathname);
124124
}
@@ -166,7 +166,7 @@ static int64
166166
calculate_tablespace_size(Oid tblspcOid)
167167
{
168168
char tblspcPath[MAXPGPATH];
169-
char pathname[MAXPGPATH];
169+
char pathname[MAXPGPATH * 2];
170170
int64 totalsize = 0;
171171
DIR *dirdesc;
172172
struct dirent *direntry;
@@ -208,7 +208,7 @@ calculate_tablespace_size(Oid tblspcOid)
208208
strcmp(direntry->d_name, "..") == 0)
209209
continue;
210210

211-
snprintf(pathname, MAXPGPATH, "%s/%s", tblspcPath, direntry->d_name);
211+
snprintf(pathname, sizeof(pathname), "%s/%s", tblspcPath, direntry->d_name);
212212

213213
if (stat(pathname, &fst) < 0)
214214
{

src/backend/utils/cache/relcache.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -5525,7 +5525,7 @@ RelationCacheInitFileRemove(void)
55255525
const char *tblspcdir = "pg_tblspc";
55265526
DIR *dir;
55275527
struct dirent *de;
5528-
char path[MAXPGPATH];
5528+
char path[MAXPGPATH + 10 + sizeof(TABLESPACE_VERSION_DIRECTORY)];
55295529

55305530
/*
55315531
* We zap the shared cache file too. In theory it can't get out of sync
@@ -5567,7 +5567,7 @@ RelationCacheInitFileRemoveInDir(const char *tblspcpath)
55675567
{
55685568
DIR *dir;
55695569
struct dirent *de;
5570-
char initfilename[MAXPGPATH];
5570+
char initfilename[MAXPGPATH * 2];
55715571

55725572
/* Scan the tablespace directory to find per-database directories */
55735573
dir = AllocateDir(tblspcpath);

src/backend/utils/error/elog.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2228,7 +2228,7 @@ static void
22282228
setup_formatted_log_time(void)
22292229
{
22302230
pg_time_t stamp_time;
2231-
char msbuf[8];
2231+
char msbuf[13];
22322232

22332233
if (!saved_timeval_set)
22342234
{

src/backend/utils/time/snapmgr.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1569,7 +1569,7 @@ XactHasExportedSnapshots(void)
15691569
void
15701570
DeleteAllExportedSnapshotFiles(void)
15711571
{
1572-
char buf[MAXPGPATH];
1572+
char buf[MAXPGPATH + sizeof(SNAPSHOT_EXPORT_DIR)];
15731573
DIR *s_dir;
15741574
struct dirent *s_de;
15751575

@@ -1590,7 +1590,7 @@ DeleteAllExportedSnapshotFiles(void)
15901590
strcmp(s_de->d_name, "..") == 0)
15911591
continue;
15921592

1593-
snprintf(buf, MAXPGPATH, SNAPSHOT_EXPORT_DIR "/%s", s_de->d_name);
1593+
snprintf(buf, sizeof(buf), SNAPSHOT_EXPORT_DIR "/%s", s_de->d_name);
15941594
/* Again, unlink failure is not worthy of FATAL */
15951595
if (unlink(buf))
15961596
elog(LOG, "could not unlink file \"%s\": %m", buf);

0 commit comments

Comments
 (0)