Accept NULL bytes in strings to be cut by the poopt module

fix #2296
This commit is contained in:
Florent Le Coz 2013-06-07 00:04:01 +02:00
parent 4b537d3477
commit 463ec5ca0d
2 changed files with 6 additions and 5 deletions

View file

@ -33,10 +33,11 @@ PyDoc_STRVAR(poopt_cut_text_doc, "cut_text(text, width)\n\n\nReturn a list of tw
static PyObject *poopt_cut_text(PyObject *self, PyObject *args) static PyObject *poopt_cut_text(PyObject *self, PyObject *args)
{ {
unsigned char *buffer; const unsigned char *buffer;
int width; const int width;
const size_t buffer_len;
if (PyArg_ParseTuple(args, "si", &buffer, &width) == 0) if (PyArg_ParseTuple(args, "is#", &width, &buffer, &buffer_len) == 0)
return NULL; return NULL;
int bpos = 0; /* the real position in the char* */ int bpos = 0; /* the real position in the char* */
@ -48,7 +49,7 @@ static PyObject *poopt_cut_text(PyObject *self, PyObject *args)
of colors attribute be ignored */ of colors attribute be ignored */
PyObject* retlist = PyList_New(0); PyObject* retlist = PyList_New(0);
while (buffer[bpos]) while (bpos < buffer_len)
{ {
if (buffer[bpos] == ' ') if (buffer[bpos] == ' ')
last_space = spos; last_space = spos;

View file

@ -909,7 +909,7 @@ class TextWin(Win):
offset += 1 offset += 1
if get_theme().CHAR_TIME_RIGHT and message.str_time: if get_theme().CHAR_TIME_RIGHT and message.str_time:
offset += 1 offset += 1
lines = cut_text(txt, self.width-offset) lines = cut_text(self.width-offset, txt)
prepend = '' prepend = ''
attrs = [] attrs = []
for line in lines: for line in lines: