summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2010-12-10 12:05:01 +0000
committerAlbrecht Schlosser <albrechts.fltk@online.de>2010-12-10 12:05:01 +0000
commit1156ad5e984b2e61a72e2677a70245f945f222ea (patch)
tree64f075769d24403ed321eb1b5ff5fdf901426e0c /src
parent3d94092dcc301e5c904851edeb4650e73d256370 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/Fl_x.cxx16
1 files changed, 9 insertions, 7 deletions
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;