Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bad version comparison in all rpm #896

Closed
fedya opened this issue Oct 14, 2019 · 2 comments
Closed

bad version comparison in all rpm #896

fedya opened this issue Oct 14, 2019 · 2 comments

Comments

@fedya
Copy link

fedya commented Oct 14, 2019

example

#include <iostream>
#include <stdint.h>
#include <rpm/rpmlib.h>

int main() {
  const char * version1 = "0.13-5";
  const char * version2 = "0.13.1-5";

  int result = rpmvercmp(version1, version2);
  if (result == -1)
    std::cout << version1 << " < " << version2 << std::endl;;
  if (result == 0)
    std::cout << version1 << " = " << version2 << std::endl;;
  if (result == 1)
    std::cout << version1 << " > " << version2 << std::endl;;
}
# g++ shit.cc -lrpm
# ./a.out

result: 0.13-5 > 0.13.1-5
What is definetly wrong.
Same in RPM5.

but

# rpmdev-vercmp 0.13-5 0.13.1-5
# 0.13-5 < 0.13.1-5

works fine

@mlschroe
Copy link
Contributor

No, that's correct. The - character compares the same as the . character, and 5 is greater than 1.

The rpmvercmp function only compares the version or the release parts. You need to split the input into epoch/version/release and then do individual rpmvercmp calls.

@mlschroe
Copy link
Contributor

(See also issue #561 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants