Skip to content

Commit

Permalink
work around windows.h min/max macros
Browse files Browse the repository at this point in the history
Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb committed Feb 4, 2023
1 parent b8d4b9c commit 0d353ac
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
14 changes: 7 additions & 7 deletions src/basicio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ void MemIo::Impl::reserve(size_t wcount) {

if (!isMalloced_) {
// Minimum size for 1st block
size_t size = std::max(blockSize * (1 + need / blockSize), size_);
auto size = std::max<size_t>(blockSize * (1 + need / blockSize), size_);
auto data = static_cast<byte*>(std::malloc(size));
if (!data) {
throw Error(ErrorCode::kerMallocFailed);
Expand Down Expand Up @@ -828,8 +828,8 @@ DataBuf MemIo::read(size_t rcount) {
}

size_t MemIo::read(byte* buf, size_t rcount) {
const size_t avail = std::max(p_->size_ - p_->idx_, static_cast<size_t>(0));
const size_t allow = std::min(rcount, avail);
const auto avail = std::max<size_t>(p_->size_ - p_->idx_, 0);
const auto allow = std::min<size_t>(rcount, avail);
if (allow > 0) {
std::memcpy(buf, &p_->data_[p_->idx_], allow);
}
Expand Down Expand Up @@ -1077,7 +1077,7 @@ size_t RemoteIo::Impl::populateBlocks(size_t lowBlock, size_t highBlock) {
size_t iBlock = (rcount == size_) ? 0 : lowBlock;

while (remain) {
size_t allow = std::min(remain, blockSize_);
auto allow = std::min<size_t>(remain, blockSize_);
blocksMap_[iBlock].populate(&source[totalRead], allow);
remain -= allow;
totalRead += allow;
Expand Down Expand Up @@ -1115,7 +1115,7 @@ int RemoteIo::open() {
auto source = reinterpret_cast<byte*>(const_cast<char*>(data.c_str()));
size_t remain = p_->size_, iBlock = 0, totalRead = 0;
while (remain) {
size_t allow = std::min(remain, p_->blockSize_);
auto allow = std::min<size_t>(remain, p_->blockSize_);
p_->blocksMap_[iBlock].populate(&source[totalRead], allow);
remain -= allow;
totalRead += allow;
Expand Down Expand Up @@ -1240,7 +1240,7 @@ size_t RemoteIo::read(byte* buf, size_t rcount) {
return 0;
p_->totalRead_ += rcount;

size_t allow = std::min(rcount, (p_->size_ - p_->idx_));
auto allow = std::min<size_t>(rcount, (p_->size_ - p_->idx_));
size_t lowBlock = p_->idx_ / p_->blockSize_;
size_t highBlock = (p_->idx_ + allow) / p_->blockSize_;

Expand All @@ -1258,7 +1258,7 @@ size_t RemoteIo::read(byte* buf, size_t rcount) {
byte* data = p_->blocksMap_[iBlock++].getData();
if (!data)
data = fakeData;
size_t blockR = std::min(allow, p_->blockSize_ - startPos);
auto blockR = std::min<size_t>(allow, p_->blockSize_ - startPos);
std::memcpy(&buf[totalRead], &data[startPos], blockR);
totalRead += blockR;
startPos = 0;
Expand Down
3 changes: 1 addition & 2 deletions src/jp2image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,7 @@ void Jp2Image::printStructure(std::ostream& out, PrintStructureOption option, si
io_->read(data.data(), data.size());
if (bPrint) {
out << Internal::stringFormat("%8zu | %8u | sub:", address, subBox.length) << toAscii(subBox.type)
<< " | "
<< Internal::binaryToString(makeSlice(data, 0, std::min(static_cast<size_t>(30), data.size())));
<< " | " << Internal::binaryToString(makeSlice(data, 0, std::min<size_t>(30, data.size())));
bLF = true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/pngimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const auto nullComp = reinterpret_cast<const Exiv2::byte*>("\0\0");
const auto typeExif = reinterpret_cast<const Exiv2::byte*>("eXIf");
const auto typeICCP = reinterpret_cast<const Exiv2::byte*>("iCCP");
bool compare(std::string_view str, const Exiv2::DataBuf& buf) {
const auto minlen = std::min(str.size(), buf.size());
const auto minlen = std::min<size_t>(str.size(), buf.size());
return buf.cmpBytes(0, str.data(), minlen) == 0;
}
} // namespace
Expand Down
4 changes: 2 additions & 2 deletions src/tiffcomposite_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ bool TiffBinaryArray::updOrigDataBuf(const byte* pData, size_t size) {

size_t TiffBinaryArray::addElement(size_t idx, const ArrayDef& def) {
auto tag = static_cast<uint16_t>(idx / cfg()->tagStep());
size_t sz = std::min(def.size(tag, cfg()->group_), TiffEntryBase::doSize() - idx);
auto sz = std::min<size_t>(def.size(tag, cfg()->group_), TiffEntryBase::doSize() - idx);
auto tc = TiffCreator::create(tag, cfg()->group_);
auto tp = dynamic_cast<TiffBinaryElement*>(tc.get());
// The assertion typically fails if a component is not configured in
Expand Down Expand Up @@ -1361,7 +1361,7 @@ size_t TiffBinaryArray::doSize() const {
if (cfg()->hasFillers_ && def()) {
const ArrayDef* lastDef = def() + defSize() - 1;
auto lastTag = static_cast<uint16_t>(lastDef->idx_ / cfg()->tagStep());
idx = std::max(idx, lastDef->idx_ + lastDef->size(lastTag, cfg()->group_));
idx = std::max<size_t>(idx, lastDef->idx_ + lastDef->size(lastTag, cfg()->group_));
}
return idx;

Expand Down

0 comments on commit 0d353ac

Please sign in to comment.