From 85f019a8e7d33cbba368a6c6b75fd091269e14a1 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Fri, 17 Mar 2017 15:14:19 -0700 Subject: Add pdfium::clamp() as a placeholder for std::clamp(). Ue it to fix a typo as well. BUG=pdfium:634 Change-Id: I2d686242ffb841aedc2fae6a3cf7a00bea667404 Reviewed-on: https://pdfium-review.googlesource.com/3113 Commit-Queue: Lei Zhang Reviewed-by: Tom Sepez --- core/fxcrt/fx_basic_bstring.cpp | 5 +++-- core/fxcrt/fx_basic_wstring.cpp | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'core/fxcrt') diff --git a/core/fxcrt/fx_basic_bstring.cpp b/core/fxcrt/fx_basic_bstring.cpp index b4eb4a75e0..f049b14c3a 100644 --- a/core/fxcrt/fx_basic_bstring.cpp +++ b/core/fxcrt/fx_basic_bstring.cpp @@ -12,6 +12,7 @@ #include "core/fxcrt/cfx_string_pool_template.h" #include "core/fxcrt/fx_basic.h" #include "third_party/base/numerics/safe_math.h" +#include "third_party/base/stl_util.h" template class CFX_StringDataTemplate; template class CFX_StringCTemplate; @@ -405,8 +406,8 @@ CFX_ByteString CFX_ByteString::Mid(FX_STRSIZE nFirst, FX_STRSIZE nCount) const { if (!m_pData) return CFX_ByteString(); - nFirst = std::min(std::max(nFirst, 0), m_pData->m_nDataLength); - nCount = std::min(std::max(nCount, 0), m_pData->m_nDataLength - nFirst); + nFirst = pdfium::clamp(nFirst, 0, m_pData->m_nDataLength); + nCount = pdfium::clamp(nCount, 0, m_pData->m_nDataLength - nFirst); if (nCount == 0) return CFX_ByteString(); diff --git a/core/fxcrt/fx_basic_wstring.cpp b/core/fxcrt/fx_basic_wstring.cpp index 8522d42a38..384b0b0086 100644 --- a/core/fxcrt/fx_basic_wstring.cpp +++ b/core/fxcrt/fx_basic_wstring.cpp @@ -13,6 +13,7 @@ #include "core/fxcrt/fx_basic.h" #include "core/fxcrt/fx_ext.h" #include "third_party/base/numerics/safe_math.h" +#include "third_party/base/stl_util.h" template class CFX_StringDataTemplate; template class CFX_StringCTemplate; @@ -375,8 +376,8 @@ CFX_WideString CFX_WideString::Mid(FX_STRSIZE nFirst, FX_STRSIZE nCount) const { if (!m_pData) return CFX_WideString(); - nFirst = std::min(std::max(nFirst, 0), m_pData->m_nDataLength); - nCount = std::min(std::max(nCount, 0), m_pData->m_nDataLength - nFirst); + nFirst = pdfium::clamp(nFirst, 0, m_pData->m_nDataLength); + nCount = pdfium::clamp(nCount, 0, m_pData->m_nDataLength - nFirst); if (nCount == 0) return CFX_WideString(); -- cgit v1.2.3