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

get rid of nested if conditions #2372

Merged
merged 1 commit into from
Oct 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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