Added result checks for calls to gmtime().
This commit is contained in:
parent
08ffa78483
commit
649a1252b7
@ -1,4 +1,4 @@
|
|||||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/datetime.c,v 1.34 2007/11/15 21:14:45 momjian Exp $ */
|
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/datetime.c,v 1.35 2009/02/04 08:51:09 meskes Exp $ */
|
||||||
|
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
|
|
||||||
@ -87,7 +87,11 @@ PGTYPESdate_from_asc(char *str, char **endptr)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case DTK_EPOCH:
|
case DTK_EPOCH:
|
||||||
GetEpochTime(tm);
|
if (GetEpochTime(tm) < 0)
|
||||||
|
{
|
||||||
|
errno = PGTYPES_DATE_BAD_DATE;
|
||||||
|
return INT_MIN;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -153,7 +157,8 @@ PGTYPESdate_today(date * d)
|
|||||||
struct tm ts;
|
struct tm ts;
|
||||||
|
|
||||||
GetCurrentDateTime(&ts);
|
GetCurrentDateTime(&ts);
|
||||||
*d = date2j(ts.tm_year, ts.tm_mon, ts.tm_mday) - date2j(2000, 1, 1);
|
if (errno == 0)
|
||||||
|
*d = date2j(ts.tm_year, ts.tm_mon, ts.tm_mday) - date2j(2000, 1, 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt.h,v 1.40 2008/11/26 16:31:02 meskes Exp $ */
|
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt.h,v 1.41 2009/02/04 08:51:09 meskes Exp $ */
|
||||||
|
|
||||||
#ifndef DT_H
|
#ifndef DT_H
|
||||||
#define DT_H
|
#define DT_H
|
||||||
@ -342,7 +342,7 @@ int tm2timestamp(struct tm *, fsec_t, int *, timestamp *);
|
|||||||
int DecodeUnits(int field, char *lowtoken, int *val);
|
int DecodeUnits(int field, char *lowtoken, int *val);
|
||||||
bool CheckDateTokenTables(void);
|
bool CheckDateTokenTables(void);
|
||||||
int EncodeDateOnly(struct tm *, int, char *, bool);
|
int EncodeDateOnly(struct tm *, int, char *, bool);
|
||||||
void GetEpochTime(struct tm *);
|
int GetEpochTime(struct tm *);
|
||||||
int ParseDateTime(char *, char *, char **, int *, int, int *, char **);
|
int ParseDateTime(char *, char *, char **, int *, int, int *, char **);
|
||||||
int DecodeDateTime(char **, int *, int, int *, struct tm *, fsec_t *, bool);
|
int DecodeDateTime(char **, int *, int, int *, struct tm *, fsec_t *, bool);
|
||||||
void j2date(int, int *, int *, int *);
|
void j2date(int, int *, int *, int *);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt_common.c,v 1.45 2009/02/02 15:35:28 meskes Exp $ */
|
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt_common.c,v 1.46 2009/02/04 08:51:09 meskes Exp $ */
|
||||||
|
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
|
|
||||||
@ -982,7 +982,7 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, cha
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
} /* EncodeDateTime() */
|
} /* EncodeDateTime() */
|
||||||
|
|
||||||
void
|
int
|
||||||
GetEpochTime(struct tm * tm)
|
GetEpochTime(struct tm * tm)
|
||||||
{
|
{
|
||||||
struct tm *t0;
|
struct tm *t0;
|
||||||
@ -990,14 +990,19 @@ GetEpochTime(struct tm * tm)
|
|||||||
|
|
||||||
t0 = gmtime(&epoch);
|
t0 = gmtime(&epoch);
|
||||||
|
|
||||||
tm->tm_year = t0->tm_year + 1900;
|
if (t0)
|
||||||
tm->tm_mon = t0->tm_mon + 1;
|
{
|
||||||
tm->tm_mday = t0->tm_mday;
|
tm->tm_year = t0->tm_year + 1900;
|
||||||
tm->tm_hour = t0->tm_hour;
|
tm->tm_mon = t0->tm_mon + 1;
|
||||||
tm->tm_min = t0->tm_min;
|
tm->tm_mday = t0->tm_mday;
|
||||||
tm->tm_sec = t0->tm_sec;
|
tm->tm_hour = t0->tm_hour;
|
||||||
|
tm->tm_min = t0->tm_min;
|
||||||
|
tm->tm_sec = t0->tm_sec;
|
||||||
|
|
||||||
return;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
} /* GetEpochTime() */
|
} /* GetEpochTime() */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1006,11 +1011,18 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn)
|
|||||||
time_t time = (time_t) _time;
|
time_t time = (time_t) _time;
|
||||||
struct tm *tx;
|
struct tm *tx;
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
if (tzp != NULL)
|
if (tzp != NULL)
|
||||||
tx = localtime((time_t *) &time);
|
tx = localtime((time_t *) &time);
|
||||||
else
|
else
|
||||||
tx = gmtime((time_t *) &time);
|
tx = gmtime((time_t *) &time);
|
||||||
|
|
||||||
|
if (!tx)
|
||||||
|
{
|
||||||
|
errno = PGTYPES_TS_BAD_TIMESTAMP;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
tm->tm_year = tx->tm_year + 1900;
|
tm->tm_year = tx->tm_year + 1900;
|
||||||
tm->tm_mon = tx->tm_mon + 1;
|
tm->tm_mon = tx->tm_mon + 1;
|
||||||
tm->tm_mday = tx->tm_mday;
|
tm->tm_mday = tx->tm_mday;
|
||||||
@ -2852,12 +2864,18 @@ PGTYPEStimestamp_defmt_scan(char **str, char *fmt, timestamp * d,
|
|||||||
time_t et = (time_t) scan_val.luint_val;
|
time_t et = (time_t) scan_val.luint_val;
|
||||||
|
|
||||||
tms = gmtime(&et);
|
tms = gmtime(&et);
|
||||||
*year = tms->tm_year + 1900;
|
|
||||||
*month = tms->tm_mon + 1;
|
if (tms)
|
||||||
*day = tms->tm_mday;
|
{
|
||||||
*hour = tms->tm_hour;
|
*year = tms->tm_year + 1900;
|
||||||
*minute = tms->tm_min;
|
*month = tms->tm_mon + 1;
|
||||||
*second = tms->tm_sec;
|
*day = tms->tm_mday;
|
||||||
|
*hour = tms->tm_hour;
|
||||||
|
*minute = tms->tm_min;
|
||||||
|
*second = tms->tm_sec;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
err = 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'S':
|
case 'S':
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/timestamp.c,v 1.42 2008/05/17 01:28:25 adunstan Exp $
|
* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/timestamp.c,v 1.43 2009/02/04 08:51:10 meskes Exp $
|
||||||
*/
|
*/
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
|
|
||||||
@ -91,11 +91,18 @@ tm2timestamp(struct tm * tm, fsec_t fsec, int *tzp, timestamp * result)
|
|||||||
static timestamp
|
static timestamp
|
||||||
SetEpochTimestamp(void)
|
SetEpochTimestamp(void)
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
|
int64 noresult = 0;
|
||||||
|
#else
|
||||||
|
double noresult = 0.0;
|
||||||
|
#endif
|
||||||
timestamp dt;
|
timestamp dt;
|
||||||
struct tm tt,
|
struct tm tt,
|
||||||
*tm = &tt;
|
*tm = &tt;
|
||||||
|
|
||||||
GetEpochTime(tm);
|
if (GetEpochTime(tm) < 0)
|
||||||
|
return noresult;
|
||||||
|
|
||||||
tm2timestamp(tm, 0, NULL, &dt);
|
tm2timestamp(tm, 0, NULL, &dt);
|
||||||
return dt;
|
return dt;
|
||||||
} /* SetEpochTimestamp() */
|
} /* SetEpochTimestamp() */
|
||||||
@ -372,7 +379,8 @@ PGTYPEStimestamp_current(timestamp * ts)
|
|||||||
struct tm tm;
|
struct tm tm;
|
||||||
|
|
||||||
GetCurrentDateTime(&tm);
|
GetCurrentDateTime(&tm);
|
||||||
tm2timestamp(&tm, 0, NULL, ts);
|
if (errno == 0)
|
||||||
|
tm2timestamp(&tm, 0, NULL, ts);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user