Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a2c1c33

Browse files
author
Michael Meskes
committed
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.
1 parent d9f37e6 commit a2c1c33

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

src/interfaces/ecpg/pgtypeslib/timestamp.c

+2
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ timestamp2tm(timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, const char **
255255
*tzn = NULL;
256256
}
257257

258+
tm->tm_yday = dDate - date2j(tm->tm_year, 1, 1) + 1;
259+
258260
return 0;
259261
} /* timestamp2tm() */
260262

src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.c

+10-4
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
147147
free(text);
148148
free(out);
149149

150+
out = (char*) malloc(48);
151+
i = PGTYPEStimestamp_fmt_asc(&ts1, out, 47, "Which is day number %j in %Y.");
152+
printf("%s\n", out);
153+
free(out);
154+
155+
150156
/* rdate_defmt_asc() */
151157

152158
date1 = 0; text = "";
@@ -431,16 +437,16 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
431437
free(text);
432438

433439
{ ECPGtrans(__LINE__, NULL, "rollback");
434-
#line 359 "dt_test.pgc"
440+
#line 365 "dt_test.pgc"
435441

436442
if (sqlca.sqlcode < 0) sqlprint ( );}
437-
#line 359 "dt_test.pgc"
443+
#line 365 "dt_test.pgc"
438444

439445
{ ECPGdisconnect(__LINE__, "CURRENT");
440-
#line 360 "dt_test.pgc"
446+
#line 366 "dt_test.pgc"
441447

442448
if (sqlca.sqlcode < 0) sqlprint ( );}
443-
#line 360 "dt_test.pgc"
449+
#line 366 "dt_test.pgc"
444450

445451

446452
return (0);

src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
[NO_PID]: sqlca: code: 0, state: 00000
4343
[NO_PID]: ecpg_get_data on line 38: RESULT: 2000-07-12 17:34:29 offset: -1; array: no
4444
[NO_PID]: sqlca: code: 0, state: 00000
45-
[NO_PID]: ECPGtrans on line 359: action "rollback"; connection "regress1"
45+
[NO_PID]: ECPGtrans on line 365: action "rollback"; connection "regress1"
4646
[NO_PID]: sqlca: code: 0, state: 00000
4747
[NO_PID]: ecpg_finish: connection regress1 closed
4848
[NO_PID]: sqlca: code: 0, state: 00000

src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.stdout

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ date seems to get encoded to julian -622
66
m: 4, d: 19, y: 1998
77
date_day of 2003-12-04 17:34:29 is 4
88
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"
9+
Which is day number 338 in 2003.
910
date_defmt_asc1: 1995-12-25
1011
date_defmt_asc2: 0095-12-25
1112
date_defmt_asc3: 0095-12-25

src/interfaces/ecpg/test/pgtypeslib/dt_test.pgc

+6
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ main(void)
7373
free(text);
7474
free(out);
7575

76+
out = (char*) malloc(48);
77+
i = PGTYPEStimestamp_fmt_asc(&ts1, out, 47, "Which is day number %j in %Y.");
78+
printf("%s\n", out);
79+
free(out);
80+
81+
7682
/* rdate_defmt_asc() */
7783

7884
date1 = 0; text = "";

0 commit comments

Comments
 (0)