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

Skip reassignment of the initialization value #530

Open
wants to merge 1 commit into
base: libpng16
Choose a base branch
from

Conversation

irwir
Copy link

@irwir irwir commented Jan 19, 2024

This was incorrect: Reversed condition changed to less instead of less or equal because the value still should be PNG_UINT_31_MAX.
Reassignment of the same value is a common kind of copy-paste errors.
Hence static analysis emits warning in this case.
A better way to avoid reassignment is in the updated commit.

@irwir irwir changed the title Skip reassigning of the initialization value Skip reassignment of the initialization value Jan 19, 2024
Copy link
Contributor

@jbowler jbowler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any reason for such a change. The compiler can work it out too and making the change requires a code review which explains why the change from:

if (a > b)
  spurious assignment;
else if (a <= b)
  required assignment;

To:

if (a < b)
   required assignment;

Is correct. I couldn't work it out; why is the case "a == b" irrelevant?

However, back to the words of the pull request rather than the code; why is this better documentation of what the code does than the original form, which you present as equivalent (ignoring the "a == b" issue)? It seems to me that "if/else" is always more clear ab initio than "if".

@irwir
Copy link
Author

irwir commented Jan 27, 2024

Thanks for reviewing.
I changed the code and the description in the first message.

@jbowler
Copy link
Contributor

jbowler commented Jan 27, 2024

libpng-ng comment: libpng(ng) shouldn't even contain this code for IDAT There is no point detecting an over-long IDAT unless it exceeds the PNG spec length (indicating a corrupted stream). IDAT buffering needs to be controlled internally to optimize the specific zlib implementation (if known) and the architecture performance; small buffers or large buffers depend on the relative speed of the zlib window copy vs the libpng row handling for large images and for small images the code can avoid the window copy entirely if enough is known about the zlib implementation.

@irwir
Copy link
Author

irwir commented Jan 30, 2024

As could be read, at least one more version of 1.6 was planned. So this code might stay for some time, while 1.7 branch did not pan out.

PS. About 5 years ago in one discussion it was suggested to rename libspng to libpng-ng. It did not happen.

@jbowler
Copy link
Contributor

jbowler commented Oct 4, 2024

@ctruta: won't fix

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

Successfully merging this pull request may close these issues.

2 participants