Skip to content

Commit

Permalink
handle lcov end line number
Browse files Browse the repository at this point in the history
According to the lcov documentation, `FN` field can contain optional
end line number.
Right now the code crashes in this case.
This commit makes sure it doesn't and it's well parsed.

Ref: https://manpages.ubuntu.com/manpages/noble/man1/geninfo.1.html

```
       Following is a list of line numbers for each function name found in the source file:

         FN:<line number of function start>,(<line number of function end>,)?<function name>

       The 'end' line number is optional, and is generated only if the compiler/toolchain version
       is  recent  enough  to  generate  the  data  (e.g., gcc 9 or newer).
```
  • Loading branch information
Cheekie25 committed Dec 3, 2024
1 parent 900877e commit f9aedac
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions fastcov.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,9 +806,10 @@ def parseInfo(path):
})
current_data = fastcov_json["sources"][current_sf][current_test_name]
elif line.startswith("FN:"):
line_num, function_name = line[3:].strip().split(",")
line_nums, function_name = line[3:].strip().rsplit(",", maxsplit=1)
line_num_start = line_nums.split(",")[0]
current_data["functions"][function_name] = {}
current_data["functions"][function_name]["start_line"] = tryParseNumber(line_num)
current_data["functions"][function_name]["start_line"] = tryParseNumber(line_num_start)
elif line.startswith("FNDA:"):
count, function_name = line[5:].strip().split(",")
current_data["functions"][function_name]["execution_count"] = tryParseNumber(count)
Expand Down

0 comments on commit f9aedac

Please sign in to comment.