Skip to content

Commit

Permalink
fix: improve version_compare logic
Browse files Browse the repository at this point in the history
Coverity was warning about unreachable code because I forgot to put in
an if statement.

Signed-off-by: Terri Oda <terri@toybox.ca>
  • Loading branch information
terriko committed Nov 30, 2023
1 parent f2df248 commit e4bb855
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions cve_bin_tool/version_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,14 @@ def version_compare(v1: str, v2: str):
# Honestly it's hard to guess if .dev3 is going to be more or less than .rc4
# unless you know the project, so hopefully people don't expect that kind of range
# matching
v1_newstring = re.sub("([a-zA-Z]+)([0-9]+)", r"\1.\2", v1_array[i])
v2_newstring = re.sub("([a-zA-Z]+)([0-9]+)", r"\1.\2", v2_array[i])
print(f"`{v1_newstring}` and `{v2_newstring}`")
return version_compare(v1_newstring, v2_newstring)
letter_number = re.compile("^[a-zA-Z]+[0-9]+$")
if re.match(letter_number, v1_array[i]) and re.match(
letter_number, v2_array[i]
):
v1_newstring = re.sub("([a-zA-Z]+)([0-9]+)", r"\1.\2", v1_array[i])
v2_newstring = re.sub("([a-zA-Z]+)([0-9]+)", r"\1.\2", v2_array[i])
# print(f"`{v1_newstring}` and `{v2_newstring}`")
return version_compare(v1_newstring, v2_newstring)

# And if all else fails, just compare the strings
if v1_array[i] > v2_array[i]:
Expand Down

0 comments on commit e4bb855

Please sign in to comment.