Skip to content

Commit c49e4ae

Browse files
committed
Use non-literal format for possibly non-standard strftime formats.
Per recent -hackers discussion. The formats in question are %G and %V, and cause warnings on MinGW at least. We assume the ecpg application knows what it's doing if it passes these formats to the library.
1 parent ab0ba6e commit c49e4ae

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

src/interfaces/ecpg/pgtypeslib/timestamp.c

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -501,17 +501,22 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm,
501501
* 4-digit year corresponding to the ISO week number.
502502
*/
503503
case 'G':
504-
tm->tm_mon -= 1;
505-
i = strftime(q, *pstr_len, "%G", tm);
506-
if (i == 0)
507-
return -1;
508-
while (*q)
509504
{
510-
q++;
511-
(*pstr_len)--;
505+
/* Keep compiler quiet - Don't use a literal format */
506+
const char *fmt = "%G";
507+
508+
tm->tm_mon -= 1;
509+
i = strftime(q, *pstr_len, fmt, tm);
510+
if (i == 0)
511+
return -1;
512+
while (*q)
513+
{
514+
q++;
515+
(*pstr_len)--;
516+
}
517+
tm->tm_mon += 1;
518+
replace_type = PGTYPES_TYPE_NOTHING;
512519
}
513-
tm->tm_mon += 1;
514-
replace_type = PGTYPES_TYPE_NOTHING;
515520
break;
516521

517522
/*
@@ -682,15 +687,20 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm,
682687
* decimal number.
683688
*/
684689
case 'V':
685-
i = strftime(q, *pstr_len, "%V", tm);
686-
if (i == 0)
687-
return -1;
688-
while (*q)
689690
{
690-
q++;
691-
(*pstr_len)--;
691+
/* Keep compiler quiet - Don't use a literal format */
692+
const char *fmt = "%V";
693+
694+
i = strftime(q, *pstr_len, fmt, tm);
695+
if (i == 0)
696+
return -1;
697+
while (*q)
698+
{
699+
q++;
700+
(*pstr_len)--;
701+
}
702+
replace_type = PGTYPES_TYPE_NOTHING;
692703
}
693-
replace_type = PGTYPES_TYPE_NOTHING;
694704
break;
695705

696706
/*

0 commit comments

Comments
 (0)