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

Commit e262725

Browse files
committed
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.
1 parent 116ce2f commit e262725

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ typedef struct _parallel_slot
7575

7676
#define NO_SLOT (-1)
7777

78+
/* state needed to save/restore an archive's output target */
79+
typedef struct _outputContext
80+
{
81+
void *OF;
82+
int gzOut;
83+
} OutputContext;
84+
7885
const char *progname;
7986

8087
static const char *modulename = gettext_noop("archiver");
@@ -114,8 +121,9 @@ static void _write_msg(const char *modulename, const char *fmt, va_list ap);
114121
static void _die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt, va_list ap);
115122

116123
static void dumpTimestamp(ArchiveHandle *AH, const char *msg, time_t tim);
117-
static OutputContext SetOutput(ArchiveHandle *AH, char *filename, int compression);
118-
static void ResetOutput(ArchiveHandle *AH, OutputContext savedContext);
124+
static void SetOutput(ArchiveHandle *AH, char *filename, int compression);
125+
static OutputContext SaveOutput(ArchiveHandle *AH);
126+
static void RestoreOutput(ArchiveHandle *AH, OutputContext savedContext);
119127

120128
static int restore_toc_entry(ArchiveHandle *AH, TocEntry *te,
121129
RestoreOptions *ropt, bool is_parallel);
@@ -299,8 +307,9 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
299307
/*
300308
* Setup the output file if necessary.
301309
*/
310+
sav = SaveOutput(AH);
302311
if (ropt->filename || ropt->compression)
303-
sav = SetOutput(AH, ropt->filename, ropt->compression);
312+
SetOutput(AH, ropt->filename, ropt->compression);
304313

305314
ahprintf(AH, "--\n-- PostgreSQL database dump\n--\n\n");
306315

@@ -420,7 +429,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
420429
AH->stage = STAGE_FINALIZING;
421430

422431
if (ropt->filename || ropt->compression)
423-
ResetOutput(AH, sav);
432+
RestoreOutput(AH, sav);
424433

425434
if (ropt->useDB)
426435
{
@@ -782,8 +791,9 @@ PrintTOCSummary(Archive *AHX, RestoreOptions *ropt)
782791
OutputContext sav;
783792
char *fmtName;
784793

794+
sav = SaveOutput(AH);
785795
if (ropt->filename)
786-
sav = SetOutput(AH, ropt->filename, 0 /* no compression */ );
796+
SetOutput(AH, ropt->filename, 0 /* no compression */ );
787797

788798
ahprintf(AH, ";\n; Archive created at %s", ctime(&AH->createDate));
789799
ahprintf(AH, "; dbname: %s\n; TOC Entries: %d\n; Compression: %d\n",
@@ -839,7 +849,7 @@ PrintTOCSummary(Archive *AHX, RestoreOptions *ropt)
839849
}
840850

841851
if (ropt->filename)
842-
ResetOutput(AH, sav);
852+
RestoreOutput(AH, sav);
843853
}
844854

845855
/***********
@@ -1117,16 +1127,11 @@ archprintf(Archive *AH, const char *fmt,...)
11171127
* Stuff below here should be 'private' to the archiver routines
11181128
*******************************/
11191129

1120-
static OutputContext
1130+
static void
11211131
SetOutput(ArchiveHandle *AH, char *filename, int compression)
11221132
{
1123-
OutputContext sav;
11241133
int fn;
11251134

1126-
/* Replace the AH output file handle */
1127-
sav.OF = AH->OF;
1128-
sav.gzOut = AH->gzOut;
1129-
11301135
if (filename)
11311136
fn = -1;
11321137
else if (AH->FH)
@@ -1182,12 +1187,21 @@ SetOutput(ArchiveHandle *AH, char *filename, int compression)
11821187
die_horribly(AH, modulename, "could not open output file: %s\n",
11831188
strerror(errno));
11841189
}
1190+
}
1191+
1192+
static OutputContext
1193+
SaveOutput(ArchiveHandle *AH)
1194+
{
1195+
OutputContext sav;
1196+
1197+
sav.OF = AH->OF;
1198+
sav.gzOut = AH->gzOut;
11851199

11861200
return sav;
11871201
}
11881202

11891203
static void
1190-
ResetOutput(ArchiveHandle *AH, OutputContext sav)
1204+
RestoreOutput(ArchiveHandle *AH, OutputContext savedContext)
11911205
{
11921206
int res;
11931207

@@ -1200,8 +1214,8 @@ ResetOutput(ArchiveHandle *AH, OutputContext sav)
12001214
die_horribly(AH, modulename, "could not close output file: %s\n",
12011215
strerror(errno));
12021216

1203-
AH->gzOut = sav.gzOut;
1204-
AH->OF = sav.OF;
1217+
AH->gzOut = savedContext.gzOut;
1218+
AH->OF = savedContext.OF;
12051219
}
12061220

12071221

src/bin/pg_dump/pg_backup_archiver.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,6 @@ typedef void (*DeClonePtr) (struct _archiveHandle * AH);
132132

133133
typedef size_t (*CustomOutPtr) (struct _archiveHandle * AH, const void *buf, size_t len);
134134

135-
typedef struct _outputContext
136-
{
137-
void *OF;
138-
int gzOut;
139-
} OutputContext;
140-
141135
typedef enum
142136
{
143137
SQL_SCAN = 0, /* normal */

0 commit comments

Comments
 (0)