]> granicus.if.org Git - postgresql/commitdiff
Suppress possibly-uninitialized-variable warnings from gcc 4.5.
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 22 Jan 2011 22:56:42 +0000 (17:56 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 22 Jan 2011 22:56:42 +0000 (17:56 -0500)
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.

src/bin/pg_dump/pg_backup_archiver.c
src/bin/pg_dump/pg_backup_archiver.h

index 64d8d93dda81805540ac70dbd7afcf11390c19fc..e230c4e1b00dd52ee3b39e82813f8191fc9f8ec9 100644 (file)
@@ -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;
 }
 
 
index d9378df55f3ad95a971af6bafb1e37b53d8bbd61..502e7410a1b55b256938087daa8bda60ba8eb6e2 100644 (file)
@@ -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 */