Skip to content

Commit

Permalink
Initialize day of year value.
Browse files Browse the repository at this point in the history
There are cases where the day of year value in struct tm is used, but it never
got calculated. Problem found by Coverity scan.
  • Loading branch information
Michael Meskes committed Jul 19, 2013
1 parent d9f37e6 commit a2c1c33
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/interfaces/ecpg/pgtypeslib/timestamp.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ timestamp2tm(timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, const char **
*tzn = NULL;
}

tm->tm_yday = dDate - date2j(tm->tm_year, 1, 1) + 1;

return 0;
} /* timestamp2tm() */

Expand Down
14 changes: 10 additions & 4 deletions src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/interfaces/ecpg/test/pgtypeslib/dt_test.pgc
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down

0 comments on commit a2c1c33

Please sign in to comment.