fix buffer overflow in countlines for files greater than 32k

Signed-off-by: Derek Stevens <nilix@nilfm.cc>
This commit is contained in:
Derek Stevens 2023-02-05 09:50:53 -07:00 committed by Anirudh Oppiliappan
parent c90b2b5193
commit d5a33e9150
No known key found for this signature in database
GPG Key ID: 8A93F96F78C5D4C4
1 changed files with 1 additions and 1 deletions

View File

@ -59,7 +59,7 @@ func countLines(r io.Reader) (int, error) {
switch {
case err == io.EOF:
/* handle last line not having a newline at the end */
if bufLen >= 1 && buf[bufLen-1] != '\n' {
if bufLen >= 1 && buf[(bufLen-1)%(32*1024)] != '\n' {
count++
}
return count, nil