Skip to content

Commit c341c7d

Browse files
committed
Fix some compiler warnings with timestamp parsing in formatting.c
gcc-7 used with a sufficient optimization level complains about warnings around do_to_timestamp() regarding the initialization and handling of some of its variables. Recent commits 66c74f8 and d589f94 made things made the interface more confusing, so document which variables are always expected and initialize properly the optional ones when they are set. Author: Andrey Lepikhov, Michael Paquier Discussion: https://postgr.es/m/a7e28b83-27b1-4e1c-c76b-4268c4b785bc@postgrespro.ru
1 parent 8729fa7 commit c341c7d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/backend/utils/adt/formatting.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4128,7 +4128,7 @@ parse_datetime(text *date_txt, text *fmt, bool strict, Oid *typid,
41284128
{
41294129
struct pg_tm tm;
41304130
fsec_t fsec;
4131-
int fprec = 0;
4131+
int fprec;
41324132
uint32 flags;
41334133

41344134
do_to_timestamp(date_txt, fmt, strict, &tm, &fsec, &fprec, &flags, have_error);
@@ -4318,11 +4318,18 @@ do_to_timestamp(text *date_txt, text *fmt, bool std,
43184318
int fmask;
43194319
bool incache = false;
43204320

4321+
Assert(tm != NULL);
4322+
Assert(fsec != NULL);
4323+
43214324
date_str = text_to_cstring(date_txt);
43224325

43234326
ZERO_tmfc(&tmfc);
43244327
ZERO_tm(tm);
43254328
*fsec = 0;
4329+
if (fprec)
4330+
*fprec = 0;
4331+
if (flags)
4332+
*flags = 0;
43264333
fmask = 0; /* bit mask for ValidateDate() */
43274334

43284335
fmt_len = VARSIZE_ANY_EXHDR(fmt);

0 commit comments

Comments
 (0)