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

Loop conditions #80

Closed
AntonyCorbett opened this issue Dec 7, 2018 · 1 comment
Closed

Loop conditions #80

AntonyCorbett opened this issue Dec 7, 2018 · 1 comment

Comments

@AntonyCorbett
Copy link

AntonyCorbett commented Dec 7, 2018

The loop conditions seem odd in this utility function.

 unsigned long readBitsFromReversedStream(size_t& bitp, const unsigned char* bits, unsigned long nbits)
  {
    unsigned long result = 0;
    for(size_t i = nbits - 1; i < nbits; i--) result += ((readBitFromReversedStream(bitp, bits)) << i);
    return result;
  }
@lvandeve
Copy link
Owner

Thanks for the report!

True indeed, it looks odd, but relies on the unsigned integer overflow to wrap around to a large positive integer, which is why it was guaranteed to work

This may be from an older version though, it's no longer like that in here in this function:

https://github.com/lvandeve/lodepng/blob/master/lodepng.cpp

So should be in order now :) Closing this issue

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