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
This commit is contained in:
Albrecht Schlosser 2010-12-10 12:05:01 +00:00
parent 3d94092dcc
commit 1156ad5e98

View File

@ -279,17 +279,16 @@ int fl_ready() {
} }
// replace \r\n by \n // 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; unsigned char *p = string, *q = p + len;
while (p < q) { while (p + 1 < q) {
if (*p == '\r' && *(p + 1) == '\n' && p + 1 < q) { if (*p == '\r' && *(p + 1) == '\n') {
memmove(p, p + 1, q - p - 1); memmove(p, p + 1, q - p - 1);
q--; q--;
len--; len--;
}
p++;
} }
p++;
}
} }
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
@ -977,7 +976,10 @@ int fl_handle(const XEvent& thisevent)
bytesread += bytesnew - 1; bytesread += bytesnew - 1;
if (!remaining) break; 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_text = buffer ? (char*)buffer : (char *)"";
Fl::e_length = bytesread; Fl::e_length = bytesread;
int old_event = Fl::e_number; int old_event = Fl::e_number;