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

Fix some static analysis minor defects #2569

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

Conversation

vrabaud
Copy link
Collaborator

@vrabaud vrabaud commented Jan 13, 2025

  • fix comparison of uint64_t with SIZE_MAX for platforms where uint64_t and size_t are different
  • do not compare two floats for equality

- fix comparison of uint64_t with SIZE_MAX for platforms where
  uint64_t and size_t are different
- do not compare two floats for equality
@vrabaud vrabaud requested a review from wantehchang January 13, 2025 10:28
@vrabaud vrabaud marked this pull request as ready for review January 13, 2025 10:28
Copy link
Collaborator

@wantehchang wantehchang left a comment

Choose a reason for hiding this comment

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

Thanks for the fixes. I suggest a change to the UINT64_MAX != SIZE_MAX tests.

@@ -1138,9 +1138,11 @@ static avifResult avifDecoderItemMaxExtent(const avifDecoderItem * item, const a

outExtent->offset = minOffset;
const uint64_t extentLength = maxOffset - minOffset;
#if UINT64_MAX != SIZE_MAX
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: Let's use > in these tests:

#if UINT64_MAX > SIZE_MAX

This excludes the unlikely case of UINT64_MAX < SIZE_MAX.

@@ -45,12 +45,13 @@ static float avifGetGainMapWeight(float hdrHeadroom, const avifGainMap * gainMap
{
const float baseHdrHeadroom = avifUnsignedFractionToFloat(gainMap->baseHdrHeadroom);
const float alternateHdrHeadroom = avifUnsignedFractionToFloat(gainMap->alternateHdrHeadroom);
if (baseHdrHeadroom == alternateHdrHeadroom) {
const float diffHdrHeadroom = alternateHdrHeadroom - baseHdrHeadroom;
if (diffHdrHeadroom == 0.f) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

// Do not apply the gain map if the HDR headroom is the same.
// This case is not handled in the specification and does not make practical sense.
return 0.0f;
}
const float w = AVIF_CLAMP((hdrHeadroom - baseHdrHeadroom) / (alternateHdrHeadroom - baseHdrHeadroom), 0.0f, 1.0f);
const float w = AVIF_CLAMP((hdrHeadroom - baseHdrHeadroom) / diffHdrHeadroom, 0.0f, 1.0f);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this Coverity defect (464731 Division or modulo by float zero) is a Coverity bug. We don't need to change our code for a Coverity bug if the current code is clearer. We can classify the Coverity defect as a false positive and ignore it in the Coverity UI.

Have you verified (with a Coverity analysis) that this change fixes the Coverity defect?

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