Author: AlbrechtS
Date: 2010-12-10 04:05:01 -0800 (Fri, 10 Dec 2010)
New Revision: 7997
Log:
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).


Modified:
   branches/branch-1.3/src/Fl_x.cxx

Modified: branches/branch-1.3/src/Fl_x.cxx
===================================================================
--- branches/branch-1.3/src/Fl_x.cxx    2010-12-10 08:09:27 UTC (rev 7996)
+++ branches/branch-1.3/src/Fl_x.cxx    2010-12-10 12:05:01 UTC (rev 7997)
@@ -279,17 +279,16 @@
 }
 
 // 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++;
-    }
+  }
 }
 
 ////////////////////////////////////////////////////////////////
@@ -977,7 +976,10 @@
       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;

_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit

Reply via email to