-
Notifications
You must be signed in to change notification settings - Fork 208
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
base: main
Are you sure you want to change the base?
Conversation
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
There was a problem hiding this 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 |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: 0.f => 0.0f
See https://google.github.io/styleguide/cppguide.html#Floating_Literals
// 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); |
There was a problem hiding this comment.
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?