diff options
author | Stefan Behnel <stefan_ml@behnel.de> | 2019-02-15 12:04:11 +0100 |
---|---|---|
committer | Stefan Behnel <stefan_ml@behnel.de> | 2019-02-15 12:04:11 +0100 |
commit | 40ad34a05fee798da737e4e6d2b4ad84cc24f595 (patch) | |
tree | 23f51a40fc22e694292dcb1f48b60e6694c0685b | |
parent | 46a910402cbac7e25db92ee9eed8b7d38d09322a (diff) | |
download | cython-40ad34a05fee798da737e4e6d2b4ad84cc24f595.tar.gz |
Fix buffer format parsing code to allow the digit '9' in numbers.
Closes GH-2845.
-rw-r--r-- | Cython/Utility/Buffer.c | 2 | ||||
-rw-r--r-- | tests/buffers/buffmt.pyx | 15 |
2 files changed, 15 insertions, 2 deletions
diff --git a/Cython/Utility/Buffer.c b/Cython/Utility/Buffer.c index 8842d11f8..7f3a0b15e 100644 --- a/Cython/Utility/Buffer.c +++ b/Cython/Utility/Buffer.c @@ -273,7 +273,7 @@ static int __Pyx_BufFmt_ParseNumber(const char** ts) { return -1; } else { count = *t++ - '0'; - while (*t >= '0' && *t < '9') { + while (*t >= '0' && *t <= '9') { count *= 10; count += *t++ - '0'; } diff --git a/tests/buffers/buffmt.pyx b/tests/buffers/buffmt.pyx index be131a7ac..851193f3f 100644 --- a/tests/buffers/buffmt.pyx +++ b/tests/buffers/buffmt.pyx @@ -37,7 +37,7 @@ if int_align != 4 or sizeof(int) != 4: cdef class MockBuffer: cdef Py_ssize_t zero cdef Py_ssize_t minusone - cdef object format + cdef bytes format cdef object itemsize def __init__(self, format, itemsize): @@ -117,6 +117,9 @@ ctypedef struct Char3Int: int c int d +ctypedef struct LongString: + char[90198] c + cdef struct CharIntCFloat: char a int b @@ -180,6 +183,16 @@ def char3int(fmt): cdef object obj = MockBuffer(fmt, sizeof(Char3Int)) cdef object[Char3Int, ndim=1] buf = obj + +@testcase +def long_string(fmt): + """ + >>> long_string("90198s") + """ + cdef object obj = MockBuffer(fmt, sizeof(LongString)) + cdef object[LongString, ndim=1] buf = obj + + @testcase def unpacked_struct(fmt): """ |