]> granicus.if.org Git - postgresql/commitdiff
Initialize day of year value.
authorMichael Meskes <meskes@postgresql.org>
Fri, 19 Jul 2013 06:59:20 +0000 (08:59 +0200)
committerMichael Meskes <meskes@postgresql.org>
Fri, 19 Jul 2013 07:04:39 +0000 (09:04 +0200)
There are cases where the day of year value in struct tm is used, but it never
got calculated. Problem found by Coverity scan.

src/interfaces/ecpg/pgtypeslib/timestamp.c
src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.c
src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.stderr
src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.stdout
src/interfaces/ecpg/test/pgtypeslib/dt_test.pgc

index f50feaf9cfa5707fe88da0b1f1513b069244b199..7f1f44dea67c219f705b5a2b40f79aeab43e84a1 100644 (file)
@@ -257,6 +257,8 @@ recalc_t:
                        *tzn = NULL;
        }
 
+       tm->tm_yday = dDate - date2j(tm->tm_year, 1, 1) + 1;
+
        return 0;
 }      /* timestamp2tm() */
 
index b0b3239b9fd7a280cfc4cf84de7a64daceb54dd6..c49aad174b9fe9021b7b29b7eb29a5d38fe866d9 100644 (file)
@@ -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);
index c0033c52cc545e4cb6dec96b4a4d6e69ee0948a7..4c438f564a7121ac4a2c8be84c1f34ae17ee1153 100644 (file)
@@ -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: yes
 [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
index a2ff5f7a3b23222a6e1abad0a13aa8dd24cc6f27..823b6e0062352a2f072f86fab86673603c4948ea 100644 (file)
@@ -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
index 4e3c4404437734eed7d0bf3e745ca7ef1e9136b4..5ae7cce2315d6840972dbd2145423118b68eeff2 100644 (file)
@@ -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 = "";