Skip to content

Commit d29130b

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 57ddea3 commit d29130b

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

src/interfaces/ecpg/pgtypeslib/timestamp.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ timestamp2tm(timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, char **tzn)
257257
*tzn = NULL;
258258
}
259259

260+
tm->tm_yday = dDate - date2j(tm->tm_year, 1, 1) + 1;
261+
260262
return 0;
261263
} /* timestamp2tm() */
262264

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

Lines changed: 10 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
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: yes
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 6 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy