mirror of
https://github.com/postgres/postgres.git
synced 2025-08-30 06:01:21 +03:00
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.
This commit is contained in:
@@ -3757,7 +3757,7 @@ CleanupBackupHistory(void)
|
||||
{
|
||||
DIR *xldir;
|
||||
struct dirent *xlde;
|
||||
char path[MAXPGPATH];
|
||||
char path[MAXPGPATH + sizeof(XLOGDIR)];
|
||||
|
||||
xldir = AllocateDir(XLOGDIR);
|
||||
if (xldir == NULL)
|
||||
@@ -3778,7 +3778,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);
|
||||
}
|
||||
|
@@ -115,7 +115,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;
|
||||
@@ -821,7 +821,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;
|
||||
|
||||
@@ -855,7 +855,7 @@ sendDir(char *path, int basepathlen, bool sizeonly, List *tablespaces)
|
||||
ereport(ERROR,
|
||||
(errmsg("shutdown requested, aborting active base 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 ||
|
||||
|
@@ -49,8 +49,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,
|
||||
@@ -74,8 +74,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,
|
||||
@@ -110,7 +110,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
|
||||
|
@@ -2282,7 +2282,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;
|
||||
|
||||
@@ -2330,7 +2330,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)
|
||||
@@ -2371,7 +2371,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)
|
||||
@@ -2412,7 +2412,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)
|
||||
@@ -2599,7 +2599,7 @@ walkdir(const char *path,
|
||||
|
||||
while ((de = ReadDirExtended(dir, path, elevel)) != NULL)
|
||||
{
|
||||
char subpath[MAXPGPATH];
|
||||
char subpath[MAXPGPATH * 2];
|
||||
struct stat fst;
|
||||
int sret;
|
||||
|
||||
@@ -2609,7 +2609,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);
|
||||
|
@@ -47,7 +47,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,
|
||||
@@ -105,7 +105,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)
|
||||
@@ -146,7 +146,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);
|
||||
@@ -309,7 +309,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. */
|
||||
|
@@ -37,7 +37,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);
|
||||
|
||||
@@ -54,7 +54,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)
|
||||
{
|
||||
@@ -82,7 +82,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 */
|
||||
@@ -94,7 +94,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 */
|
||||
@@ -114,7 +114,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);
|
||||
}
|
||||
@@ -162,7 +162,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;
|
||||
@@ -204,7 +204,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)
|
||||
{
|
||||
|
4
src/backend/utils/cache/relcache.c
vendored
4
src/backend/utils/cache/relcache.c
vendored
@@ -4659,7 +4659,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
|
||||
@@ -4701,7 +4701,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);
|
||||
|
@@ -1886,7 +1886,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;
|
||||
|
@@ -1154,7 +1154,7 @@ XactHasExportedSnapshots(void)
|
||||
void
|
||||
DeleteAllExportedSnapshotFiles(void)
|
||||
{
|
||||
char buf[MAXPGPATH];
|
||||
char buf[MAXPGPATH + sizeof(SNAPSHOT_EXPORT_DIR)];
|
||||
DIR *s_dir;
|
||||
struct dirent *s_de;
|
||||
|
||||
@@ -1175,7 +1175,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);
|
||||
|
Reference in New Issue
Block a user