]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Fix float parsing when the data buffer is not terminated
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Thu, 10 Jun 2021 16:08:12 +0000 (17:08 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Mon, 14 Jun 2021 09:37:19 +0000 (10:37 +0100)
psycopg3_c/psycopg3_c/types/numeric.pyx
tests/types/test_numeric.py

index 68ecf3301822cf6304d31ae41521463a14e761e7..1c80f9eff357305bd7dda667bc675519bc5a114c 100644 (file)
@@ -395,8 +395,9 @@ cdef class FloatLoader(CLoader):
     format = PQ_TEXT
 
     cdef object cload(self, const char *data, size_t length):
+        cdef char *endptr
         cdef double d = PyOS_string_to_double(
-            data, NULL, <PyObject *>OverflowError)
+            data, &endptr, <PyObject *>OverflowError)
         return PyFloat_FromDouble(d)
 
 
index 8fc9ab42f727dab29d44e431ce1caf7ff01607a7..acce86eb875656b66f14a8c776ebd9eaa3102e56 100644 (file)
@@ -295,6 +295,16 @@ def test_load_float_approx(conn, expr, pgtype, want, fmt_out):
     assert result == pytest.approx(want)
 
 
+def test_load_float_copy(conn):
+    cur = conn.cursor(binary=False)
+    with cur.copy("copy (select 3.14::float8, 'hi'::text) to stdout;") as copy:
+        copy.set_types(["float8", "text"])
+        rec = copy.read_row()
+
+    assert rec[0] == pytest.approx(3.14)
+    assert rec[1] == "hi"
+
+
 #
 # Tests with decimal
 #