From 8963c1f683244b730da1b5a1f669d7433328bba3 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Tue, 28 Jul 2015 03:17:30 -0400 Subject: [PATCH] Fix Textbuffer_reverse() --- mwparserfromhell/parser/ctokenizer/textbuffer.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mwparserfromhell/parser/ctokenizer/textbuffer.c b/mwparserfromhell/parser/ctokenizer/textbuffer.c index e028a58..0c711c5 100644 --- a/mwparserfromhell/parser/ctokenizer/textbuffer.c +++ b/mwparserfromhell/parser/ctokenizer/textbuffer.c @@ -214,19 +214,19 @@ int Textbuffer_concat(Textbuffer* self, Textbuffer* other) */ void Textbuffer_reverse(Textbuffer* self) { - Py_ssize_t i, mid = self->length / 2; + Py_ssize_t i, end = self->length - 1; Unicode tmp; - for (i = 0; i < mid; i++) { + for (i = 0; i < self->length / 2; i++) { #ifdef PEP_393 tmp = PyUnicode_READ(self->kind, self->data, i); PyUnicode_WRITE(self->kind, self->data, i, - PyUnicode_READ(self->kind, self->data, mid + i)); - PyUnicode_WRITE(self->kind, self->data, mid + i, tmp); + PyUnicode_READ(self->kind, self->data, end - i)); + PyUnicode_WRITE(self->kind, self->data, end - i, tmp); #else tmp = self->data[i]; - self->data[i] = self->data[mid + i]; - self->data[mid + i] = tmp; + self->data[i] = self->data[end - i]; + self->data[end - i] = tmp; #endif } }