From 1156ad5e984b2e61a72e2677a70245f945f222ea Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Fri, 10 Dec 2010 12:05:01 +0000 Subject: Fixed buffer null termination inconsistency when removing cr's from selection, source file indenting, and a crash if we have an empty selection. Update for previous fix to STR #2472 (X11). git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7997 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl_x.cxx | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/Fl_x.cxx b/src/Fl_x.cxx index 12fd89e61..1da79a8ac 100644 --- a/src/Fl_x.cxx +++ b/src/Fl_x.cxx @@ -279,17 +279,16 @@ int fl_ready() { } // replace \r\n by \n -static void convert_crlf(unsigned char *string, long& len) -{ +static void convert_crlf(unsigned char *string, long& len) { unsigned char *p = string, *q = p + len; - while (p < q) { - if (*p == '\r' && *(p + 1) == '\n' && p + 1 < q) { + while (p + 1 < q) { + if (*p == '\r' && *(p + 1) == '\n') { memmove(p, p + 1, q - p - 1); q--; len--; - } - p++; } + p++; + } } //////////////////////////////////////////////////////////////// @@ -977,7 +976,10 @@ int fl_handle(const XEvent& thisevent) bytesread += bytesnew - 1; if (!remaining) break; } - convert_crlf(buffer, bytesread); + if (buffer) { + convert_crlf(buffer, bytesread); + buffer[bytesread] = 0; + } Fl::e_text = buffer ? (char*)buffer : (char *)""; Fl::e_length = bytesread; int old_event = Fl::e_number; -- cgit v1.2.3