Skip to content

Commit

Permalink
Argument to isValidCompression should be int rather than Compression (#…
Browse files Browse the repository at this point in the history
…1661)

The sanitizer flags invalid enum values. By definition, the argument
might not be a valid enum value.

Signed-off-by: Cary Phillips <cary@ilm.com>
  • Loading branch information
cary-ilm authored Mar 6, 2024
1 parent bea5cca commit c27ea89
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/lib/OpenEXR/ImfCompression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ getCompressionIdFromName (const std::string& name, Compression& id)

/// Return true if a compression id exists.
bool
isValidCompression (Compression id)
isValidCompression (int id)
{
return id >= NO_COMPRESSION && id < NUM_COMPRESSION_METHODS;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/OpenEXR/ImfCompression.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ IMF_EXPORT void
getCompressionIdFromName (const std::string& name, Compression& id);

/// Return true if a compression id exists.
IMF_EXPORT bool isValidCompression (Compression id);
IMF_EXPORT bool isValidCompression (int id);

/// Return a string enumerating all compression names, with a custom separator.
IMF_EXPORT void
Expand Down
2 changes: 1 addition & 1 deletion src/lib/OpenEXR/ImfCompressionAttribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ CompressionAttribute::readValueFrom (
// (Header::sanityCheck will throw an exception when files with invalid Compression types are read)
//

if (!isValidCompression(static_cast<Compression>(tmp)))
if (!isValidCompression(tmp))
{
tmp = NUM_COMPRESSION_METHODS;
}
Expand Down
3 changes: 2 additions & 1 deletion src/test/OpenEXRTest/testCompressionApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ testCompressionApi (const string& tempDir)

for (int i = 0; i < numMethods; i++)
{
assert (isValidCompression (i) == true);

Compression c = static_cast<Compression> (i);
Compression id;
string name, desc;
Expand All @@ -50,7 +52,6 @@ testCompressionApi (const string& tempDir)
getCompressionDescriptionFromId (c, desc);
assert (!desc.empty ());

assert (isValidCompression (c) == true);
assert (isValidCompression (id) == true);

assert (getCompressionNumScanlines (c) > 0);
Expand Down

0 comments on commit c27ea89

Please sign in to comment.