libdnf: fix return value of findProductId()#3208
Merged
jirihnidek merged 1 commit intomainfrom Feb 14, 2023
Merged
Conversation
e25f065 to
050d1aa
Compare
findProductId() returns an int, either -1 or 1 depending on whether it was possible to find the product ID in the specified certificate. The problem with this kind of return value is that's very easy to mistake for a boolean, and indeed installProductId() has a boolean-like check that it is always true, no matter the return value of findProductId(). As a fix, change the return type of findProductId() to gboolean, with true returned whether the search succeeded: - reduce the scope of the 'ret_val' variable, so there are less chances to use it wrongly - make 'ret_val' false by default, only changing it to true in the only place where it needs to be like that - adapt the tests accordingly Reported-by: Matyas Horky
050d1aa to
77aee7e
Compare
Contributor
Author
|
In case your question is: why did this "work" so far? subscription-manager/src/plugins/libdnf/product-id.c Lines 974 to 996 in 703c212
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
findProductId()returns an int, either -1 or 1 depending on whether it was possible to find the product ID in the specified certificate. The problem with this kind of return value is that's very easy to mistake for a boolean, and indeedinstallProductId()has a boolean-like check that it is always true, no matter the return value offindProductId().As a fix, change the return type of
findProductId()to gboolean, with true returned whether the search succeeded:ret_valvariable, so there are less chances to use it wronglyret_valfalse by default, only changing it to true in the only place where it needs to be like thatReported-by: Matyas Horky