Skip to content

Commit a0cce34

Browse files
committed
fix how we count line numbers
if the file is not encoded properly, reading it as text will raise an exception. this opens the file in binary mode, and uses a more compact way to read the number of lines
1 parent fa78055 commit a0cce34

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

chc/cmdline/ParseManager.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,8 @@ def preprocess_file_with_gcc(
290290

291291
def get_file_length(self, fname: str) -> int:
292292
"""Return the number of lines in named file."""
293-
294-
with open(fname) as f:
295-
for i, l in enumerate(f):
296-
pass
297-
return i + 1
293+
with open(fname, 'rb') as f:
294+
return sum(1 for _ in f)
298295

299296
def normalize_filename(self, filename: str) -> str:
300297
"""Make filename relative to project directory (if in project

0 commit comments

Comments
 (0)