8000 Pass -1 if size >= INT_MAX · python/cpython@9febd15 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9febd15

Browse files
author
Erlend E. Aasland
committed
Pass -1 if size >= INT_MAX
1 parent f901fd5 commit 9febd15

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

Modules/_sqlite/cursor.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ pysqlite_cursor_executescript(pysqlite_Cursor *self, PyObject *script_obj)
681681
const char* script_cstr;
682682
sqlite3_stmt* statement;
683683
int rc;
684-
Py_ssize_t script_length;
684+
Py_ssize_t sql_len;
685685
PyObject* result;
686686

687687
if (!check_cursor(self)) {
@@ -691,7 +691,7 @@ pysqlite_cursor_executescript(pysqlite_Cursor *self, PyObject *script_obj)
691691
self->reset = 0;
692692

693693
if (PyUnicode_Check(script_obj)) {
694-
script_cstr = PyUnicode_AsUTF8AndSize(script_obj, &script_length);
694+
script_cstr = PyUnicode_AsUTF8AndSize(script_obj, &sql_len);
695695
if (!script_cstr) {
696696
return NULL;
697697
}
@@ -707,14 +707,13 @@ pysqlite_cursor_executescript(pysqlite_Cursor *self, PyObject *script_obj)
707707
}
708708
Py_DECREF(result);
709709

710-
Py_ssize_t size_incl_null = script_length + 1;
711710
while (1) {
712711
const char *tail;
713712

714713
Py_BEGIN_ALLOW_THREADS
715714
rc = sqlite3_prepare_v2(self->connection->db,
716715
script_cstr,
717-
size_incl_null,
716+
(sql_len >= INT_MAX) ? -1 : (int)sql_len + 1,
718717
&statement,
719718
&tail);
720719
Py_END_ALLOW_THREADS
@@ -747,7 +746,7 @@ pysqlite_cursor_executescript(pysqlite_Cursor *self, PyObject *script_obj)
747746
if (*tail == (char)0) {
748747
break;
749748
}
750-
size_incl_null -= (tail - script_cstr);
749+
sql_len -= (tail - script_cstr);
751750
script_cstr = tail;
752751
}
753752

Modules/_sqlite/statement.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,16 @@ int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* con
9393
break;
9494
}
9595

96+
if (sql_cstr_len >= INT_MAX) {
97+
sql_cstr_len = -1;
98+
}
99+
else {
100+
sql_cstr_len += 1;
101+
}
96102
Py_BEGIN_ALLOW_THREADS
97103
rc = sqlite3_prepare_v2(connection->db,
98104
sql_cstr,
99-
sql_cstr_len + 1,
105+
(int)sql_cstr_len,
100106
&self->st,
101107
&tail);
102108
Py_END_ALLOW_THREADS

0 commit comments

Comments
 (0)
0