aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Meskes <meskes@postgresql.org>2013-07-19 08:59:20 +0200
committerMichael Meskes <meskes@postgresql.org>2013-07-19 09:05:18 +0200
commit4652abeb30b28dcb38621ea31f24936cdbdc83f8 (patch)
tree950f2f3b4580b1c665880683a699bed4c503d92a /src
parentf4ceb7aa56e356da30a8de376a66f0fbcdbf938a (diff)
downloadpostgresql-4652abeb30b28dcb38621ea31f24936cdbdc83f8.tar.gz
postgresql-4652abeb30b28dcb38621ea31f24936cdbdc83f8.zip
Initialize day of year value.
There are cases where the day of year value in struct tm is used, but it never got calculated. Problem found by Coverity scan.
Diffstat (limited to 'src')
-rw-r--r--src/interfaces/ecpg/pgtypeslib/timestamp.c2
-rw-r--r--src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.c14
-rw-r--r--src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.stderr2
-rw-r--r--src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.stdout1
-rw-r--r--src/interfaces/ecpg/test/pgtypeslib/dt_test.pgc6
5 files changed, 20 insertions, 5 deletions
diff --git a/src/interfaces/ecpg/pgtypeslib/timestamp.c b/src/interfaces/ecpg/pgtypeslib/timestamp.c
index 570b9bad945..dbec0d3f29e 100644
--- a/src/interfaces/ecpg/pgtypeslib/timestamp.c
+++ b/src/interfaces/ecpg/pgtypeslib/timestamp.c
@@ -255,6 +255,8 @@ recalc_t:
*tzn = NULL;
}
+ tm->tm_yday = dDate - date2j(tm->tm_year, 1, 1) + 1;
+
return 0;
} /* timestamp2tm() */
diff --git a/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.c b/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.c
index 648b648e219..78f6b3de71e 100644
--- a/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.c
+++ b/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.c
@@ -147,6 +147,12 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
free(text);
free(out);
+ out = (char*) malloc(48);
+ i = PGTYPEStimestamp_fmt_asc(&ts1, out, 47, "Which is day number %j in %Y.");
+ printf("%s\n", out);
+ free(out);
+
+
/* rdate_defmt_asc() */
date1 = 0; text = "";
@@ -431,16 +437,16 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
free(text);
{ ECPGtrans(__LINE__, NULL, "rollback");
-#line 359 "dt_test.pgc"
+#line 365 "dt_test.pgc"
if (sqlca.sqlcode < 0) sqlprint ( );}
-#line 359 "dt_test.pgc"
+#line 365 "dt_test.pgc"
{ ECPGdisconnect(__LINE__, "CURRENT");
-#line 360 "dt_test.pgc"
+#line 366 "dt_test.pgc"
if (sqlca.sqlcode < 0) sqlprint ( );}
-#line 360 "dt_test.pgc"
+#line 366 "dt_test.pgc"
return (0);
diff --git a/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.stderr b/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.stderr
index 41a8013f47a..c1285f54c37 100644
--- a/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.stderr
+++ b/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.stderr
@@ -42,7 +42,7 @@
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_get_data on line 38: RESULT: 2000-07-12 17:34:29 offset: -1; array: no
[NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGtrans on line 359: action "rollback"; connection "regress1"
+[NO_PID]: ECPGtrans on line 365: action "rollback"; connection "regress1"
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_finish: connection regress1 closed
[NO_PID]: sqlca: code: 0, state: 00000
diff --git a/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.stdout b/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.stdout
index a2ff5f7a3b2..823b6e00623 100644
--- a/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.stdout
+++ b/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.stdout
@@ -6,6 +6,7 @@ date seems to get encoded to julian -622
m: 4, d: 19, y: 1998
date_day of 2003-12-04 17:34:29 is 4
Above date in format "(ddd), mmm. dd, yyyy, repeat: (ddd), mmm. dd, yyyy. end" is "(Thu), Dec. 04, 2003, repeat: (Thu), Dec. 04, 2003. end"
+Which is day number 338 in 2003.
date_defmt_asc1: 1995-12-25
date_defmt_asc2: 0095-12-25
date_defmt_asc3: 0095-12-25
diff --git a/src/interfaces/ecpg/test/pgtypeslib/dt_test.pgc b/src/interfaces/ecpg/test/pgtypeslib/dt_test.pgc
index d56ca87e219..768cbd5e6f1 100644
--- a/src/interfaces/ecpg/test/pgtypeslib/dt_test.pgc
+++ b/src/interfaces/ecpg/test/pgtypeslib/dt_test.pgc
@@ -73,6 +73,12 @@ main(void)
free(text);
free(out);
+ out = (char*) malloc(48);
+ i = PGTYPEStimestamp_fmt_asc(&ts1, out, 47, "Which is day number %j in %Y.");
+ printf("%s\n", out);
+ free(out);
+
+
/* rdate_defmt_asc() */
date1 = 0; text = "";