Commit 7ef4c5df authored by Alexander Barkov's avatar Alexander Barkov

Connect: fixing non thread-safe code.

Passing "struct tm" buffer to GetGmTime() instead of using a static bufer.

modified:
  storage/connect/tabodbc.cpp
  storage/connect/value.cpp
  storage/connect/value.h
parent aebcd56c
...@@ -895,7 +895,7 @@ void ODBCCOL::WriteColumn(PGLOBAL g) ...@@ -895,7 +895,7 @@ void ODBCCOL::WriteColumn(PGLOBAL g)
Value->SetValue_pval(To_Val, false); // Convert the inserted value Value->SetValue_pval(To_Val, false); // Convert the inserted value
if (Buf_Type == TYPE_DATE) { if (Buf_Type == TYPE_DATE) {
struct tm *dbtime = ((DTVAL*)Value)->GetGmTime(); struct tm tm, *dbtime = ((DTVAL*)Value)->GetGmTime(&tm);
Sqlbuf->second = dbtime->tm_sec; Sqlbuf->second = dbtime->tm_sec;
Sqlbuf->minute = dbtime->tm_min; Sqlbuf->minute = dbtime->tm_min;
......
...@@ -1251,9 +1251,8 @@ static struct tm *gmtime_mysql(const time_t *timep, struct tm *tm) ...@@ -1251,9 +1251,8 @@ static struct tm *gmtime_mysql(const time_t *timep, struct tm *tm)
} }
struct tm *DTVAL::GetGmTime(void) struct tm *DTVAL::GetGmTime(struct tm *tm_buffer)
{ {
static struct tm tm_static; /* TODO: Move as a parameter to GetGmTime() */
struct tm *datm; struct tm *datm;
time_t t = (time_t)Tval; time_t t = (time_t)Tval;
...@@ -1263,13 +1262,13 @@ struct tm *DTVAL::GetGmTime(void) ...@@ -1263,13 +1262,13 @@ struct tm *DTVAL::GetGmTime(void)
for (n = 0; t < 0; n += 4) for (n = 0; t < 0; n += 4)
t += FOURYEARS; t += FOURYEARS;
datm = gmtime_mysql(&t, &tm_static); datm = gmtime_mysql(&t, tm_buffer);
if (datm) if (datm)
datm->tm_year -= n; datm->tm_year -= n;
} else } else
datm = gmtime_mysql(&t, &tm_static); datm = gmtime_mysql(&t, tm_buffer);
return datm; return datm;
} // end of GetGmTime } // end of GetGmTime
...@@ -1519,7 +1518,7 @@ char *DTVAL::GetCharString(char *p) ...@@ -1519,7 +1518,7 @@ char *DTVAL::GetCharString(char *p)
{ {
if (Pdtp) { if (Pdtp) {
size_t n = 0; size_t n = 0;
struct tm *ptm = GetGmTime(); struct tm tm, *ptm= GetGmTime(&tm);
if (ptm) if (ptm)
n = strftime(Sdate, Len + 1, Pdtp->OutFmt, ptm); n = strftime(Sdate, Len + 1, Pdtp->OutFmt, ptm);
...@@ -1545,7 +1544,7 @@ char *DTVAL::ShowValue(char *buf, int len) ...@@ -1545,7 +1544,7 @@ char *DTVAL::ShowValue(char *buf, int len)
if (Pdtp) { if (Pdtp) {
char *p; char *p;
size_t m, n = 0; size_t m, n = 0;
struct tm *ptm = GetGmTime(); struct tm tm, *ptm = GetGmTime(&tm);
if (Len < len) { if (Len < len) {
p = buf; p = buf;
...@@ -1575,7 +1574,7 @@ char *DTVAL::ShowValue(char *buf, int len) ...@@ -1575,7 +1574,7 @@ char *DTVAL::ShowValue(char *buf, int len)
bool DTVAL::GetTmMember(OPVAL op, int& mval) bool DTVAL::GetTmMember(OPVAL op, int& mval)
{ {
bool rc = false; bool rc = false;
struct tm *ptm = GetGmTime(); struct tm tm, *ptm = GetGmTime(&tm);
switch (op) { switch (op) {
case OP_MDAY: mval = ptm->tm_mday; break; case OP_MDAY: mval = ptm->tm_mday; break;
...@@ -1603,7 +1602,7 @@ bool DTVAL::WeekNum(PGLOBAL g, int& nval) ...@@ -1603,7 +1602,7 @@ bool DTVAL::WeekNum(PGLOBAL g, int& nval)
{ {
// w is the start of the week SUN=0, MON=1, etc. // w is the start of the week SUN=0, MON=1, etc.
int m, n, w = nval % 7; int m, n, w = nval % 7;
struct tm *ptm = GetGmTime(); struct tm tm, *ptm = GetGmTime(&tm);
// Which day is January 4th of this year? // Which day is January 4th of this year?
m = (367 + ptm->tm_wday - ptm->tm_yday) % 7; m = (367 + ptm->tm_wday - ptm->tm_yday) % 7;
...@@ -1627,7 +1626,7 @@ bool DTVAL::WeekNum(PGLOBAL g, int& nval) ...@@ -1627,7 +1626,7 @@ bool DTVAL::WeekNum(PGLOBAL g, int& nval)
bool DTVAL::FormatValue(PVAL vp, char *fmt) bool DTVAL::FormatValue(PVAL vp, char *fmt)
{ {
char *buf = (char*)vp->GetTo_Val(); // Should be big enough char *buf = (char*)vp->GetTo_Val(); // Should be big enough
struct tm *ptm = GetGmTime(); struct tm tm, *ptm = GetGmTime(&tm);
if (trace) if (trace)
htrc("FormatValue: ptm=%p len=%d\n", ptm, vp->GetValLen()); htrc("FormatValue: ptm=%p len=%d\n", ptm, vp->GetValLen());
......
...@@ -288,7 +288,7 @@ class DllExport DTVAL : public TYPVAL<int> { ...@@ -288,7 +288,7 @@ class DllExport DTVAL : public TYPVAL<int> {
bool MakeDate(PGLOBAL g, int *val, int nval); bool MakeDate(PGLOBAL g, int *val, int nval);
bool WeekNum(PGLOBAL g, int& nval); bool WeekNum(PGLOBAL g, int& nval);
struct tm *GetGmTime(void); struct tm *GetGmTime(struct tm *);
protected: protected:
// Default constructor not to be used // Default constructor not to be used
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment