Fix out of bounds write on platforms where sizeof(bool) != 1

Found by code scanning
This commit is contained in:
Kovid Goyal 2020-07-07 09:25:14 +05:30
parent 209b78a3ec
commit dad7d366b3
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -123,7 +123,7 @@ new(PyTypeObject *type, PyObject *args, PyObject UNUSED *kwds) {
) {
Py_CLEAR(self); return NULL;
}
self->alt_tabstops = self->main_tabstops + self->columns * sizeof(bool);
self->alt_tabstops = self->main_tabstops + self->columns;
self->tabstops = self->main_tabstops;
init_tabstops(self->main_tabstops, self->columns);
init_tabstops(self->alt_tabstops, self->columns);
@ -236,7 +236,7 @@ screen_resize(Screen *self, unsigned int lines, unsigned int columns) {
PyMem_Free(self->main_tabstops);
self->main_tabstops = PyMem_Calloc(2*self->columns, sizeof(bool));
if (self->main_tabstops == NULL) { PyErr_NoMemory(); return false; }
self->alt_tabstops = self->main_tabstops + self->columns * sizeof(bool);
self->alt_tabstops = self->main_tabstops + self->columns;
self->tabstops = self->main_tabstops;
init_tabstops(self->main_tabstops, self->columns);
init_tabstops(self->alt_tabstops, self->columns);