Break up ASSERT statements with ands.
ASSERT(cond1); ASSERT(cond2) is equivalent to ASSERT(cond1 && cond2),
but makes it easier to see which condition failed.
Change-Id: Ia52e15ab76e581c5cc36053e74fca303a42610a9
Reviewed-on: https://pdfium-review.googlesource.com/c/45530
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/edit/cpdf_creator.cpp b/core/fpdfapi/edit/cpdf_creator.cpp
index 7eb7673..06eb979 100644
--- a/core/fpdfapi/edit/cpdf_creator.cpp
+++ b/core/fpdfapi/edit/cpdf_creator.cpp
@@ -74,7 +74,8 @@
}
bool CFX_FileBufferArchive::WriteBlock(const void* pBuf, size_t size) {
- ASSERT(pBuf && size > 0);
+ ASSERT(pBuf);
+ ASSERT(size > 0);
const uint8_t* buffer = reinterpret_cast<const uint8_t*>(pBuf);
size_t temp_size = size;
diff --git a/core/fxcrt/cfx_datetime.cpp b/core/fxcrt/cfx_datetime.cpp
index 0147b59..8d5a637 100644
--- a/core/fxcrt/cfx_datetime.cpp
+++ b/core/fxcrt/cfx_datetime.cpp
@@ -29,7 +29,8 @@
int32_t DaysBeforeMonthInYear(int32_t iYear, uint8_t iMonth) {
ASSERT(iYear != 0);
- ASSERT(iMonth >= 1 && iMonth <= 12);
+ ASSERT(iMonth >= 1);
+ ASSERT(iMonth <= 12);
const int32_t* p =
FX_IsLeapYear(iYear) ? g_FXDaysBeforeLeapMonth : g_FXDaysBeforeMonth;
@@ -46,8 +47,10 @@
uint8_t iDay,
bool bIncludeThisDay) {
ASSERT(iYear != 0);
- ASSERT(iMonth >= 1 && iMonth <= 12);
- ASSERT(iDay >= 1 && iDay <= FX_DaysInMonth(iYear, iMonth));
+ ASSERT(iMonth >= 1);
+ ASSERT(iMonth <= 12);
+ ASSERT(iDay >= 1);
+ ASSERT(iDay <= FX_DaysInMonth(iYear, iMonth));
int64_t iDays = DaysBeforeMonthInYear(iYear, iMonth);
iDays += iDay;
@@ -79,7 +82,8 @@
uint8_t FX_DaysInMonth(int32_t iYear, uint8_t iMonth) {
ASSERT(iYear != 0);
- ASSERT(iMonth >= 1 && iMonth <= 12);
+ ASSERT(iMonth >= 1);
+ ASSERT(iMonth <= 12);
const uint8_t* p =
FX_IsLeapYear(iYear) ? g_FXDaysPerLeapMonth : g_FXDaysPerMonth;
diff --git a/core/fxcrt/cfx_seekablestreamproxy.cpp b/core/fxcrt/cfx_seekablestreamproxy.cpp
index 98ed8b1..14a016c 100644
--- a/core/fxcrt/cfx_seekablestreamproxy.cpp
+++ b/core/fxcrt/cfx_seekablestreamproxy.cpp
@@ -28,7 +28,8 @@
size_t srcLen,
wchar_t* pDst,
size_t dstLen) {
- ASSERT(pDst && dstLen > 0);
+ ASSERT(pDst);
+ ASSERT(dstLen > 0);
if (srcLen < 1)
return {0, 0};
@@ -203,7 +204,8 @@
}
size_t CFX_SeekableStreamProxy::ReadData(uint8_t* pBuffer, size_t iBufferSize) {
- ASSERT(pBuffer && iBufferSize > 0);
+ ASSERT(pBuffer);
+ ASSERT(iBufferSize > 0);
iBufferSize =
std::min(iBufferSize, static_cast<size_t>(GetSize() - m_iPosition));
diff --git a/core/fxcrt/css/cfx_cssdeclaration.cpp b/core/fxcrt/css/cfx_cssdeclaration.cpp
index db2ec35..598db98 100644
--- a/core/fxcrt/css/cfx_cssdeclaration.cpp
+++ b/core/fxcrt/css/cfx_cssdeclaration.cpp
@@ -30,7 +30,9 @@
int32_t iValueLen,
float& fValue,
CFX_CSSNumberType& eUnit) {
- ASSERT(pszValue && iValueLen > 0);
+ ASSERT(pszValue);
+ ASSERT(iValueLen > 0);
+
int32_t iUsedLen = 0;
fValue = FXSYS_wcstof(pszValue, iValueLen, &iUsedLen);
if (iUsedLen <= 0)
@@ -57,7 +59,9 @@
int32_t iValueLen,
int32_t* iOffset,
int32_t* iLength) {
- ASSERT(pszValue && iValueLen > 0);
+ ASSERT(pszValue);
+ ASSERT(iValueLen > 0);
+
*iOffset = 0;
*iLength = iValueLen;
if (iValueLen >= 2) {
@@ -74,7 +78,8 @@
bool CFX_CSSDeclaration::ParseCSSColor(const wchar_t* pszValue,
int32_t iValueLen,
FX_ARGB* dwColor) {
- ASSERT(pszValue && iValueLen > 0);
+ ASSERT(pszValue);
+ ASSERT(iValueLen > 0);
ASSERT(dwColor);
if (*pszValue == '#') {
diff --git a/core/fxcrt/css/cfx_cssstyleselector.cpp b/core/fxcrt/css/cfx_cssstyleselector.cpp
index 9b1a223..f6b48bd 100644
--- a/core/fxcrt/css/cfx_cssstyleselector.cpp
+++ b/core/fxcrt/css/cfx_cssstyleselector.cpp
@@ -139,7 +139,8 @@
void CFX_CSSStyleSelector::AppendInlineStyle(CFX_CSSDeclaration* pDecl,
const WideString& style) {
- ASSERT(pDecl && !style.IsEmpty());
+ ASSERT(pDecl);
+ ASSERT(!style.IsEmpty());
auto pSyntax = pdfium::MakeUnique<CFX_CSSSyntaxParser>(
style.c_str(), style.GetLength(), 32, true);
diff --git a/core/fxcrt/css/cfx_csssyntaxparser.cpp b/core/fxcrt/css/cfx_csssyntaxparser.cpp
index 844337c..9cc9991 100644
--- a/core/fxcrt/css/cfx_csssyntaxparser.cpp
+++ b/core/fxcrt/css/cfx_csssyntaxparser.cpp
@@ -35,7 +35,10 @@
: m_iTextDataLen(0),
m_dwCheck(0xFFFFFFFF),
m_eStatus(CFX_CSSSyntaxStatus::None) {
- ASSERT(pBuffer && iBufferSize > 0 && iTextDatSize > 0);
+ ASSERT(pBuffer);
+ ASSERT(iBufferSize > 0);
+ ASSERT(iTextDatSize > 0);
+
m_eMode = bOnlyDeclaration ? CFX_CSSSyntaxMode::PropertyName
: CFX_CSSSyntaxMode::RuleSet;
m_TextData.InitWithSize(iTextDatSize);
diff --git a/core/fxcrt/css/cfx_cssvaluelistparser.cpp b/core/fxcrt/css/cfx_cssvaluelistparser.cpp
index 2339dec..d38dad7 100644
--- a/core/fxcrt/css/cfx_cssvaluelistparser.cpp
+++ b/core/fxcrt/css/cfx_cssvaluelistparser.cpp
@@ -12,7 +12,8 @@
int32_t iLen,
wchar_t separator)
: m_Separator(separator), m_pCur(psz), m_pEnd(psz + iLen) {
- ASSERT(psz && iLen > 0);
+ ASSERT(psz);
+ ASSERT(iLen > 0);
}
bool CFX_CSSValueListParser::NextValue(CFX_CSSPrimitiveType* eType,
diff --git a/core/fxcrt/fx_bidi.cpp b/core/fxcrt/fx_bidi.cpp
index 29eb6ea..7bd34a3 100644
--- a/core/fxcrt/fx_bidi.cpp
+++ b/core/fxcrt/fx_bidi.cpp
@@ -483,7 +483,8 @@
int32_t iBaseLevel,
size_t iStart,
bool bReverse) {
- ASSERT(iBaseLevel >= 0 && iBaseLevel <= kBidiMaxLevel);
+ ASSERT(iBaseLevel >= 0);
+ ASSERT(iBaseLevel <= kBidiMaxLevel);
ASSERT(iStart < iCount);
if (iCount < 1)
diff --git a/core/fxcrt/fx_extension.cpp b/core/fxcrt/fx_extension.cpp
index 443e301..e41b7ab 100644
--- a/core/fxcrt/fx_extension.cpp
+++ b/core/fxcrt/fx_extension.cpp
@@ -115,7 +115,10 @@
}
wchar_t* FXSYS_wcsncpy(wchar_t* dstStr, const wchar_t* srcStr, size_t count) {
- ASSERT(dstStr && srcStr && count > 0);
+ ASSERT(dstStr);
+ ASSERT(srcStr);
+ ASSERT(count > 0);
+
for (size_t i = 0; i < count; ++i)
if ((dstStr[i] = srcStr[i]) == L'\0')
break;
@@ -123,7 +126,10 @@
}
int32_t FXSYS_wcsnicmp(const wchar_t* s1, const wchar_t* s2, size_t count) {
- ASSERT(s1 && s2 && count > 0);
+ ASSERT(s1);
+ ASSERT(s2);
+ ASSERT(count > 0);
+
wchar_t wch1 = 0, wch2 = 0;
while (count-- > 0) {
wch1 = static_cast<wchar_t>(FXSYS_towlower(*s1++));
diff --git a/core/fxcrt/string_data_template.h b/core/fxcrt/string_data_template.h
index 656d350..cda41e0 100644
--- a/core/fxcrt/string_data_template.h
+++ b/core/fxcrt/string_data_template.h
@@ -64,13 +64,18 @@
}
void CopyContents(const CharType* pStr, size_t nLen) {
- ASSERT(nLen >= 0 && nLen <= m_nAllocLength);
+ ASSERT(nLen >= 0);
+ ASSERT(nLen <= m_nAllocLength);
+
memcpy(m_String, pStr, nLen * sizeof(CharType));
m_String[nLen] = 0;
}
void CopyContentsAt(size_t offset, const CharType* pStr, size_t nLen) {
- ASSERT(offset >= 0 && nLen >= 0 && offset + nLen <= m_nAllocLength);
+ ASSERT(offset >= 0);
+ ASSERT(nLen >= 0);
+ ASSERT(offset + nLen <= m_nAllocLength);
+
memcpy(m_String + offset, pStr, nLen * sizeof(CharType));
m_String[offset + nLen] = 0;
}
diff --git a/core/fxge/dib/cfx_dibbase.cpp b/core/fxge/dib/cfx_dibbase.cpp
index 1dcbcf9..a8da398 100644
--- a/core/fxge/dib/cfx_dibbase.cpp
+++ b/core/fxge/dib/cfx_dibbase.cpp
@@ -866,7 +866,9 @@
if (width == 0 || height == 0)
return;
- ASSERT(width > 0 && height > 0);
+ ASSERT(width > 0);
+ ASSERT(height > 0);
+
if (dest_left > m_Width || dest_top > m_Height) {
width = 0;
height = 0;
@@ -905,7 +907,9 @@
}
void CFX_DIBBase::GetPalette(uint32_t* pal, int alpha) const {
- ASSERT(GetBPP() <= 8 && !IsCmykImage());
+ ASSERT(GetBPP() <= 8);
+ ASSERT(!IsCmykImage());
+
if (GetBPP() == 1) {
pal[0] = ((m_pPalette ? m_pPalette.get()[0] : 0xff000000) & 0xffffff) |
(alpha << 24);
diff --git a/core/fxge/dib/cfx_dibitmap.cpp b/core/fxge/dib/cfx_dibitmap.cpp
index 0112704..456161c 100644
--- a/core/fxge/dib/cfx_dibitmap.cpp
+++ b/core/fxge/dib/cfx_dibitmap.cpp
@@ -1054,7 +1054,9 @@
return true;
}
if (m_bpp == 1) {
- ASSERT(!IsCmykImage() && static_cast<uint8_t>(alpha_flag >> 8) == 0);
+ ASSERT(!IsCmykImage());
+ ASSERT(static_cast<uint8_t>(alpha_flag >> 8) == 0);
+
int left_shift = rect.left % 8;
int right_shift = rect.right % 8;
int new_width = rect.right / 8 - rect.left / 8;
diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp
index b995e53..8a189f0 100644
--- a/core/fxge/skia/fx_skia_device.cpp
+++ b/core/fxge/skia/fx_skia_device.cpp
@@ -376,7 +376,8 @@
}
uint8_t FloatToByte(float f) {
- ASSERT(0 <= f && f <= 1);
+ ASSERT(0 <= f);
+ ASSERT(f <= 1);
return (uint8_t)(f * 255.99f);
}
diff --git a/core/fxge/win32/fx_win32_device.cpp b/core/fxge/win32/fx_win32_device.cpp
index 4f2abae..55c385c 100644
--- a/core/fxge/win32/fx_win32_device.cpp
+++ b/core/fxge/win32/fx_win32_device.cpp
@@ -1270,7 +1270,9 @@
const FX_RECT* pClipRect,
const FXDIB_ResampleOptions& options,
BlendMode blend_type) {
- ASSERT(pSource && pClipRect);
+ ASSERT(pSource);
+ ASSERT(pClipRect);
+
if (options.HasAnyOptions() || dest_width > 10000 || dest_width < -10000 ||
dest_height > 10000 || dest_height < -10000) {
return UseFoxitStretchEngine(pSource, color, dest_left, dest_top,
diff --git a/core/fxge/win32/fx_win32_print.cpp b/core/fxge/win32/fx_win32_print.cpp
index f2d3a9c..fab039c 100644
--- a/core/fxge/win32/fx_win32_print.cpp
+++ b/core/fxge/win32/fx_win32_print.cpp
@@ -83,7 +83,8 @@
pSource->GetHeight(), &clip_rect,
FXDIB_ResampleOptions(), BlendMode::kNormal);
}
- ASSERT(pSource && !pSource->IsAlphaMask());
+ ASSERT(pSource);
+ ASSERT(!pSource->IsAlphaMask());
ASSERT(blend_type == BlendMode::kNormal);
if (pSource->HasAlpha())
return false;
diff --git a/fxjs/cfxjse_value.cpp b/fxjs/cfxjse_value.cpp
index a84b571..9f33e33 100644
--- a/fxjs/cfxjse_value.cpp
+++ b/fxjs/cfxjse_value.cpp
@@ -262,7 +262,8 @@
bool CFXJSE_Value::SetFunctionBind(CFXJSE_Value* lpOldFunction,
CFXJSE_Value* lpNewThis) {
- ASSERT(lpOldFunction && lpNewThis);
+ ASSERT(lpOldFunction);
+ ASSERT(lpNewThis);
CFXJSE_ScopeUtil_IsolateHandleRootContext scope(GetIsolate());
v8::Local<v8::Value> rgArgs[2];
diff --git a/fxjs/cjs_eventhandler.cpp b/fxjs/cjs_eventhandler.cpp
index 1a4ffbb..cd3e140 100644
--- a/fxjs/cjs_eventhandler.cpp
+++ b/fxjs/cjs_eventhandler.cpp
@@ -162,7 +162,11 @@
bool bWillCommit,
bool bFieldFull,
bool* pbRc) {
- ASSERT(pValue && pbRc && pSelEnd && pSelStart);
+ ASSERT(pValue);
+ ASSERT(pbRc);
+ ASSERT(pSelStart);
+ ASSERT(pSelEnd);
+
Initialize(JET_FIELD_KEYSTROKE);
m_nCommitKey = 0;
@@ -188,7 +192,9 @@
CPDF_FormField* pTarget,
WideString* pValue,
bool* pbRc) {
- ASSERT(pValue && pbRc);
+ ASSERT(pValue);
+ ASSERT(pbRc);
+
Initialize(JET_FIELD_VALIDATE);
m_pWideStrChange = strChange;
@@ -205,7 +211,9 @@
CPDF_FormField* pTarget,
WideString* pValue,
bool* pRc) {
- ASSERT(pValue && pRc);
+ ASSERT(pValue);
+ ASSERT(pRc);
+
Initialize(JET_FIELD_CALCULATE);
if (pSource)
diff --git a/xfa/fde/cfde_textout.cpp b/xfa/fde/cfde_textout.cpp
index 07a0962..6d7aaea 100644
--- a/xfa/fde/cfde_textout.cpp
+++ b/xfa/fde/cfde_textout.cpp
@@ -40,7 +40,9 @@
int32_t iCount,
float fFontSize,
const CFX_Matrix* pMatrix) {
- ASSERT(pFont && pCharPos && iCount > 0);
+ ASSERT(pFont);
+ ASSERT(pCharPos);
+ ASSERT(iCount > 0);
CFX_Font* pFxFont = pFont->GetDevFont();
if (FontStyleIsItalic(pFont->GetFontStyles()) && !pFxFont->IsItalic()) {
@@ -207,7 +209,8 @@
return;
}
- ASSERT(m_pFont && m_fFontSize >= 1.0f);
+ ASSERT(m_pFont);
+ ASSERT(m_fFontSize >= 1.0f);
if (!m_Styles.single_line_) {
if (pRect->Width() < 1.0f)
@@ -283,7 +286,8 @@
void CFDE_TextOut::DrawLogicText(CFX_RenderDevice* device,
const WideStringView& str,
const CFX_RectF& rect) {
- ASSERT(m_pFont && m_fFontSize >= 1.0f);
+ ASSERT(m_pFont);
+ ASSERT(m_fFontSize >= 1.0f);
if (str.IsEmpty())
return;
diff --git a/xfa/fgas/layout/cfx_breakpiece.cpp b/xfa/fgas/layout/cfx_breakpiece.cpp
index 364c117..9372c2f 100644
--- a/xfa/fgas/layout/cfx_breakpiece.cpp
+++ b/xfa/fgas/layout/cfx_breakpiece.cpp
@@ -30,7 +30,9 @@
}
CFX_Char* CFX_BreakPiece::GetChar(int32_t index) const {
- ASSERT(index >= 0 && index < m_iChars && m_pChars);
+ ASSERT(index >= 0);
+ ASSERT(index < m_iChars);
+ ASSERT(m_pChars);
return &(*m_pChars)[m_iStartChar + index];
}
diff --git a/xfa/fgas/layout/cfx_rtfbreak.cpp b/xfa/fgas/layout/cfx_rtfbreak.cpp
index a50bade..1f6f6e6 100644
--- a/xfa/fgas/layout/cfx_rtfbreak.cpp
+++ b/xfa/fgas/layout/cfx_rtfbreak.cpp
@@ -66,7 +66,8 @@
}
CFX_BreakType CFX_RTFBreak::AppendChar(wchar_t wch) {
- ASSERT(m_pFont && m_pCurLine);
+ ASSERT(m_pFont);
+ ASSERT(m_pCurLine);
uint32_t dwProps = FX_GetUnicodeProperties(wch);
FX_CHARTYPE chartype = GetCharTypeFromProp(dwProps);
@@ -679,7 +680,8 @@
void CFX_RTFBreak::SplitTextLine(CFX_BreakLine* pCurLine,
CFX_BreakLine* pNextLine,
bool bAllChars) {
- ASSERT(pCurLine && pNextLine);
+ ASSERT(pCurLine);
+ ASSERT(pNextLine);
if (pCurLine->m_LineChars.size() < 2)
return;
@@ -720,7 +722,8 @@
if (!pText || pText->iLength < 1)
return 0;
- ASSERT(pText->pFont && pText->pRect);
+ ASSERT(pText->pFont);
+ ASSERT(pText->pRect);
RetainPtr<CFGAS_GEFont> pFont = pText->pFont;
CFX_RectF rtText(*pText->pRect);
diff --git a/xfa/fgas/layout/cfx_txtbreak.cpp b/xfa/fgas/layout/cfx_txtbreak.cpp
index 2a03b9c..940052e 100644
--- a/xfa/fgas/layout/cfx_txtbreak.cpp
+++ b/xfa/fgas/layout/cfx_txtbreak.cpp
@@ -38,8 +38,8 @@
}
void CFX_TxtBreak::SetAlignment(int32_t iAlignment) {
- ASSERT(iAlignment >= CFX_TxtLineAlignment_Left &&
- iAlignment <= CFX_TxtLineAlignment_Justified);
+ ASSERT(iAlignment >= CFX_TxtLineAlignment_Left);
+ ASSERT(iAlignment <= CFX_TxtLineAlignment_Justified);
m_iAlignment = iAlignment;
}
@@ -613,7 +613,9 @@
void CFX_TxtBreak::SplitTextLine(CFX_BreakLine* pCurLine,
CFX_BreakLine* pNextLine,
bool bAllChars) {
- ASSERT(pCurLine && pNextLine);
+ ASSERT(pCurLine);
+ ASSERT(pNextLine);
+
if (pCurLine->m_LineChars.size() < 2)
return;
diff --git a/xfa/fwl/cfwl_monthcalendar.cpp b/xfa/fwl/cfwl_monthcalendar.cpp
index d55984f..dc8328b 100644
--- a/xfa/fwl/cfwl_monthcalendar.cpp
+++ b/xfa/fwl/cfwl_monthcalendar.cpp
@@ -643,7 +643,9 @@
}
WideString CFWL_MonthCalendar::GetHeadText(int32_t iYear, int32_t iMonth) {
- ASSERT(iMonth > 0 && iMonth < 13);
+ ASSERT(iMonth > 0);
+ ASSERT(iMonth < 13);
+
static const wchar_t* const pMonth[] = {L"January", L"February", L"March",
L"April", L"May", L"June",
L"July", L"August", L"September",
diff --git a/xfa/fxfa/cxfa_ffpageview.cpp b/xfa/fxfa/cxfa_ffpageview.cpp
index 351f576..6028059 100644
--- a/xfa/fxfa/cxfa_ffpageview.cpp
+++ b/xfa/fxfa/cxfa_ffpageview.cpp
@@ -31,7 +31,8 @@
const FX_RECT& devicePageRect,
int32_t iRotate,
uint32_t dwCoordinatesType) {
- ASSERT(iRotate >= 0 && iRotate <= 3);
+ ASSERT(iRotate >= 0);
+ ASSERT(iRotate <= 3);
bool bFlipX = (dwCoordinatesType & 0x01) != 0;
bool bFlipY = (dwCoordinatesType & 0x02) != 0;
diff --git a/xfa/fxfa/parser/cxfa_localevalue.cpp b/xfa/fxfa/parser/cxfa_localevalue.cpp
index ef6c685..e0cf99d 100644
--- a/xfa/fxfa/parser/cxfa_localevalue.cpp
+++ b/xfa/fxfa/parser/cxfa_localevalue.cpp
@@ -678,7 +678,9 @@
int32_t nIntLen,
int32_t nDecLen) {
ASSERT(wsFormat.IsEmpty());
- ASSERT(nIntLen >= -1 && nDecLen >= -1);
+ ASSERT(nIntLen >= -1);
+ ASSERT(nDecLen >= -1);
+
int32_t nTotalLen = (nIntLen >= 0 ? nIntLen : 2) + 1 +
(nDecLen >= 0 ? nDecLen : 2) + (nDecLen == 0 ? 0 : 1);
{
diff --git a/xfa/fxfa/parser/cxfa_rectangle.cpp b/xfa/fxfa/parser/cxfa_rectangle.cpp
index 31a19bd..0a7ebea 100644
--- a/xfa/fxfa/parser/cxfa_rectangle.cpp
+++ b/xfa/fxfa/parser/cxfa_rectangle.cpp
@@ -446,7 +446,8 @@
int32_t nIndex,
bool bStart,
bool bCorner) {
- ASSERT(nIndex >= 0 && nIndex < 8);
+ ASSERT(nIndex >= 0);
+ ASSERT(nIndex < 8);
int32_t n = (nIndex & 1) ? nIndex - 1 : nIndex;
CXFA_Stroke* corner1 = strokes[n];