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

rpm: Fix Visual Studio compiler warnings #2181

Merged
merged 3 commits into from May 13, 2024
Merged

Conversation

stoeckmann
Copy link
Contributor

Instead of simply adding casts, this PR reduces the total amount of casts needed:

  • Adjust type of variables for their specific use case
  • Add a new inline function to unify casting (and clarify code blocks)
  • Use definition to explain magic number (and reduce casts)
  • Use hpos instead of magic number to highlight that additional bytes will be parsed

The latter two changes can be performed because the if-block in question already ensures that hpos and 16 are identical.

The minimum header size is used at multiple instances in the code.
Clarify its meaning by using a definition.

Also, while in an if-block which checked if rpm->pos is 16, use the
value to avoid a warning with Visual Studio and to clarify that
more data will follow beginning at the current position.

Fixes:

warning C4244: '=': conversion from 'uint64_t' to 'long', possible loss of data
It is used in conjunction with avail_in and total, which are ssize_t as
well. Reduces the amount of required casts.
Introduce a new static inlined function which allows type-safe
conversion from uint64_t to size_t even on 32 bit systems.

While at it, turn variable n into size_t because it's used as
argument to memcpy and is always supposed to indicate length of
heap operations, not files.

Fixes:

warning C4244: 'function': conversion from 'uint64_t' to 'size_t', possible loss of data
@mmatuska mmatuska self-requested a review May 13, 2024 06:44
@mmatuska mmatuska merged commit 1d6e5d1 into libarchive:master May 13, 2024
20 checks passed
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.

None yet

2 participants