diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2011-01-22 17:56:42 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2011-01-22 17:56:42 -0500 |
commit | e2627258c3cc43b8b00c5c29c35933a33259e718 (patch) | |
tree | 6956cca30250ffabc71022459aad636347db1a40 /src | |
parent | 116ce2f4d01b929cc7c3bd0f7e6bca631f83da50 (diff) |
Suppress possibly-uninitialized-variable warnings from gcc 4.5.
It appears that gcc 4.5 can issue such warnings for whole structs, not
just scalar variables as in the past. Refactor some pg_dump code slightly
so that the OutputContext local variables are always initialized, even
if they won't be used. It's cheap enough to not be worth worrying about.
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/pg_dump/pg_backup_archiver.c | 44 | ||||
-rw-r--r-- | src/bin/pg_dump/pg_backup_archiver.h | 6 |
2 files changed, 29 insertions, 21 deletions
diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c index 64d8d93dda8..e230c4e1b00 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -75,6 +75,13 @@ typedef struct _parallel_slot #define NO_SLOT (-1) +/* state needed to save/restore an archive's output target */ +typedef struct _outputContext +{ + void *OF; + int gzOut; +} OutputContext; + const char *progname; static const char *modulename = gettext_noop("archiver"); @@ -114,8 +121,9 @@ static void _write_msg(const char *modulename, const char *fmt, va_list ap); static void _die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt, va_list ap); static void dumpTimestamp(ArchiveHandle *AH, const char *msg, time_t tim); -static OutputContext SetOutput(ArchiveHandle *AH, char *filename, int compression); -static void ResetOutput(ArchiveHandle *AH, OutputContext savedContext); +static void SetOutput(ArchiveHandle *AH, char *filename, int compression); +static OutputContext SaveOutput(ArchiveHandle *AH); +static void RestoreOutput(ArchiveHandle *AH, OutputContext savedContext); static int restore_toc_entry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool is_parallel); @@ -299,8 +307,9 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt) /* * Setup the output file if necessary. */ + sav = SaveOutput(AH); if (ropt->filename || ropt->compression) - sav = SetOutput(AH, ropt->filename, ropt->compression); + SetOutput(AH, ropt->filename, ropt->compression); ahprintf(AH, "--\n-- PostgreSQL database dump\n--\n\n"); @@ -420,7 +429,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt) AH->stage = STAGE_FINALIZING; if (ropt->filename || ropt->compression) - ResetOutput(AH, sav); + RestoreOutput(AH, sav); if (ropt->useDB) { @@ -782,8 +791,9 @@ PrintTOCSummary(Archive *AHX, RestoreOptions *ropt) OutputContext sav; char *fmtName; + sav = SaveOutput(AH); if (ropt->filename) - sav = SetOutput(AH, ropt->filename, 0 /* no compression */ ); + SetOutput(AH, ropt->filename, 0 /* no compression */ ); ahprintf(AH, ";\n; Archive created at %s", ctime(&AH->createDate)); ahprintf(AH, "; dbname: %s\n; TOC Entries: %d\n; Compression: %d\n", @@ -839,7 +849,7 @@ PrintTOCSummary(Archive *AHX, RestoreOptions *ropt) } if (ropt->filename) - ResetOutput(AH, sav); + RestoreOutput(AH, sav); } /*********** @@ -1117,16 +1127,11 @@ archprintf(Archive *AH, const char *fmt,...) * Stuff below here should be 'private' to the archiver routines *******************************/ -static OutputContext +static void SetOutput(ArchiveHandle *AH, char *filename, int compression) { - OutputContext sav; int fn; - /* Replace the AH output file handle */ - sav.OF = AH->OF; - sav.gzOut = AH->gzOut; - if (filename) fn = -1; else if (AH->FH) @@ -1182,12 +1187,21 @@ SetOutput(ArchiveHandle *AH, char *filename, int compression) die_horribly(AH, modulename, "could not open output file: %s\n", strerror(errno)); } +} + +static OutputContext +SaveOutput(ArchiveHandle *AH) +{ + OutputContext sav; + + sav.OF = AH->OF; + sav.gzOut = AH->gzOut; return sav; } static void -ResetOutput(ArchiveHandle *AH, OutputContext sav) +RestoreOutput(ArchiveHandle *AH, OutputContext savedContext) { int res; @@ -1200,8 +1214,8 @@ ResetOutput(ArchiveHandle *AH, OutputContext sav) die_horribly(AH, modulename, "could not close output file: %s\n", strerror(errno)); - AH->gzOut = sav.gzOut; - AH->OF = sav.OF; + AH->gzOut = savedContext.gzOut; + AH->OF = savedContext.OF; } diff --git a/src/bin/pg_dump/pg_backup_archiver.h b/src/bin/pg_dump/pg_backup_archiver.h index d9378df55f3..502e7410a1b 100644 --- a/src/bin/pg_dump/pg_backup_archiver.h +++ b/src/bin/pg_dump/pg_backup_archiver.h @@ -132,12 +132,6 @@ typedef void (*DeClonePtr) (struct _archiveHandle * AH); typedef size_t (*CustomOutPtr) (struct _archiveHandle * AH, const void *buf, size_t len); -typedef struct _outputContext -{ - void *OF; - int gzOut; -} OutputContext; - typedef enum { SQL_SCAN = 0, /* normal */ |