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

check_license() and check_license1() from the README do not behave identical #20

Open
BullyWiiPlaza opened this issue Jun 22, 2020 · 3 comments

Comments

@BullyWiiPlaza
Copy link

The README introduces a non-obfuscated example check_license() code and an obfuscated check_license1() code. Logically, generating a key based on the user name and then checking the license should always return 1:

const auto user_name = "obfy";
const auto generated_license = generate_license(user_name);
const auto is_license_valid = check_license1(user_name, generated_license.c_str());
std::cout << "License valid: " << is_license_valid << std::endl;

If I run this code it actually prints 0 using check_license1() but 1 using check_license() regardless of debug or release build. Shouldn't both functions behave idental? Why don't they?

@fritzone
Copy link
Owner

Thanks for reporting this issue, let me check the reason for this misbehaviour and I will get back to this thread when I have some conclusion why this happens.

@chausner
Copy link

The problem is with the post-increment operator in this line:

V(current) += user[V(i)++];

Changing it to

V(current) += user[V(i)];
V(i)++;

makes the sample work.

The root cause appears to be this implementation of the post-increment operator:

    /* post increment/decrement */
    refholder<T> operator++(int) { refholder<T> rv(*this); operator ++(); return rv; }

I only had a brief look at the code but it seems refholder<T> rv(*this) only creates a shallow copy, the reference continues to point to the same underlying value so it will get mutated by operator++.

@BullyWiiPlaza
Copy link
Author

Any updates on this matter regarding pull requests or commits to the repository?

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

3 participants