Skip to content

Commit

Permalink
get rid of nested if conditions
Browse files Browse the repository at this point in the history
Easier to read with lambdas.

Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb committed Oct 4, 2022
1 parent a2cb06a commit 7f913b4
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions src/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,35 @@ void Image::printIFDStructure(BasicIo& io, std::ostream& out, Exiv2::PrintStruct
std::string sp; // output spacer

// prepare to print the value
uint32_t kount = isPrintXMP(tag, option) ? count // haul in all the data
: isPrintICC(tag, option) ? count // ditto
: isStringType(type) ? (count > 32 ? 32 : count) // restrict long arrays
: count > 5 ? 5
: count;
uint32_t kount = [=] {
// haul in all the data
if (isPrintXMP(tag, option))
return count;
// ditto
if (isPrintICC(tag, option))
return count;
// restrict long arrays
if (isStringType(type)) {
if (count > 32u)
return 32u;
return count;
}
if (count > 5u)
return 5u;
return count;
}();
uint32_t pad = isStringType(type) ? 1 : 0;
size_t size = isStringType(type) ? 1 : is2ByteType(type) ? 2 : is4ByteType(type) ? 4 : is8ByteType(type) ? 8 : 1;
size_t size = [=] {
if (isStringType(type))
return 1;
if (is2ByteType(type))
return 2;
if (is4ByteType(type))
return 4;
if (is8ByteType(type))
return 8;
return 1;
}();

// if ( offset > io.size() ) offset = 0; // Denial of service?

Expand Down

0 comments on commit 7f913b4

Please sign in to comment.