summaryrefslogtreecommitdiffstats
path: root/main/eboard/eboard-const-safety.patch
blob: de275c3bb67f2c95fd21335732e356a348b60f67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
--- eboard-1.1.1.orig/ntext.cc
+++ eboard-1.1.1/ntext.cc
@@ -237,6 +237,7 @@
 void NText::append(const char *text, int len, int color) {
   int i;
   NLine *nl;
+  char buf[len + 1];
   char *p;
 
   if (len < 0) {
@@ -244,11 +245,14 @@
     return;
   }
 
-  p = strchr(text, '\n');
+  strncpy(buf, text, len);
+  buf[len] = '\0';
+
+  p = strchr(buf, '\n');
   if (p!=NULL) {
     *p = 0;
-    i = strlen(text);
-    nl = new NLine(text, color);
+    i = strlen(buf);
+    nl = new NLine(buf, color);
     *p = '\n';
     lines.push_back(nl);
     formatLine(lines.size()-1);
@@ -257,7 +261,7 @@
   }
 
   // if search for \n failed, this is a single line
-  nl = new NLine(text, color);
+  nl = new NLine(buf, color);
   lines.push_back(nl);
   formatLine(lines.size()-1);
   discardExcess();