summaryrefslogtreecommitdiff
path: root/psycopg
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2017-02-24 02:10:27 +0100
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2017-02-24 02:10:27 +0100
commit14fe3ad8c9f9e9ecf63e352b23dafe9da22a80ab (patch)
treea45836f011c6f09152949b86b3d19ea97f0fec81 /psycopg
parentf5bd6063fc16c4f008716833dc1209796caf39d8 (diff)
downloadpsycopg2-14fe3ad8c9f9e9ecf63e352b23dafe9da22a80ab.tar.gz
Fixed integer overflow in interval typecaster
Close #512.
Diffstat (limited to 'psycopg')
-rw-r--r--psycopg/typecast_datetime.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/psycopg/typecast_datetime.c b/psycopg/typecast_datetime.c
index ad74101..6b94175 100644
--- a/psycopg/typecast_datetime.c
+++ b/psycopg/typecast_datetime.c
@@ -220,10 +220,10 @@ typecast_PYTIME_cast(const char *str, Py_ssize_t len, PyObject *curs)
static PyObject *
typecast_PYINTERVAL_cast(const char *str, Py_ssize_t len, PyObject *curs)
{
- long years = 0, months = 0, days = 0;
+ long years = 0, months = 0, days = 0, sec;
double hours = 0.0, minutes = 0.0, seconds = 0.0, hundredths = 0.0;
double v = 0.0, sign = 1.0, denominator = 1.0;
- int part = 0, sec;
+ int part = 0;
double micro;
if (str == NULL) { Py_RETURN_NONE; }
@@ -318,8 +318,8 @@ typecast_PYINTERVAL_cast(const char *str, Py_ssize_t len, PyObject *curs)
days += years*365 + months*30;
micro = (seconds - floor(seconds)) * 1000000.0;
- sec = (int)floor(seconds);
- return PyObject_CallFunction((PyObject*)PyDateTimeAPI->DeltaType, "iii",
+ sec = (long)floor(seconds);
+ return PyObject_CallFunction((PyObject*)PyDateTimeAPI->DeltaType, "lli",
days, sec, (int)round(micro));
}