Skip to content

Commit 066d83b

Browse files
waskyosipma
authored andcommitted
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 0c95b65 commit 066d83b

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)