@@ -67,13 +67,9 @@ void TFileViewer::draw()
67
67
68
68
if ( delta.y + i < fileLines->getCount () )
69
69
{
70
- char s[maxLineLength+1 ];
71
70
p = (char *)( fileLines->at (delta.y +i) );
72
- if ( p == 0 || strlen (p) < delta.x )
73
- s[0 ] = EOS;
74
- else
75
- strnzcpy ( s, p+delta.x , maxLineLength+1 );
76
- b.moveStr ( 0 , s, c );
71
+ if ( p )
72
+ b.moveStr ( 0 , p, c, (short )size.x , delta.x );
77
73
}
78
74
writeBuf ( 0 , i, (short )size.x , 1 , b );
79
75
}
@@ -103,7 +99,8 @@ void TFileViewer::readFile( const char *fName )
103
99
}
104
100
else
105
101
{
106
- char line[maxLineLength+1 ];
102
+ char *line = (char *) malloc (maxLineLength);
103
+ size_t lineSize = maxLineLength;
107
104
char c;
108
105
while ( !lowMemory () &&
109
106
!fileToView.eof () &&
@@ -113,17 +110,19 @@ void TFileViewer::readFile( const char *fName )
113
110
int i = 0 ;
114
111
while ( !fileToView.eof () && c != ' \n ' && c != ' \r ' ) // read a whole line
115
112
{
116
- if ( i < maxLineLength )
117
- line[i++] = c;
113
+ if (i == lineSize)
114
+ line = (char *) realloc (line, (lineSize *= 2 ));
115
+ line[i++] = c;
118
116
fileToView.get ( c );
119
117
}
120
118
line[i] = ' \0 ' ;
121
119
if ( c == ' \r ' && fileToView.peek () == ' \n ' )
122
120
fileToView.get ( c ); // grab trailing newline on CRLF
123
- limit.x = max ( limit.x , strlen ( line ) );
121
+ limit.x = max ( limit.x , strwidth ( line ) );
124
122
fileLines->insert ( newStr ( line ) );
125
123
}
126
124
isValid = True;
125
+ ::free (line);
127
126
}
128
127
limit.y = fileLines->getCount ();
129
128
}
0 commit comments