Clang-format core/fxcrt
Change-Id: I1badda6d7f5cdd784cf91a82d7254ce8b0d4f202
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/130751
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcrt/binary_buffer.cpp b/core/fxcrt/binary_buffer.cpp
index 6e05ec1..e0281e0 100644
--- a/core/fxcrt/binary_buffer.cpp
+++ b/core/fxcrt/binary_buffer.cpp
@@ -95,8 +95,9 @@
}
void BinaryBuffer::AppendSpan(pdfium::span<const uint8_t> span) {
- if (span.empty())
+ if (span.empty()) {
return;
+ }
ExpandBuf(span.size());
fxcrt::Copy(span, pdfium::make_span(buffer_).subspan(GetSize()));
diff --git a/core/fxcrt/bytestring.cpp b/core/fxcrt/bytestring.cpp
index 1b4aad3..d1bd195 100644
--- a/core/fxcrt/bytestring.cpp
+++ b/core/fxcrt/bytestring.cpp
@@ -59,8 +59,9 @@
int nMaxLen = UNSAFE_BUFFERS(vsnprintf(nullptr, 0, pFormat, argListCopy));
va_end(argListCopy);
- if (nMaxLen <= 0)
+ if (nMaxLen <= 0) {
return ByteString();
+ }
ByteString ret;
{
@@ -120,8 +121,9 @@
nSafeLen += str2.GetLength();
size_t nNewLen = nSafeLen.ValueOrDie();
- if (nNewLen == 0)
+ if (nNewLen == 0) {
return;
+ }
data_ = StringData::Create(nNewLen);
data_->CopyContents(str1.span());
@@ -130,12 +132,14 @@
ByteString::ByteString(const std::initializer_list<ByteStringView>& list) {
FX_SAFE_SIZE_T nSafeLen = 0;
- for (const auto& item : list)
+ for (const auto& item : list) {
nSafeLen += item.GetLength();
+ }
size_t nNewLen = nSafeLen.ValueOrDie();
- if (nNewLen == 0)
+ if (nNewLen == 0) {
return;
+ }
data_ = StringData::Create(nNewLen);
@@ -165,10 +169,11 @@
}
ByteString& ByteString::operator=(ByteStringView str) {
- if (str.IsEmpty())
+ if (str.IsEmpty()) {
clear();
- else
+ } else {
AssignCopy(str.unterminated_c_str(), str.GetLength());
+ }
return *this;
}
@@ -212,8 +217,9 @@
}
ByteString& ByteString::operator+=(ByteStringView str) {
- if (!str.IsEmpty())
+ if (!str.IsEmpty()) {
Concat(str.unterminated_c_str(), str.GetLength());
+ }
return *this;
}
@@ -224,8 +230,9 @@
return !ptr || !ptr[0];
}
- if (!ptr)
+ if (!ptr) {
return data_->data_length_ == 0;
+ }
// SAFETY: `data_length_` is within `string_`, and the strlen() call
// (whose own safety is required from the caller) ensures there are
@@ -351,16 +358,18 @@
}
void ByteString::MakeLower() {
- if (IsEmpty())
+ if (IsEmpty()) {
return;
+ }
ReallocBeforeWrite(data_->data_length_);
FXSYS_strlwr(data_->string_);
}
void ByteString::MakeUpper() {
- if (IsEmpty())
+ if (IsEmpty()) {
return;
+ }
ReallocBeforeWrite(data_->data_length_);
FXSYS_strupr(data_->string_);
@@ -378,10 +387,12 @@
// SAFETY: Comparison limited to minimum valid length of either argument.
int result = UNSAFE_BUFFERS(
FXSYS_memcmp(data_->string_, str.unterminated_c_str(), min_len));
- if (result != 0)
+ if (result != 0) {
return result;
- if (this_len == that_len)
+ }
+ if (this_len == that_len) {
return 0;
+ }
return this_len < that_len ? -1 : 1;
}
@@ -410,28 +421,32 @@
uint32_t FX_HashCode_GetA(ByteStringView str) {
uint32_t dwHashCode = 0;
- for (ByteStringView::UnsignedType c : str)
+ for (ByteStringView::UnsignedType c : str) {
dwHashCode = 31 * dwHashCode + c;
+ }
return dwHashCode;
}
uint32_t FX_HashCode_GetLoweredA(ByteStringView str) {
uint32_t dwHashCode = 0;
- for (ByteStringView::UnsignedType c : str)
+ for (ByteStringView::UnsignedType c : str) {
dwHashCode = 31 * dwHashCode + tolower(c);
+ }
return dwHashCode;
}
uint32_t FX_HashCode_GetAsIfW(ByteStringView str) {
uint32_t dwHashCode = 0;
- for (ByteStringView::UnsignedType c : str)
+ for (ByteStringView::UnsignedType c : str) {
dwHashCode = 1313 * dwHashCode + c;
+ }
return dwHashCode;
}
uint32_t FX_HashCode_GetLoweredAsIfW(ByteStringView str) {
uint32_t dwHashCode = 0;
- for (ByteStringView::UnsignedType c : str)
+ for (ByteStringView::UnsignedType c : str) {
dwHashCode = 1313 * dwHashCode + FXSYS_towlower(c);
+ }
return dwHashCode;
}
diff --git a/core/fxcrt/cfx_bitstream.cpp b/core/fxcrt/cfx_bitstream.cpp
index f0e305d..6333465 100644
--- a/core/fxcrt/cfx_bitstream.cpp
+++ b/core/fxcrt/cfx_bitstream.cpp
@@ -57,8 +57,9 @@
bit_left -= 8;
result |= data_[byte_pos++] << bit_left;
}
- if (bit_left)
+ if (bit_left) {
result |= data_[byte_pos] >> (8 - bit_left);
+ }
bit_pos_ += nBits;
return result;
}
diff --git a/core/fxcrt/cfx_datetime.cpp b/core/fxcrt/cfx_datetime.cpp
index 6a9359f..f8952b2 100644
--- a/core/fxcrt/cfx_datetime.cpp
+++ b/core/fxcrt/cfx_datetime.cpp
@@ -51,8 +51,9 @@
int64_t iDays = DaysBeforeMonthInYear(iYear, iMonth);
iDays += iDay;
- if (!bIncludeThisDay)
+ if (!bIncludeThisDay) {
iDays--;
+ }
if (iYear > 0) {
iYear--;
@@ -93,8 +94,9 @@
int32_t CFX_DateTime::GetDayOfWeek() const {
int32_t v = static_cast<int32_t>(DateToDays(year_, month_, day_, true) % 7);
- if (v < 0)
+ if (v < 0) {
v += 7;
+ }
return v;
}
diff --git a/core/fxcrt/cfx_fileaccess_windows.cpp b/core/fxcrt/cfx_fileaccess_windows.cpp
index d5b6788..7adc1b5 100644
--- a/core/fxcrt/cfx_fileaccess_windows.cpp
+++ b/core/fxcrt/cfx_fileaccess_windows.cpp
@@ -121,11 +121,13 @@
return 0;
}
- if (pos >= GetSize())
+ if (pos >= GetSize()) {
return 0;
+ }
- if (SetPosition(pos) == (FX_FILESIZE)-1)
+ if (SetPosition(pos) == (FX_FILESIZE)-1) {
return 0;
+ }
return Read(buffer);
}
@@ -139,8 +141,9 @@
}
bool CFX_FileAccess_Windows::Truncate(FX_FILESIZE szFile) {
- if (SetPosition(szFile) == (FX_FILESIZE)-1)
+ if (SetPosition(szFile) == (FX_FILESIZE)-1) {
return false;
+ }
return !!::SetEndOfFile(file_);
}
diff --git a/core/fxcrt/cfx_memorystream.cpp b/core/fxcrt/cfx_memorystream.cpp
index cb804d8..1c13b8c 100644
--- a/core/fxcrt/cfx_memorystream.cpp
+++ b/core/fxcrt/cfx_memorystream.cpp
@@ -38,8 +38,9 @@
bool CFX_MemoryStream::ReadBlockAtOffset(pdfium::span<uint8_t> buffer,
FX_FILESIZE offset) {
- if (buffer.empty() || offset < 0)
+ if (buffer.empty() || offset < 0) {
return false;
+ }
FX_SAFE_SIZE_T new_pos = buffer.size();
new_pos += offset;
@@ -57,8 +58,9 @@
}
bool CFX_MemoryStream::WriteBlock(pdfium::span<const uint8_t> buffer) {
- if (buffer.empty())
+ if (buffer.empty()) {
return true;
+ }
FX_SAFE_SIZE_T safe_new_pos = buffer.size();
safe_new_pos += cur_size_;
@@ -74,8 +76,9 @@
new_size += (kBlockSize - 1);
new_size /= kBlockSize;
new_size *= kBlockSize;
- if (!new_size.IsValid())
+ if (!new_size.IsValid()) {
return false;
+ }
data_.resize(new_size.ValueOrDie());
}
diff --git a/core/fxcrt/cfx_read_only_span_stream.cpp b/core/fxcrt/cfx_read_only_span_stream.cpp
index 47429a5..6640271 100644
--- a/core/fxcrt/cfx_read_only_span_stream.cpp
+++ b/core/fxcrt/cfx_read_only_span_stream.cpp
@@ -21,13 +21,15 @@
bool CFX_ReadOnlySpanStream::ReadBlockAtOffset(pdfium::span<uint8_t> buffer,
FX_FILESIZE offset) {
- if (buffer.empty() || offset < 0)
+ if (buffer.empty() || offset < 0) {
return false;
+ }
FX_SAFE_SIZE_T pos = buffer.size();
pos += offset;
- if (!pos.IsValid() || pos.ValueOrDie() > span_.size())
+ if (!pos.IsValid() || pos.ValueOrDie() > span_.size()) {
return false;
+ }
fxcrt::Copy(
span_.subspan(pdfium::checked_cast<size_t>(offset), buffer.size()),
diff --git a/core/fxcrt/cfx_seekablestreamproxy.cpp b/core/fxcrt/cfx_seekablestreamproxy.cpp
index 54098f0..5e0d16b 100644
--- a/core/fxcrt/cfx_seekablestreamproxy.cpp
+++ b/core/fxcrt/cfx_seekablestreamproxy.cpp
@@ -41,14 +41,16 @@
iPending = 0;
pDst[iDstNum++] = byte;
} else if (byte < 0xc0) {
- if (iPending < 1)
+ if (iPending < 1) {
continue;
+ }
dwCode = dwCode << 6;
dwCode |= (byte & 0x3f);
--iPending;
- if (iPending == 0)
+ if (iPending == 0) {
pDst[iDstNum++] = dwCode;
+ }
} else if (byte < 0xe0) {
iPending = 1;
dwCode = (byte & 0x1f);
diff --git a/core/fxcrt/cfx_timer.cpp b/core/fxcrt/cfx_timer.cpp
index d7252a1..658f39a 100644
--- a/core/fxcrt/cfx_timer.cpp
+++ b/core/fxcrt/cfx_timer.cpp
@@ -36,8 +36,9 @@
DCHECK(callback_iface_);
if (handler_iface_) {
timer_id_ = handler_iface_->SetTimer(nInterval, TimerProc);
- if (HasValidID())
+ if (HasValidID()) {
(*g_pwl_timer_map)[timer_id_] = this;
+ }
}
}
diff --git a/core/fxcrt/check.h b/core/fxcrt/check.h
index d050b3d..1da982c 100644
--- a/core/fxcrt/check.h
+++ b/core/fxcrt/check.h
@@ -11,11 +11,11 @@
#include "core/fxcrt/compiler_specific.h"
#include "core/fxcrt/immediate_crash.h"
-#define CHECK(condition) \
- do { \
- if (UNLIKELY(!(condition))) { \
- pdfium::ImmediateCrash(); \
- } \
+#define CHECK(condition) \
+ do { \
+ if (UNLIKELY(!(condition))) { \
+ pdfium::ImmediateCrash(); \
+ } \
} while (0)
#if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
diff --git a/core/fxcrt/css/cfx_cssdata.cpp b/core/fxcrt/css/cfx_cssdata.cpp
index 3a85cb0..2ac3378 100644
--- a/core/fxcrt/css/cfx_cssdata.cpp
+++ b/core/fxcrt/css/cfx_cssdata.cpp
@@ -57,8 +57,9 @@
const CFX_CSSData::Property* CFX_CSSData::GetPropertyByName(
WideStringView name) {
- if (name.IsEmpty())
+ if (name.IsEmpty()) {
return nullptr;
+ }
uint32_t hash = FX_HashCode_GetLoweredW(name);
auto* result = std::lower_bound(
@@ -83,8 +84,9 @@
const CFX_CSSData::PropertyValue* CFX_CSSData::GetPropertyValueByName(
WideStringView wsName) {
- if (wsName.IsEmpty())
+ if (wsName.IsEmpty()) {
return nullptr;
+ }
uint32_t hash = FX_HashCode_GetLoweredW(wsName);
auto* result = std::lower_bound(
diff --git a/core/fxcrt/css/cfx_cssdeclaration.cpp b/core/fxcrt/css/cfx_cssdeclaration.cpp
index 8726c41..8ff2e0d 100644
--- a/core/fxcrt/css/cfx_cssdeclaration.cpp
+++ b/core/fxcrt/css/cfx_cssdeclaration.cpp
@@ -451,8 +451,9 @@
case CFX_CSSPropertyValue::Thin:
case CFX_CSSPropertyValue::Thick:
case CFX_CSSPropertyValue::Medium:
- if (!pWidth)
+ if (!pWidth) {
pWidth = pdfium::MakeRetain<CFX_CSSEnumValue>(pValue->eName);
+ }
break;
default:
break;
@@ -499,36 +500,41 @@
case CFX_CSSPropertyValue::XxLarge:
case CFX_CSSPropertyValue::Smaller:
case CFX_CSSPropertyValue::Larger:
- if (!pFontSize)
+ if (!pFontSize) {
pFontSize = pdfium::MakeRetain<CFX_CSSEnumValue>(pValue->eName);
+ }
continue;
case CFX_CSSPropertyValue::Bold:
case CFX_CSSPropertyValue::Bolder:
case CFX_CSSPropertyValue::Lighter:
- if (!pWeight)
+ if (!pWeight) {
pWeight = pdfium::MakeRetain<CFX_CSSEnumValue>(pValue->eName);
+ }
continue;
case CFX_CSSPropertyValue::Italic:
case CFX_CSSPropertyValue::Oblique:
- if (!pStyle)
+ if (!pStyle) {
pStyle = pdfium::MakeRetain<CFX_CSSEnumValue>(pValue->eName);
+ }
continue;
case CFX_CSSPropertyValue::SmallCaps:
- if (!pVariant)
+ if (!pVariant) {
pVariant = pdfium::MakeRetain<CFX_CSSEnumValue>(pValue->eName);
+ }
continue;
case CFX_CSSPropertyValue::Normal:
- if (!pStyle)
+ if (!pStyle) {
pStyle = pdfium::MakeRetain<CFX_CSSEnumValue>(pValue->eName);
- else if (!pVariant)
+ } else if (!pVariant) {
pVariant = pdfium::MakeRetain<CFX_CSSEnumValue>(pValue->eName);
- else if (!pWeight)
+ } else if (!pWeight) {
pWeight = pdfium::MakeRetain<CFX_CSSEnumValue>(pValue->eName);
- else if (!pFontSize)
+ } else if (!pFontSize) {
pFontSize = pdfium::MakeRetain<CFX_CSSEnumValue>(pValue->eName);
- else if (!pLineHeight)
+ } else if (!pLineHeight) {
pLineHeight =
pdfium::MakeRetain<CFX_CSSEnumValue>(pValue->eName);
+ }
continue;
default:
break;
diff --git a/core/fxcrt/css/cfx_cssoutputtextbuf.cpp b/core/fxcrt/css/cfx_cssoutputtextbuf.cpp
index d6b78ea..e22bf5e 100644
--- a/core/fxcrt/css/cfx_cssoutputtextbuf.cpp
+++ b/core/fxcrt/css/cfx_cssoutputtextbuf.cpp
@@ -22,8 +22,9 @@
WideStringView CFX_CSSOutputTextBuf::GetTrailingBlankTrimmedString() const {
WideStringView result(buffer_);
- while (!result.IsEmpty() && result.Back() <= ' ')
+ while (!result.IsEmpty() && result.Back() <= ' ') {
result = result.First(result.GetLength() - 1);
+ }
return result;
}
diff --git a/core/fxcrt/css/cfx_cssrulecollection.cpp b/core/fxcrt/css/cfx_cssrulecollection.cpp
index 51579f5..d134479 100644
--- a/core/fxcrt/css/cfx_cssrulecollection.cpp
+++ b/core/fxcrt/css/cfx_cssrulecollection.cpp
@@ -27,8 +27,9 @@
void CFX_CSSRuleCollection::SetRulesFromSheet(const CFX_CSSStyleSheet* sheet) {
tag_rules_.clear();
- for (size_t i = 0; i < sheet->CountRules(); ++i)
+ for (size_t i = 0; i < sheet->CountRules(); ++i) {
AddRule(sheet->GetRule(i));
+ }
}
void CFX_CSSRuleCollection::AddRule(CFX_CSSStyleRule* pStyleRule) {
diff --git a/core/fxcrt/css/cfx_cssselector.cpp b/core/fxcrt/css/cfx_cssselector.cpp
index 4a0761d..3f829d1 100644
--- a/core/fxcrt/css/cfx_cssselector.cpp
+++ b/core/fxcrt/css/cfx_cssselector.cpp
@@ -16,8 +16,9 @@
size_t GetCSSNameLen(WideStringView str) {
for (size_t i = 0; i < str.GetLength(); ++i) {
wchar_t wch = str[i];
- if (!isascii(wch) || (!isalnum(wch) && wch != '_' && wch != '-'))
+ if (!isascii(wch) || (!isalnum(wch) && wch != '_' && wch != '-')) {
return i;
+ }
}
return str.GetLength();
}
@@ -54,11 +55,13 @@
const bool is_star = wch == '*';
const bool is_valid_char = is_star || (isascii(wch) && isalpha(wch));
- if (!is_valid_char)
+ if (!is_valid_char) {
return nullptr;
+ }
- if (head)
+ if (head) {
head->set_is_descendant();
+ }
size_t len = is_star ? 1 : GetCSSNameLen(str.Last(str.GetLength() - i));
auto new_head =
std::make_unique<CFX_CSSSelector>(str.Substr(i, len), std::move(head));
diff --git a/core/fxcrt/css/cfx_cssstyleselector.cpp b/core/fxcrt/css/cfx_cssstyleselector.cpp
index 6d8928a..7fd33c6 100644
--- a/core/fxcrt/css/cfx_cssstyleselector.cpp
+++ b/core/fxcrt/css/cfx_cssstyleselector.cpp
@@ -34,8 +34,9 @@
RetainPtr<CFX_CSSComputedStyle> CFX_CSSStyleSelector::CreateComputedStyle(
const CFX_CSSComputedStyle* pParentStyle) {
auto pStyle = pdfium::MakeRetain<CFX_CSSComputedStyle>();
- if (pParentStyle)
+ if (pParentStyle) {
pStyle->inherited_data_ = pParentStyle->inherited_data_;
+ }
return pStyle;
}
@@ -51,16 +52,19 @@
std::vector<const CFX_CSSDeclaration*> CFX_CSSStyleSelector::MatchDeclarations(
const WideString& tagname) {
std::vector<const CFX_CSSDeclaration*> matchedDecls;
- if (tagname.IsEmpty())
+ if (tagname.IsEmpty()) {
return matchedDecls;
+ }
auto* rules = ua_rules_.GetTagRuleData(tagname);
- if (!rules)
+ if (!rules) {
return matchedDecls;
+ }
for (const auto& d : *rules) {
- if (MatchSelector(tagname, d->pSelector))
+ if (MatchSelector(tagname, d->pSelector)) {
matchedDecls.push_back(d->pDeclaration);
+ }
}
return matchedDecls;
}
@@ -70,8 +74,9 @@
// TODO(dsinclair): The code only supports a single level of selector at this
// point. None of the code using selectors required the complexity so lets
// just say we don't support them to simplify the code for now.
- if (!pSel || pSel->next_selector() || pSel->is_descendant())
+ if (!pSel || pSel->next_selector() || pSel->is_descendant()) {
return false;
+ }
return pSel->name_hash() == FX_HashCode_GetLoweredW(tagname.AsStringView());
}
@@ -84,8 +89,9 @@
if (!styleString.IsEmpty() || !alignString.IsEmpty()) {
pDecl = std::make_unique<CFX_CSSDeclaration>();
- if (!styleString.IsEmpty())
+ if (!styleString.IsEmpty()) {
AppendInlineStyle(pDecl.get(), styleString);
+ }
if (!alignString.IsEmpty()) {
pDecl->AddProperty(
CFX_CSSData::GetPropertyByEnum(CFX_CSSProperty::TextAlign),
@@ -103,20 +109,25 @@
std::vector<const CFX_CSSPropertyHolder*> normals;
std::vector<const CFX_CSSCustomProperty*> customs;
- for (auto* decl : declArray)
+ for (auto* decl : declArray) {
ExtractValues(decl, &importants, &normals, &customs);
+ }
- if (extraDecl)
+ if (extraDecl) {
ExtractValues(extraDecl, &importants, &normals, &customs);
+ }
- for (auto* prop : normals)
+ for (auto* prop : normals) {
ApplyProperty(prop->eProperty, prop->pValue, pComputedStyle);
+ }
- for (auto* prop : customs)
+ for (auto* prop : customs) {
pComputedStyle->AddCustomStyle(*prop);
+ }
- for (auto* prop : importants)
+ for (auto* prop : importants) {
ApplyProperty(prop->eProperty, prop->pValue, pComputedStyle);
+ }
}
void CFX_CSSStyleSelector::ExtractValues(
@@ -125,13 +136,15 @@
std::vector<const CFX_CSSPropertyHolder*>* normals,
std::vector<const CFX_CSSCustomProperty*>* custom) {
for (const auto& holder : *decl) {
- if (holder->bImportant)
+ if (holder->bImportant) {
importants->push_back(holder.get());
- else
+ } else {
normals->push_back(holder.get());
+ }
}
- for (auto it = decl->custom_begin(); it != decl->custom_end(); it++)
+ for (auto it = decl->custom_begin(); it != decl->custom_end(); it++) {
custom->push_back(it->get());
+ }
}
void CFX_CSSStyleSelector::AppendInlineStyle(CFX_CSSDeclaration* pDecl,
@@ -150,16 +163,18 @@
if (eStatus == CFX_CSSSyntaxParser::Status::kPropertyName) {
WideStringView strValue = pSyntax->GetCurrentString();
property = CFX_CSSData::GetPropertyByName(strValue);
- if (!property)
+ if (!property) {
wsName = WideString(strValue);
+ }
} else if (eStatus == CFX_CSSSyntaxParser::Status::kPropertyValue) {
if (property || iLen2 > 0) {
WideStringView strValue = pSyntax->GetCurrentString();
if (!strValue.IsEmpty()) {
- if (property)
+ if (property) {
pDecl->AddProperty(property, strValue);
- else if (iLen2 > 0)
+ } else if (iLen2 > 0) {
pDecl->AddProperty(wsName, WideString(strValue));
+ }
}
}
} else {
@@ -557,8 +572,9 @@
Mask<CFX_CSSTEXTDECORATION> dwDecoration;
for (const RetainPtr<CFX_CSSValue>& val :
pdfium::Reversed(pValue->values())) {
- if (val->GetType() != CFX_CSSValue::PrimitiveType::kEnum)
+ if (val->GetType() != CFX_CSSValue::PrimitiveType::kEnum) {
continue;
+ }
switch (val.AsRaw<CFX_CSSEnumValue>()->Value()) {
case CFX_CSSPropertyValue::Underline:
diff --git a/core/fxcrt/css/cfx_cssstylesheet.cpp b/core/fxcrt/css/cfx_cssstylesheet.cpp
index bddc71e..5f25eb3 100644
--- a/core/fxcrt/css/cfx_cssstylesheet.cpp
+++ b/core/fxcrt/css/cfx_cssstylesheet.cpp
@@ -30,12 +30,15 @@
auto pSyntax = std::make_unique<CFX_CSSSyntaxParser>(buffer);
while (true) {
CFX_CSSSyntaxParser::Status eStatus = pSyntax->DoSyntaxParse();
- if (eStatus == CFX_CSSSyntaxParser::Status::kStyleRule)
+ if (eStatus == CFX_CSSSyntaxParser::Status::kStyleRule) {
eStatus = LoadStyleRule(pSyntax.get());
- if (eStatus == CFX_CSSSyntaxParser::Status::kEOS)
+ }
+ if (eStatus == CFX_CSSSyntaxParser::Status::kEOS) {
return true;
- if (eStatus == CFX_CSSSyntaxParser::Status::kError)
+ }
+ if (eStatus == CFX_CSSSyntaxParser::Status::kError) {
return false;
+ }
}
}
@@ -51,15 +54,17 @@
case CFX_CSSSyntaxParser::Status::kSelector: {
WideStringView strValue = pSyntax->GetCurrentString();
auto pSelector = CFX_CSSSelector::FromString(strValue);
- if (pSelector)
+ if (pSelector) {
selectors.push_back(std::move(pSelector));
+ }
break;
}
case CFX_CSSSyntaxParser::Status::kPropertyName: {
WideStringView strValue = pSyntax->GetCurrentString();
property = CFX_CSSData::GetPropertyByName(strValue);
- if (!property)
+ if (!property) {
wsName = WideString(strValue);
+ }
break;
}
case CFX_CSSSyntaxParser::Status::kPropertyValue: {
diff --git a/core/fxcrt/css/cfx_csssyntaxparser.cpp b/core/fxcrt/css/cfx_csssyntaxparser.cpp
index a32309a..4308bb1 100644
--- a/core/fxcrt/css/cfx_csssyntaxparser.cpp
+++ b/core/fxcrt/css/cfx_csssyntaxparser.cpp
@@ -102,8 +102,9 @@
return Status::kPropertyName;
case '}':
input_.MoveNext();
- if (!RestoreMode())
+ if (!RestoreMode()) {
return Status::kError;
+ }
return Status::kDeclClose;
case '/':
@@ -148,8 +149,9 @@
break;
case Mode::kComment:
if (wch == '*' && input_.GetNextChar() == '/') {
- if (!RestoreMode())
+ if (!RestoreMode()) {
return Status::kError;
+ }
input_.MoveNext();
}
input_.MoveNext();
diff --git a/core/fxcrt/debug/alias.cc b/core/fxcrt/debug/alias.cc
index 2d51ab2..a418581 100644
--- a/core/fxcrt/debug/alias.cc
+++ b/core/fxcrt/debug/alias.cc
@@ -12,8 +12,7 @@
#pragma clang optimize off
#endif
-void Alias(const void* var) {
-}
+void Alias(const void* var) {}
#if defined(__clang__)
#pragma clang optimize on
diff --git a/core/fxcrt/fx_bidi.cpp b/core/fxcrt/fx_bidi.cpp
index 8a114ce..d292a5b 100644
--- a/core/fxcrt/fx_bidi.cpp
+++ b/core/fxcrt/fx_bidi.cpp
@@ -40,8 +40,9 @@
}
bool bChangeDirection = (direction != current_segment_.direction);
- if (bChangeDirection)
+ if (bChangeDirection) {
StartNewSegment(direction);
+ }
current_segment_.count++;
return bChangeDirection;
@@ -62,11 +63,13 @@
CFX_BidiString::CFX_BidiString(const WideString& str) : str_(str) {
CFX_BidiChar bidi;
for (wchar_t c : str_) {
- if (bidi.AppendChar(c))
+ if (bidi.AppendChar(c)) {
order_.push_back(bidi.GetSegmentInfo());
+ }
}
- if (bidi.EndChar())
+ if (bidi.EndChar()) {
order_.push_back(bidi.GetSegmentInfo());
+ }
size_t nR2L = std::count_if(
order_.begin(), order_.end(), [](const CFX_BidiChar::Segment& seg) {
@@ -78,8 +81,9 @@
return seg.direction == CFX_BidiChar::Direction::kLeft;
});
- if (nR2L > 0 && nR2L >= nL2R)
+ if (nR2L > 0 && nR2L >= nL2R) {
SetOverallDirectionRight();
+ }
}
CFX_BidiString::~CFX_BidiString() = default;
diff --git a/core/fxcrt/fx_codepage.cpp b/core/fxcrt/fx_codepage.cpp
index 82af097..e189eaa 100644
--- a/core/fxcrt/fx_codepage.cpp
+++ b/core/fxcrt/fx_codepage.cpp
@@ -238,8 +238,9 @@
FX_Charset FX_GetCharsetFromCodePage(FX_CodePage codepage) {
for (const auto& it : kFXCharset2CodePageTable) {
- if (it.codepage == codepage)
+ if (it.codepage == codepage) {
return it.charset;
+ }
}
return FX_Charset::kANSI;
}
@@ -303,8 +304,9 @@
size_t len = 0;
for (size_t i = 0; i < wstr.GetLength(); i++) {
if (wstr[i] < 0x100) {
- if (len < buf.size())
+ if (len < buf.size()) {
buf[len] = static_cast<char>(wstr[i]);
+ }
len++;
}
}
@@ -324,8 +326,9 @@
#else
size_t wlen = 0;
for (size_t i = 0; i < bstr.GetLength(); i++) {
- if (wlen < buf.size())
+ if (wlen < buf.size()) {
buf[wlen] = reinterpret_cast<uint8_t>(bstr[i]);
+ }
wlen++;
}
return wlen;
diff --git a/core/fxcrt/fx_coordinates.cpp b/core/fxcrt/fx_coordinates.cpp
index 9c6bc1a..32b52d7 100644
--- a/core/fxcrt/fx_coordinates.cpp
+++ b/core/fxcrt/fx_coordinates.cpp
@@ -68,8 +68,9 @@
template <>
void CFX_VTemplate<float>::Normalize() {
float fLen = Length();
- if (fLen < 0.0001f)
+ if (fLen < 0.0001f) {
return;
+ }
x /= fLen;
y /= fLen;
@@ -84,10 +85,12 @@
}
void FX_RECT::Normalize() {
- if (left > right)
+ if (left > right) {
std::swap(left, right);
- if (top > bottom)
+ }
+ if (top > bottom) {
std::swap(top, bottom);
+ }
}
void FX_RECT::Intersect(const FX_RECT& src) {
@@ -135,8 +138,9 @@
// static
CFX_FloatRect CFX_FloatRect::GetBBox(pdfium::span<const CFX_PointF> pPoints) {
- if (pPoints.empty())
+ if (pPoints.empty()) {
return CFX_FloatRect();
+ }
float min_x = pPoints.front().x;
float max_x = pPoints.front().x;
@@ -152,10 +156,12 @@
}
void CFX_FloatRect::Normalize() {
- if (left > right)
+ if (left > right) {
std::swap(left, right);
- if (bottom > top)
+ }
+ if (bottom > top) {
std::swap(top, bottom);
+ }
}
void CFX_FloatRect::Intersect(const CFX_FloatRect& other_rect) {
@@ -166,8 +172,9 @@
bottom = std::max(bottom, other.bottom);
right = std::min(right, other.right);
top = std::min(top, other.top);
- if (left > right || bottom > top)
+ if (left > right || bottom > top) {
*this = CFX_FloatRect();
+ }
}
void CFX_FloatRect::Union(const CFX_FloatRect& other_rect) {
@@ -277,8 +284,9 @@
}
CFX_FloatRect CFX_FloatRect::GetDeflated(float x, float y) const {
- if (IsEmpty())
+ if (IsEmpty()) {
return CFX_FloatRect();
+ }
CFX_FloatRect that = *this;
that.Deflate(x, y);
@@ -372,8 +380,9 @@
CFX_Matrix CFX_Matrix::GetInverse() const {
CFX_Matrix inverse;
float i = a * d - b * c;
- if (fabs(i) == 0)
+ if (fabs(i) == 0) {
return inverse;
+ }
float j = -i;
inverse.a = d / i;
@@ -432,18 +441,22 @@
}
float CFX_Matrix::GetXUnit() const {
- if (b == 0)
+ if (b == 0) {
return (a > 0 ? a : -a);
- if (a == 0)
+ }
+ if (a == 0) {
return (b > 0 ? b : -b);
+ }
return hypotf(a, b);
}
float CFX_Matrix::GetYUnit() const {
- if (c == 0)
+ if (c == 0) {
return (d > 0 ? d : -d);
- if (d == 0)
+ }
+ if (d == 0) {
return (c > 0 ? c : -c);
+ }
return hypotf(c, d);
}
diff --git a/core/fxcrt/fx_extension.cpp b/core/fxcrt/fx_extension.cpp
index 7b908af..ce5f074 100644
--- a/core/fxcrt/fx_extension.cpp
+++ b/core/fxcrt/fx_extension.cpp
@@ -120,8 +120,9 @@
time_t FXSYS_time(time_t* tloc) {
time_t ret_val = g_time_func();
- if (tloc)
+ if (tloc) {
*tloc = ret_val;
+ }
return ret_val;
}
diff --git a/core/fxcrt/fx_extension.h b/core/fxcrt/fx_extension.h
index 593b560..af2c932 100644
--- a/core/fxcrt/fx_extension.h
+++ b/core/fxcrt/fx_extension.h
@@ -25,7 +25,7 @@
#define FX_INVALID_OFFSET static_cast<uint32_t>(-1)
-#define FX_IsOdd(a) ((a)&1)
+#define FX_IsOdd(a) ((a) & 1)
float FXSYS_wcstof(WideStringView pwsStr, size_t* pUsedLen);
@@ -86,15 +86,17 @@
}
inline int FXSYS_HexCharToInt(char c) {
- if (!FXSYS_IsHexDigit(c))
+ if (!FXSYS_IsHexDigit(c)) {
return 0;
+ }
char upchar = FXSYS_ToUpperASCII(c);
return upchar > '9' ? upchar - 'A' + 10 : upchar - '0';
}
inline int FXSYS_WideHexCharToInt(wchar_t c) {
- if (!FXSYS_IsWideHexDigit(c))
+ if (!FXSYS_IsWideHexDigit(c)) {
return 0;
+ }
char upchar = toupper(static_cast<char>(c));
return upchar > '9' ? upchar - 'A' + 10 : upchar - '0';
}
@@ -134,10 +136,12 @@
template <typename T>
bool FXSYS_SafeLT(const T& lhs, const T& rhs) {
- if (isnan(lhs) && isnan(rhs))
+ if (isnan(lhs) && isnan(rhs)) {
return false;
- if (isnan(lhs) || isnan(rhs))
+ }
+ if (isnan(lhs) || isnan(rhs)) {
return isnan(lhs) < isnan(rhs);
+ }
return lhs < rhs;
}
diff --git a/core/fxcrt/fx_folder_posix.cpp b/core/fxcrt/fx_folder_posix.cpp
index a921128..29888e1 100644
--- a/core/fxcrt/fx_folder_posix.cpp
+++ b/core/fxcrt/fx_folder_posix.cpp
@@ -36,8 +36,9 @@
std::unique_ptr<FX_Folder> FX_Folder::OpenFolder(const ByteString& path) {
DIR* dir = opendir(path.c_str());
- if (!dir)
+ if (!dir) {
return nullptr;
+ }
// Private ctor.
return pdfium::WrapUnique(new FX_PosixFolder(path, dir));
@@ -52,13 +53,15 @@
bool FX_PosixFolder::GetNextFile(ByteString* filename, bool* bFolder) {
struct dirent* de = readdir(dir_);
- if (!de)
+ if (!de) {
return false;
+ }
ByteString fullpath = path_ + "/" + de->d_name;
struct stat deStat;
- if (stat(fullpath.c_str(), &deStat) < 0)
+ if (stat(fullpath.c_str(), &deStat) < 0) {
return false;
+ }
*filename = de->d_name;
*bFolder = S_ISDIR(deStat.st_mode);
diff --git a/core/fxcrt/fx_memory.cpp b/core/fxcrt/fx_memory.cpp
index a216ef3..e8d54f7 100644
--- a/core/fxcrt/fx_memory.cpp
+++ b/core/fxcrt/fx_memory.cpp
@@ -141,45 +141,51 @@
void* AllocOrDie(size_t num_members, size_t member_size) {
void* result = Alloc(num_members, member_size);
- if (!result)
+ if (!result) {
FX_OutOfMemoryTerminate(0); // Never returns.
+ }
return result;
}
void* AllocOrDie2D(size_t w, size_t h, size_t member_size) {
- if (w >= std::numeric_limits<size_t>::max() / h)
+ if (w >= std::numeric_limits<size_t>::max() / h) {
FX_OutOfMemoryTerminate(0); // Never returns.
+ }
return AllocOrDie(w * h, member_size);
}
void* CallocOrDie(size_t num_members, size_t member_size) {
void* result = Calloc(num_members, member_size);
- if (!result)
+ if (!result) {
FX_OutOfMemoryTerminate(0); // Never returns.
+ }
return result;
}
void* CallocOrDie2D(size_t w, size_t h, size_t member_size) {
- if (w >= std::numeric_limits<size_t>::max() / h)
+ if (w >= std::numeric_limits<size_t>::max() / h) {
FX_OutOfMemoryTerminate(0); // Never returns.
+ }
return CallocOrDie(w * h, member_size);
}
void* ReallocOrDie(void* ptr, size_t num_members, size_t member_size) {
void* result = Realloc(ptr, num_members, member_size);
- if (!result)
+ if (!result) {
FX_OutOfMemoryTerminate(0); // Never returns.
+ }
return result;
}
void* StringAllocOrDie(size_t num_members, size_t member_size) {
void* result = StringAlloc(num_members, member_size);
- if (!result)
+ if (!result) {
FX_OutOfMemoryTerminate(0); // Never returns.
+ }
return result;
}
diff --git a/core/fxcrt/fx_memory_malloc.cpp b/core/fxcrt/fx_memory_malloc.cpp
index bc958dd..28f36f0 100644
--- a/core/fxcrt/fx_memory_malloc.cpp
+++ b/core/fxcrt/fx_memory_malloc.cpp
@@ -26,24 +26,27 @@
void* Alloc(size_t num_members, size_t member_size) {
FX_SAFE_SIZE_T total = member_size;
total *= num_members;
- if (!total.IsValid() || total.ValueOrDie() >= kMallocSizeLimit)
+ if (!total.IsValid() || total.ValueOrDie() >= kMallocSizeLimit) {
return nullptr;
+ }
return malloc(total.ValueOrDie());
}
void* Calloc(size_t num_members, size_t member_size) {
FX_SAFE_SIZE_T total = member_size;
total *= num_members;
- if (!total.IsValid() || total.ValueOrDie() >= kMallocSizeLimit)
+ if (!total.IsValid() || total.ValueOrDie() >= kMallocSizeLimit) {
return nullptr;
+ }
return calloc(num_members, member_size);
}
void* Realloc(void* ptr, size_t num_members, size_t member_size) {
FX_SAFE_SIZE_T total = num_members;
total *= member_size;
- if (!total.IsValid() || total.ValueOrDie() >= kMallocSizeLimit)
+ if (!total.IsValid() || total.ValueOrDie() >= kMallocSizeLimit) {
return nullptr;
+ }
return realloc(ptr, total.ValueOrDie());
}
@@ -54,8 +57,9 @@
void* StringAlloc(size_t num_members, size_t member_size) {
FX_SAFE_SIZE_T total = member_size;
total *= num_members;
- if (!total.IsValid())
+ if (!total.IsValid()) {
return nullptr;
+ }
return malloc(total.ValueOrDie());
}
@@ -72,15 +76,17 @@
void* FX_ArrayBufferAllocate(size_t length) {
void* result = calloc(length, 1);
- if (!result)
+ if (!result) {
FX_OutOfMemoryTerminate(length);
+ }
return result;
}
void* FX_ArrayBufferAllocateUninitialized(size_t length) {
void* result = malloc(length);
- if (!result)
+ if (!result) {
FX_OutOfMemoryTerminate(length);
+ }
return result;
}
diff --git a/core/fxcrt/fx_memory_pa.cpp b/core/fxcrt/fx_memory_pa.cpp
index d7a1e72..9ecf90a 100644
--- a/core/fxcrt/fx_memory_pa.cpp
+++ b/core/fxcrt/fx_memory_pa.cpp
@@ -51,8 +51,9 @@
void* Alloc(size_t num_members, size_t member_size) {
FX_SAFE_SIZE_T total = member_size;
total *= num_members;
- if (!total.IsValid())
+ if (!total.IsValid()) {
return nullptr;
+ }
return GetGeneralPartitionAllocator()
.root()
@@ -63,8 +64,9 @@
void* Calloc(size_t num_members, size_t member_size) {
FX_SAFE_SIZE_T total = member_size;
total *= num_members;
- if (!total.IsValid())
+ if (!total.IsValid()) {
return nullptr;
+ }
return GetGeneralPartitionAllocator()
.root()
@@ -76,8 +78,9 @@
void* Realloc(void* ptr, size_t num_members, size_t member_size) {
FX_SAFE_SIZE_T size = num_members;
size *= member_size;
- if (!size.IsValid())
+ if (!size.IsValid()) {
return nullptr;
+ }
return GetGeneralPartitionAllocator()
.root()
@@ -102,8 +105,9 @@
void* StringAlloc(size_t num_members, size_t member_size) {
FX_SAFE_SIZE_T total = member_size;
total *= num_members;
- if (!total.IsValid())
+ if (!total.IsValid()) {
return nullptr;
+ }
return GetStringPartitionAllocator()
.root()
diff --git a/core/fxcrt/fx_number.cpp b/core/fxcrt/fx_number.cpp
index d2cd130..fbd60a5 100644
--- a/core/fxcrt/fx_number.cpp
+++ b/core/fxcrt/fx_number.cpp
@@ -21,8 +21,9 @@
FX_Number::FX_Number(float value) : value_(value) {}
FX_Number::FX_Number(ByteStringView strc) {
- if (strc.IsEmpty())
+ if (strc.IsEmpty()) {
return;
+ }
if (strc.Contains('.')) {
value_ = StringToFloat(strc);
@@ -65,8 +66,9 @@
static constexpr uint32_t uLimit =
static_cast<uint32_t>(std::numeric_limits<int>::max());
- if (uValue > (bNegative ? uLimit + 1 : uLimit))
+ if (uValue > (bNegative ? uLimit + 1 : uLimit)) {
uValue = 0;
+ }
// Switch back to the int space so we can flip to a negative if we need.
int32_t value = static_cast<int32_t>(uValue);
diff --git a/core/fxcrt/fx_random.cpp b/core/fxcrt/fx_random.cpp
index 26a0596..a35be66 100644
--- a/core/fxcrt/fx_random.cpp
+++ b/core/fxcrt/fx_random.cpp
@@ -72,8 +72,9 @@
void* ContextFromNextGlobalSeed() {
if (!g_bHaveGlobalSeed) {
#if BUILDFLAG(IS_WIN)
- if (!GenerateSeedFromCryptoRandom(&g_nGlobalSeed))
+ if (!GenerateSeedFromCryptoRandom(&g_nGlobalSeed)) {
g_nGlobalSeed = GenerateSeedFromEnvironment();
+ }
#else
g_nGlobalSeed = GenerateSeedFromEnvironment();
#endif
diff --git a/core/fxcrt/fx_stream.cpp b/core/fxcrt/fx_stream.cpp
index 81e0443..6e9c6b2 100644
--- a/core/fxcrt/fx_stream.cpp
+++ b/core/fxcrt/fx_stream.cpp
@@ -71,8 +71,9 @@
RetainPtr<IFX_SeekableReadStream> IFX_SeekableReadStream::CreateFromFilename(
const char* filename) {
std::unique_ptr<FileAccessIface> pFA = FileAccessIface::Create();
- if (!pFA->Open(filename))
+ if (!pFA->Open(filename)) {
return nullptr;
+ }
return pdfium::MakeRetain<CFX_CRTFileStream>(std::move(pFA));
}
diff --git a/core/fxcrt/fx_stream.h b/core/fxcrt/fx_stream.h
index 00ae0c7..6436f87 100644
--- a/core/fxcrt/fx_stream.h
+++ b/core/fxcrt/fx_stream.h
@@ -61,7 +61,6 @@
};
class IFX_SeekableStream : public IFX_SeekableReadStream,
- public IFX_SeekableWriteStream {
-};
+ public IFX_SeekableWriteStream {};
#endif // CORE_FXCRT_FX_STREAM_H_
diff --git a/core/fxcrt/fx_string.h b/core/fxcrt/fx_string.h
index 88a7afe..06ebe3a 100644
--- a/core/fxcrt/fx_string.h
+++ b/core/fxcrt/fx_string.h
@@ -41,8 +41,9 @@
StringViewTemplate<typename StrType::CharType> remaining(that.span());
while (true) {
std::optional<size_t> index = remaining.Find(ch);
- if (!index.has_value())
+ if (!index.has_value()) {
break;
+ }
result.emplace_back(remaining.First(index.value()));
remaining = remaining.Last(remaining.GetLength() - index.value() - 1);
}
diff --git a/core/fxcrt/fx_system.cpp b/core/fxcrt/fx_system.cpp
index f9b4037..d5c00af 100644
--- a/core/fxcrt/fx_system.cpp
+++ b/core/fxcrt/fx_system.cpp
@@ -22,8 +22,9 @@
template <typename IntType, typename CharType>
IntType FXSYS_StrToInt(const CharType* str) {
- if (!str)
+ if (!str) {
return 0;
+ }
// Process the sign.
bool neg = *str == '-';
@@ -98,22 +99,28 @@
} // namespace
int FXSYS_roundf(float f) {
- if (isnan(f))
+ if (isnan(f)) {
return 0;
- if (f < static_cast<float>(std::numeric_limits<int>::min()))
+ }
+ if (f < static_cast<float>(std::numeric_limits<int>::min())) {
return std::numeric_limits<int>::min();
- if (f >= static_cast<float>(std::numeric_limits<int>::max()))
+ }
+ if (f >= static_cast<float>(std::numeric_limits<int>::max())) {
return std::numeric_limits<int>::max();
+ }
return static_cast<int>(round(f));
}
int FXSYS_round(double d) {
- if (isnan(d))
+ if (isnan(d)) {
return 0;
- if (d < static_cast<double>(std::numeric_limits<int>::min()))
+ }
+ if (d < static_cast<double>(std::numeric_limits<int>::min())) {
return std::numeric_limits<int>::min();
- if (d >= static_cast<double>(std::numeric_limits<int>::max()))
+ }
+ if (d >= static_cast<double>(std::numeric_limits<int>::max())) {
return std::numeric_limits<int>::max();
+ }
return static_cast<int>(round(d));
}
diff --git a/core/fxcrt/maybe_owned.h b/core/fxcrt/maybe_owned.h
index 6f4de82..b38a1ab 100644
--- a/core/fxcrt/maybe_owned.h
+++ b/core/fxcrt/maybe_owned.h
@@ -43,8 +43,9 @@
// Helpful for untangling a collection of intertwined MaybeOwned<>.
void ResetIfUnowned() {
- if (!IsOwned())
+ if (!IsOwned()) {
Reset();
+ }
}
T* Get() const& {
diff --git a/core/fxcrt/numerics/checked_math_impl.h b/core/fxcrt/numerics/checked_math_impl.h
index c12be99..7ee488d 100644
--- a/core/fxcrt/numerics/checked_math_impl.h
+++ b/core/fxcrt/numerics/checked_math_impl.h
@@ -34,8 +34,9 @@
// that of y.
if (std::is_signed<T>::value
? static_cast<SignedDst>((uresult ^ ux) & (uresult ^ uy)) < 0
- : uresult < uy) // Unsigned is either valid or underflow.
+ : uresult < uy) { // Unsigned is either valid or underflow.
return false;
+ }
*result = static_cast<T>(uresult);
return true;
}
@@ -51,8 +52,9 @@
using result_type = typename MaxExponentPromotion<T, U>::type;
template <typename V>
static constexpr bool Do(T x, U y, V* result) {
- if constexpr (CheckedAddFastOp<T, U>::is_supported)
+ if constexpr (CheckedAddFastOp<T, U>::is_supported) {
return CheckedAddFastOp<T, U>::Do(x, y, result);
+ }
// Double the underlying type up to a full machine word.
using FastPromotion = typename FastIntegerArithmeticPromotion<T, U>::type;
@@ -76,8 +78,9 @@
is_valid = CheckedAddImpl(static_cast<Promotion>(x),
static_cast<Promotion>(y), &presult);
}
- if (!is_valid || !IsValueInRangeForNumericType<V>(presult))
+ if (!is_valid || !IsValueInRangeForNumericType<V>(presult)) {
return false;
+ }
*result = static_cast<V>(presult);
return true;
}
@@ -97,8 +100,9 @@
// the same sign.
if (std::is_signed<T>::value
? static_cast<SignedDst>((uresult ^ ux) & (ux ^ uy)) < 0
- : x < y)
+ : x < y) {
return false;
+ }
*result = static_cast<T>(uresult);
return true;
}
@@ -114,8 +118,9 @@
using result_type = typename MaxExponentPromotion<T, U>::type;
template <typename V>
static constexpr bool Do(T x, U y, V* result) {
- if constexpr (CheckedSubFastOp<T, U>::is_supported)
+ if constexpr (CheckedSubFastOp<T, U>::is_supported) {
return CheckedSubFastOp<T, U>::Do(x, y, result);
+ }
// Double the underlying type up to a full machine word.
using FastPromotion = typename FastIntegerArithmeticPromotion<T, U>::type;
@@ -139,8 +144,9 @@
is_valid = CheckedSubImpl(static_cast<Promotion>(x),
static_cast<Promotion>(y), &presult);
}
- if (!is_valid || !IsValueInRangeForNumericType<V>(presult))
+ if (!is_valid || !IsValueInRangeForNumericType<V>(presult)) {
return false;
+ }
*result = static_cast<V>(presult);
return true;
}
@@ -162,8 +168,9 @@
// After that it's an unsigned overflow check on the absolute value, with
// a +1 bound for a negative result.
if (uy > UnsignedDst(!std::is_signed<T>::value || is_negative) &&
- ux > (std::numeric_limits<T>::max() + UnsignedDst(is_negative)) / uy)
+ ux > (std::numeric_limits<T>::max() + UnsignedDst(is_negative)) / uy) {
return false;
+ }
*result = static_cast<T>(is_negative ? 0 - uresult : uresult);
return true;
}
@@ -179,8 +186,9 @@
using result_type = typename MaxExponentPromotion<T, U>::type;
template <typename V>
static constexpr bool Do(T x, U y, V* result) {
- if constexpr (CheckedMulFastOp<T, U>::is_supported)
+ if constexpr (CheckedMulFastOp<T, U>::is_supported) {
return CheckedMulFastOp<T, U>::Do(x, y, result);
+ }
using Promotion = typename FastIntegerArithmeticPromotion<T, U>::type;
// Verify the destination type can hold the result (always true for 0).
@@ -204,8 +212,9 @@
is_valid = CheckedMulImpl(static_cast<Promotion>(x),
static_cast<Promotion>(y), &presult);
}
- if (!is_valid || !IsValueInRangeForNumericType<V>(presult))
+ if (!is_valid || !IsValueInRangeForNumericType<V>(presult)) {
return false;
+ }
*result = static_cast<V>(presult);
return true;
}
@@ -224,8 +233,9 @@
using result_type = typename MaxExponentPromotion<T, U>::type;
template <typename V>
static constexpr bool Do(T x, U y, V* result) {
- if (BASE_NUMERICS_UNLIKELY(!y))
+ if (BASE_NUMERICS_UNLIKELY(!y)) {
return false;
+ }
// The overflow check can be compiled away if we don't have the exact
// combination of types needed to trigger this case.
@@ -247,8 +257,9 @@
}
const Promotion presult = Promotion(x) / Promotion(y);
- if (!IsValueInRangeForNumericType<V>(presult))
+ if (!IsValueInRangeForNumericType<V>(presult)) {
return false;
+ }
*result = static_cast<V>(presult);
return true;
}
@@ -265,8 +276,9 @@
using result_type = typename MaxExponentPromotion<T, U>::type;
template <typename V>
static constexpr bool Do(T x, U y, V* result) {
- if (BASE_NUMERICS_UNLIKELY(!y))
+ if (BASE_NUMERICS_UNLIKELY(!y)) {
return false;
+ }
using Promotion = typename BigEnoughPromotion<T, U>::type;
if (BASE_NUMERICS_UNLIKELY(
@@ -281,8 +293,9 @@
const Promotion presult =
static_cast<Promotion>(x) % static_cast<Promotion>(y);
- if (!IsValueInRangeForNumericType<V>(presult))
+ if (!IsValueInRangeForNumericType<V>(presult)) {
return false;
+ }
*result = static_cast<Promotion>(presult);
return true;
}
@@ -314,8 +327,9 @@
// Handle the legal corner-case of a full-width signed shift of zero.
if (!std::is_signed<T>::value || x ||
- as_unsigned(shift) != as_unsigned(std::numeric_limits<T>::digits))
+ as_unsigned(shift) != as_unsigned(std::numeric_limits<T>::digits)) {
return false;
+ }
*result = 0;
return true;
}
@@ -342,8 +356,9 @@
}
const T tmp = x >> shift;
- if (!IsValueInRangeForNumericType<V>(tmp))
+ if (!IsValueInRangeForNumericType<V>(tmp)) {
return false;
+ }
*result = static_cast<V>(tmp);
return true;
}
@@ -364,8 +379,9 @@
static constexpr bool Do(T x, U y, V* result) {
const result_type tmp =
static_cast<result_type>(x) & static_cast<result_type>(y);
- if (!IsValueInRangeForNumericType<V>(tmp))
+ if (!IsValueInRangeForNumericType<V>(tmp)) {
return false;
+ }
*result = static_cast<V>(tmp);
return true;
}
@@ -386,8 +402,9 @@
static constexpr bool Do(T x, U y, V* result) {
const result_type tmp =
static_cast<result_type>(x) | static_cast<result_type>(y);
- if (!IsValueInRangeForNumericType<V>(tmp))
+ if (!IsValueInRangeForNumericType<V>(tmp)) {
return false;
+ }
*result = static_cast<V>(tmp);
return true;
}
@@ -408,8 +425,9 @@
static constexpr bool Do(T x, U y, V* result) {
const result_type tmp =
static_cast<result_type>(x) ^ static_cast<result_type>(y);
- if (!IsValueInRangeForNumericType<V>(tmp))
+ if (!IsValueInRangeForNumericType<V>(tmp)) {
return false;
+ }
*result = static_cast<V>(tmp);
return true;
}
@@ -432,8 +450,9 @@
const result_type tmp = IsGreater<T, U>::Test(x, y)
? static_cast<result_type>(x)
: static_cast<result_type>(y);
- if (!IsValueInRangeForNumericType<V>(tmp))
+ if (!IsValueInRangeForNumericType<V>(tmp)) {
return false;
+ }
*result = static_cast<V>(tmp);
return true;
}
@@ -456,8 +475,9 @@
const result_type tmp = IsLess<T, U>::Test(x, y)
? static_cast<result_type>(x)
: static_cast<result_type>(y);
- if (!IsValueInRangeForNumericType<V>(tmp))
+ if (!IsValueInRangeForNumericType<V>(tmp)) {
return false;
+ }
*result = static_cast<V>(tmp);
return true;
}
diff --git a/core/fxcrt/numerics/clamped_math_impl.h b/core/fxcrt/numerics/clamped_math_impl.h
index be9f908..75ca8c6 100644
--- a/core/fxcrt/numerics/clamped_math_impl.h
+++ b/core/fxcrt/numerics/clamped_math_impl.h
@@ -80,8 +80,9 @@
using result_type = typename MaxExponentPromotion<T, U>::type;
template <typename V = result_type>
static constexpr V Do(T x, U y) {
- if (!IsConstantEvaluated() && ClampedAddFastOp<T, U>::is_supported)
+ if (!IsConstantEvaluated() && ClampedAddFastOp<T, U>::is_supported) {
return ClampedAddFastOp<T, U>::template Do<V>(x, y);
+ }
static_assert(std::is_same<V, result_type>::value ||
IsTypeInRangeForNumericType<U, V>::value,
@@ -106,8 +107,9 @@
using result_type = typename MaxExponentPromotion<T, U>::type;
template <typename V = result_type>
static constexpr V Do(T x, U y) {
- if (!IsConstantEvaluated() && ClampedSubFastOp<T, U>::is_supported)
+ if (!IsConstantEvaluated() && ClampedSubFastOp<T, U>::is_supported) {
return ClampedSubFastOp<T, U>::template Do<V>(x, y);
+ }
static_assert(std::is_same<V, result_type>::value ||
IsTypeInRangeForNumericType<U, V>::value,
@@ -132,8 +134,9 @@
using result_type = typename MaxExponentPromotion<T, U>::type;
template <typename V = result_type>
static constexpr V Do(T x, U y) {
- if (!IsConstantEvaluated() && ClampedMulFastOp<T, U>::is_supported)
+ if (!IsConstantEvaluated() && ClampedMulFastOp<T, U>::is_supported) {
return ClampedMulFastOp<T, U>::template Do<V>(x, y);
+ }
V result = {};
const V saturated =
@@ -156,8 +159,9 @@
template <typename V = result_type>
static constexpr V Do(T x, U y) {
V result = {};
- if (BASE_NUMERICS_LIKELY((CheckedDivOp<T, U>::Do(x, y, &result))))
+ if (BASE_NUMERICS_LIKELY((CheckedDivOp<T, U>::Do(x, y, &result)))) {
return result;
+ }
// Saturation goes to max, min, or NaN (if x is zero).
return x ? CommonMaxOrMin<V>(IsValueNegative(x) ^ IsValueNegative(y))
: SaturationDefaultLimits<V>::NaN();
@@ -200,8 +204,9 @@
// Shift as unsigned to avoid undefined behavior.
V result = static_cast<V>(as_unsigned(x) << shift);
// If the shift can be reversed, we know it was valid.
- if (BASE_NUMERICS_LIKELY(result >> shift == x))
+ if (BASE_NUMERICS_LIKELY(result >> shift == x)) {
return result;
+ }
}
return x ? CommonMaxOrMin<V>(IsValueNegative(x)) : 0;
}
diff --git a/core/fxcrt/numerics/safe_conversions_impl.h b/core/fxcrt/numerics/safe_conversions_impl.h
index 1b717ca..4dae1ed 100644
--- a/core/fxcrt/numerics/safe_conversions_impl.h
+++ b/core/fxcrt/numerics/safe_conversions_impl.h
@@ -266,8 +266,7 @@
template <typename Dst,
typename Src,
- template <typename>
- class Bounds,
+ template <typename> class Bounds,
IntegerRepresentation DstSign = std::is_signed<Dst>::value
? INTEGER_REPRESENTATION_SIGNED
: INTEGER_REPRESENTATION_UNSIGNED,
@@ -285,8 +284,7 @@
// Same sign narrowing: The range is contained for normal limits.
template <typename Dst,
typename Src,
- template <typename>
- class Bounds,
+ template <typename> class Bounds,
IntegerRepresentation DstSign,
IntegerRepresentation SrcSign>
struct DstRangeRelationToSrcRangeImpl<Dst,
@@ -495,16 +493,16 @@
typename Lhs,
typename Rhs = Lhs,
bool is_intmax_type =
- std::is_integral<typename MaxExponentPromotion<Lhs, Rhs>::type>::value&&
- IntegerBitsPlusSign<typename MaxExponentPromotion<Lhs, Rhs>::type>::
+ std::is_integral<
+ typename MaxExponentPromotion<Lhs, Rhs>::type>::value &&
+ IntegerBitsPlusSign<typename MaxExponentPromotion<Lhs, Rhs>::type>::
value == IntegerBitsPlusSign<intmax_t>::value,
- bool is_max_exponent =
- StaticDstRangeRelationToSrcRange<
- typename MaxExponentPromotion<Lhs, Rhs>::type,
- Lhs>::value ==
- NUMERIC_RANGE_CONTAINED&& StaticDstRangeRelationToSrcRange<
- typename MaxExponentPromotion<Lhs, Rhs>::type,
- Rhs>::value == NUMERIC_RANGE_CONTAINED>
+ bool is_max_exponent = StaticDstRangeRelationToSrcRange<
+ typename MaxExponentPromotion<Lhs, Rhs>::type,
+ Lhs>::value == NUMERIC_RANGE_CONTAINED &&
+ StaticDstRangeRelationToSrcRange<
+ typename MaxExponentPromotion<Lhs, Rhs>::type,
+ Rhs>::value == NUMERIC_RANGE_CONTAINED>
struct BigEnoughPromotion;
// The side with the max exponent is big enough.
diff --git a/core/fxcrt/numerics/safe_math_arm_impl.h b/core/fxcrt/numerics/safe_math_arm_impl.h
index 9a13a63..f2d83cb 100644
--- a/core/fxcrt/numerics/safe_math_arm_impl.h
+++ b/core/fxcrt/numerics/safe_math_arm_impl.h
@@ -36,8 +36,9 @@
Promotion presult;
presult = static_cast<Promotion>(x) * static_cast<Promotion>(y);
- if (!IsValueInRangeForNumericType<V>(presult))
+ if (!IsValueInRangeForNumericType<V>(presult)) {
return false;
+ }
*result = static_cast<V>(presult);
return true;
}
@@ -55,8 +56,9 @@
__attribute__((always_inline)) static V Do(T x, U y) {
// This will get promoted to an int, so let the compiler do whatever is
// clever and rely on the saturated cast to bounds check.
- if (IsIntegerArithmeticSafe<int, T, U>::value)
+ if (IsIntegerArithmeticSafe<int, T, U>::value) {
return saturated_cast<V>(static_cast<int>(x) + static_cast<int>(y));
+ }
int32_t result;
int32_t x_i32 = checked_cast<int32_t>(x);
@@ -81,8 +83,9 @@
__attribute__((always_inline)) static V Do(T x, U y) {
// This will get promoted to an int, so let the compiler do whatever is
// clever and rely on the saturated cast to bounds check.
- if (IsIntegerArithmeticSafe<int, T, U>::value)
+ if (IsIntegerArithmeticSafe<int, T, U>::value) {
return saturated_cast<V>(static_cast<int>(x) - static_cast<int>(y));
+ }
int32_t result;
int32_t x_i32 = checked_cast<int32_t>(x);
diff --git a/core/fxcrt/retain_ptr.h b/core/fxcrt/retain_ptr.h
index 3a053f5..0ee6e4a 100644
--- a/core/fxcrt/retain_ptr.h
+++ b/core/fxcrt/retain_ptr.h
@@ -71,8 +71,9 @@
// Copy-assign a RetainPtr.
// Required in addition to copy conversion assignment below.
RetainPtr& operator=(const RetainPtr& that) {
- if (*this != that)
+ if (*this != that) {
Reset(that.Get());
+ }
return *this;
}
@@ -88,8 +89,9 @@
typename = typename std::enable_if<
std::is_convertible<U*, T*>::value>::type>
RetainPtr& operator=(const RetainPtr<U>& that) {
- if (*this != that)
+ if (*this != that) {
Reset(that.Get());
+ }
return *this;
}
@@ -115,8 +117,9 @@
}
void Reset(T* obj = nullptr) {
- if (obj)
+ if (obj) {
obj->Retain();
+ }
obj_.reset(obj);
}
diff --git a/core/fxcrt/shared_copy_on_write.h b/core/fxcrt/shared_copy_on_write.h
index 1ae964a..87f6ab4 100644
--- a/core/fxcrt/shared_copy_on_write.h
+++ b/core/fxcrt/shared_copy_on_write.h
@@ -31,8 +31,9 @@
}
SharedCopyOnWrite& operator=(const SharedCopyOnWrite& that) {
- if (*this != that)
+ if (*this != that) {
object_ = that.object_;
+ }
return *this;
}
diff --git a/core/fxcrt/span.h b/core/fxcrt/span.h
index 604b001..ae24e4a 100644
--- a/core/fxcrt/span.h
+++ b/core/fxcrt/span.h
@@ -57,8 +57,8 @@
template <typename Container, typename T>
using ContainerHasConvertibleData =
- IsLegalSpanConversion<typename std::remove_pointer<decltype(
- std::declval<Container>().data())>::type,
+ IsLegalSpanConversion<typename std::remove_pointer<
+ decltype(std::declval<Container>().data())>::type,
T>;
template <typename Container>
using ContainerHasIntegralSize =
diff --git a/core/fxcrt/string_view_template.h b/core/fxcrt/string_view_template.h
index 8d10b02..07cd2c7 100644
--- a/core/fxcrt/string_view_template.h
+++ b/core/fxcrt/string_view_template.h
@@ -132,34 +132,40 @@
bool IsASCII() const {
for (auto c : *this) {
- if (c <= 0 || c > 127) // Questionable signedness of |c|.
+ if (c <= 0 || c > 127) { // Questionable signedness of |c|.
return false;
+ }
}
return true;
}
bool EqualsASCII(const StringViewTemplate<char>& that) const {
size_t length = GetLength();
- if (length != that.GetLength())
+ if (length != that.GetLength()) {
return false;
+ }
for (size_t i = 0; i < length; ++i) {
auto c = (*this)[i];
- if (c <= 0 || c > 127 || c != that[i]) // Questionable signedness of |c|.
+ if (c <= 0 || c > 127 ||
+ c != that[i]) { // Questionable signedness of |c|.
return false;
+ }
}
return true;
}
bool EqualsASCIINoCase(const StringViewTemplate<char>& that) const {
size_t length = GetLength();
- if (length != that.GetLength())
+ if (length != that.GetLength()) {
return false;
+ }
for (size_t i = 0; i < length; ++i) {
auto c = (*this)[i];
- if (c <= 0 || c > 127 || tolower(c) != tolower(that[i]))
+ if (c <= 0 || c > 127 || tolower(c) != tolower(that[i])) {
return false;
+ }
}
return true;
}
@@ -171,8 +177,9 @@
uint32_t strid = 0;
size_t size = std::min(static_cast<size_t>(4), span_.size());
- for (size_t i = 0; i < size; i++)
+ for (size_t i = 0; i < size; i++) {
strid = strid * 256 + span_[i];
+ }
return strid << ((4 - size) * 8);
}
@@ -230,22 +237,23 @@
return StringViewTemplate();
}
- if (!IsValidIndex(first))
+ if (!IsValidIndex(first)) {
return StringViewTemplate();
+ }
- if (count == 0 || !IsValidLength(count))
+ if (count == 0 || !IsValidLength(count)) {
return StringViewTemplate();
+ }
- if (!IsValidIndex(first + count - 1))
+ if (!IsValidIndex(first + count - 1)) {
return StringViewTemplate();
+ }
// SAFETY: performance-sensitive, checks above equivalent to subspan()'s.
return UNSAFE_BUFFERS(StringViewTemplate(span_.data() + first, count));
}
- StringViewTemplate First(size_t count) const {
- return Substr(0, count);
- }
+ StringViewTemplate First(size_t count) const { return Substr(0, count); }
StringViewTemplate Last(size_t count) const {
// Unsigned underflow is well-defined and out-of-range is handled by
@@ -254,15 +262,18 @@
}
StringViewTemplate TrimmedRight(CharType ch) const {
- if (IsEmpty())
+ if (IsEmpty()) {
return StringViewTemplate();
+ }
size_t pos = GetLength();
- while (pos && CharAt(pos - 1) == ch)
+ while (pos && CharAt(pos - 1) == ch) {
pos--;
+ }
- if (pos == 0)
+ if (pos == 0) {
return StringViewTemplate();
+ }
// SAFETY: Loop above keeps `pos` at length of string or less.
return UNSAFE_BUFFERS(StringViewTemplate(span_.data(), pos));
diff --git a/core/fxcrt/template_util.h b/core/fxcrt/template_util.h
index 876c88e..a6abcb0 100644
--- a/core/fxcrt/template_util.h
+++ b/core/fxcrt/template_util.h
@@ -15,9 +15,12 @@
namespace pdfium {
-template <class T> struct is_non_const_reference : std::false_type {};
-template <class T> struct is_non_const_reference<T&> : std::true_type {};
-template <class T> struct is_non_const_reference<const T&> : std::false_type {};
+template <class T>
+struct is_non_const_reference : std::false_type {};
+template <class T>
+struct is_non_const_reference<T&> : std::true_type {};
+template <class T>
+struct is_non_const_reference<const T&> : std::false_type {};
namespace internal {
diff --git a/core/fxcrt/tree_node.h b/core/fxcrt/tree_node.h
index eb0e257..adcb064 100644
--- a/core/fxcrt/tree_node.h
+++ b/core/fxcrt/tree_node.h
@@ -41,8 +41,9 @@
}
T* GetNthChild(int32_t n) {
- if (n < 0)
+ if (n < 0) {
return nullptr;
+ }
T* result = GetFirstChild();
while (n-- && result) {
result = result->GetNextSibling();
@@ -134,13 +135,15 @@
}
void RemoveAllChildren() {
- while (T* child = GetFirstChild())
+ while (T* child = GetFirstChild()) {
RemoveChild(child);
+ }
}
void RemoveSelfIfParented() {
- if (T* parent = GetParent())
+ if (T* parent = GetParent()) {
parent->RemoveChild(static_cast<T*>(this));
+ }
}
private:
@@ -165,8 +168,9 @@
// Child left in state where sibling members need subsequent adjustment.
void BecomeParent(T* child) {
CHECK(child != this); // Detect attempts at self-insertion.
- if (child->m_pParent)
+ if (child->m_pParent) {
child->m_pParent->TreeNodeBase<T>::RemoveChild(child);
+ }
child->m_pParent = static_cast<T*>(this);
CHECK(!child->m_pNextSibling);
CHECK(!child->m_pPrevSibling);
diff --git a/core/fxcrt/weak_ptr.h b/core/fxcrt/weak_ptr.h
index b13d5a0..d09b13d 100644
--- a/core/fxcrt/weak_ptr.h
+++ b/core/fxcrt/weak_ptr.h
@@ -59,8 +59,8 @@
explicit Handle(std::unique_ptr<T, D> ptr) : obj_(std::move(ptr)) {}
void Reset(std::unique_ptr<T, D> ptr) { obj_ = std::move(ptr); }
- void Clear() { // Now you're all weak ptrs ...
- obj_.reset(); // unique_ptr nulls first before invoking delete.
+ void Clear() { // Now you're all weak ptrs ...
+ obj_.reset(); // unique_ptr nulls first before invoking delete.
}
T* Get() const { return obj_.get(); }
T* Retain() {
diff --git a/core/fxcrt/widestring.cpp b/core/fxcrt/widestring.cpp
index 1b3e02c..e13ef5d 100644
--- a/core/fxcrt/widestring.cpp
+++ b/core/fxcrt/widestring.cpp
@@ -265,8 +265,9 @@
std::optional<WideString> TryVSWPrintf(size_t size,
const wchar_t* pFormat,
va_list argList) {
- if (!size)
+ if (!size) {
return std::nullopt;
+ }
WideString str;
{
@@ -283,8 +284,9 @@
FXSYS_memset(buffer.data(), 0, (size + 1) * sizeof(wchar_t)));
int ret = UNSAFE_TODO(vswprintf(buffer.data(), size + 1, pFormat, argList));
bool bSufficientBuffer = ret >= 0 || buffer[size - 1] == 0;
- if (!bSufficientBuffer)
+ if (!bSufficientBuffer) {
return std::nullopt;
+ }
}
str.ReleaseBuffer(str.GetStringLength());
return str;
@@ -382,8 +384,9 @@
std::optional<WideString> ret =
TryVSWPrintf(static_cast<size_t>(maxLen), format, argListCopy);
va_end(argListCopy);
- if (ret.has_value())
+ if (ret.has_value()) {
return ret.value();
+ }
maxLen *= 2;
}
@@ -426,8 +429,9 @@
nSafeLen += str2.GetLength();
size_t nNewLen = nSafeLen.ValueOrDie();
- if (nNewLen == 0)
+ if (nNewLen == 0) {
return;
+ }
data_ = StringData::Create(nNewLen);
data_->CopyContents(str1.span());
@@ -436,12 +440,14 @@
WideString::WideString(const std::initializer_list<WideStringView>& list) {
FX_SAFE_SIZE_T nSafeLen = 0;
- for (const auto& item : list)
+ for (const auto& item : list) {
nSafeLen += item.GetLength();
+ }
size_t nNewLen = nSafeLen.ValueOrDie();
- if (nNewLen == 0)
+ if (nNewLen == 0) {
return;
+ }
data_ = StringData::Create(nNewLen);
@@ -464,10 +470,11 @@
}
WideString& WideString::operator=(WideStringView str) {
- if (str.IsEmpty())
+ if (str.IsEmpty()) {
clear();
- else
+ } else {
AssignCopy(str.unterminated_c_str(), str.GetLength());
+ }
return *this;
}
@@ -511,8 +518,9 @@
}
WideString& WideString::operator+=(WideStringView str) {
- if (!str.IsEmpty())
+ if (!str.IsEmpty()) {
Concat(str.unterminated_c_str(), str.GetLength());
+ }
return *this;
}
@@ -551,11 +559,13 @@
return true;
}
- if (IsEmpty())
+ if (IsEmpty()) {
return other.IsEmpty();
+ }
- if (other.IsEmpty())
+ if (other.IsEmpty()) {
return false;
+ }
// SAFETY: data_length_ bytes available at string_.
return other.data_->data_length_ == data_->data_length_ &&
@@ -571,8 +581,9 @@
if (!data_ && !str.unterminated_c_str()) {
return false;
}
- if (c_str() == str.unterminated_c_str())
+ if (c_str() == str.unterminated_c_str()) {
return false;
+ }
size_t len = GetLength();
size_t other_len = str.GetLength();
@@ -594,24 +605,27 @@
ByteString WideString::ToASCII() const {
ByteString result;
result.Reserve(GetLength());
- for (wchar_t wc : *this)
+ for (wchar_t wc : *this) {
result.InsertAtBack(static_cast<char>(wc & 0x7f));
+ }
return result;
}
ByteString WideString::ToLatin1() const {
ByteString result;
result.Reserve(GetLength());
- for (wchar_t wc : *this)
+ for (wchar_t wc : *this) {
result.InsertAtBack(static_cast<char>(wc & 0xff));
+ }
return result;
}
ByteString WideString::ToDefANSI() const {
size_t dest_len =
FX_WideCharToMultiByte(FX_CodePage::kDefANSI, AsStringView(), {});
- if (!dest_len)
+ if (!dest_len) {
return ByteString();
+ }
ByteString bstr;
{
@@ -706,16 +720,18 @@
}
void WideString::MakeLower() {
- if (IsEmpty())
+ if (IsEmpty()) {
return;
+ }
ReallocBeforeWrite(data_->data_length_);
FXSYS_wcslwr(data_->string_);
}
void WideString::MakeUpper() {
- if (IsEmpty())
+ if (IsEmpty()) {
return;
+ }
ReallocBeforeWrite(data_->data_length_);
FXSYS_wcsupr(data_->string_);
@@ -725,8 +741,9 @@
WideString WideString::FromASCII(ByteStringView bstr) {
WideString result;
result.Reserve(bstr.GetLength());
- for (char c : bstr)
+ for (char c : bstr) {
result.InsertAtBack(static_cast<wchar_t>(c & 0x7f));
+ }
return result;
}
@@ -734,16 +751,18 @@
WideString WideString::FromLatin1(ByteStringView bstr) {
WideString result;
result.Reserve(bstr.GetLength());
- for (char c : bstr)
+ for (char c : bstr) {
result.InsertAtBack(static_cast<wchar_t>(c & 0xff));
+ }
return result;
}
// static
WideString WideString::FromDefANSI(ByteStringView bstr) {
size_t dest_len = FX_MultiByteToWideChar(FX_CodePage::kDefANSI, bstr, {});
- if (!dest_len)
+ if (!dest_len) {
return WideString();
+ }
WideString wstr;
{
@@ -829,10 +848,12 @@
// SAFTEY: Comparison limited to minimum length of either argument.
int result = UNSAFE_BUFFERS(
FXSYS_wmemcmp(data_->string_, str.data_->string_, min_len));
- if (result != 0)
+ if (result != 0) {
return result;
- if (this_len == that_len)
+ }
+ if (this_len == that_len) {
return 0;
+ }
return this_len < that_len ? -1 : 1;
}
@@ -881,14 +902,16 @@
uint32_t FX_HashCode_GetW(WideStringView str) {
uint32_t dwHashCode = 0;
- for (WideStringView::UnsignedType c : str)
+ for (WideStringView::UnsignedType c : str) {
dwHashCode = 1313 * dwHashCode + c;
+ }
return dwHashCode;
}
uint32_t FX_HashCode_GetLoweredW(WideStringView str) {
uint32_t dwHashCode = 0;
- for (wchar_t c : str) // match FXSYS_towlower() arg type.
+ for (wchar_t c : str) { // match FXSYS_towlower() arg type.
dwHashCode = 1313 * dwHashCode + FXSYS_towlower(c);
+ }
return dwHashCode;
}
diff --git a/core/fxcrt/widetext_buffer.cpp b/core/fxcrt/widetext_buffer.cpp
index 1129ebd..ec73831 100644
--- a/core/fxcrt/widetext_buffer.cpp
+++ b/core/fxcrt/widetext_buffer.cpp
@@ -46,8 +46,9 @@
WideTextBuffer& WideTextBuffer::operator<<(ByteStringView ascii) {
pdfium::span<wchar_t> new_span = ExpandWideBuf(ascii.GetLength());
- for (size_t i = 0; i < ascii.GetLength(); ++i)
+ for (size_t i = 0; i < ascii.GetLength(); ++i) {
new_span[i] = ascii[i];
+ }
return *this;
}
diff --git a/core/fxcrt/win/win_util.cc b/core/fxcrt/win/win_util.cc
index 43e9151..10ee9d0 100644
--- a/core/fxcrt/win/win_util.cc
+++ b/core/fxcrt/win/win_util.cc
@@ -4,7 +4,8 @@
#include "core/fxcrt/win/win_util.h"
-#include <windows.h>
+#include <windows.h> // Must come before processthreadsapi.h
+
#include <processthreadsapi.h>
namespace pdfium {
@@ -13,14 +14,15 @@
static auto is_user32_and_gdi32_available = []() {
// If win32k syscalls aren't disabled, then user32 and gdi32 are available.
- typedef decltype(
- GetProcessMitigationPolicy)* GetProcessMitigationPolicyType;
+ typedef decltype(GetProcessMitigationPolicy)*
+ GetProcessMitigationPolicyType;
GetProcessMitigationPolicyType get_process_mitigation_policy_func =
reinterpret_cast<GetProcessMitigationPolicyType>(GetProcAddress(
GetModuleHandle(L"kernel32.dll"), "GetProcessMitigationPolicy"));
- if (!get_process_mitigation_policy_func)
+ if (!get_process_mitigation_policy_func) {
return true;
+ }
PROCESS_MITIGATION_SYSTEM_CALL_DISABLE_POLICY policy = {};
if (get_process_mitigation_policy_func(GetCurrentProcess(),
diff --git a/core/fxcrt/xml/cfx_xmlelement.cpp b/core/fxcrt/xml/cfx_xmlelement.cpp
index 2b58003..185bd93 100644
--- a/core/fxcrt/xml/cfx_xmlelement.cpp
+++ b/core/fxcrt/xml/cfx_xmlelement.cpp
@@ -30,8 +30,9 @@
// text nodes?
for (CFX_XMLNode* pChild = GetFirstChild(); pChild;
pChild = pChild->GetNextSibling()) {
- if (pChild->GetType() == Type::kText)
+ if (pChild->GetType() == Type::kText) {
node->AppendLastChild(pChild->Clone(doc));
+ }
}
return node;
}
@@ -71,8 +72,9 @@
for (CFX_XMLNode* pChild = GetFirstChild(); pChild;
pChild = pChild->GetNextSibling()) {
CFX_XMLText* pText = ToXMLText(pChild);
- if (pText)
+ if (pText) {
buffer += pText->GetText();
+ }
}
return buffer;
}
@@ -115,10 +117,12 @@
size_t idx) const {
for (auto* child = GetFirstChild(); child; child = child->GetNextSibling()) {
CFX_XMLElement* elem = ToXMLElement(child);
- if (!elem || elem->name_ != name)
+ if (!elem || elem->name_ != name) {
continue;
- if (idx == 0)
+ }
+ if (idx == 0) {
return elem;
+ }
--idx;
}
diff --git a/core/fxcrt/xml/cfx_xmlnode.cpp b/core/fxcrt/xml/cfx_xmlnode.cpp
index 4ce2a60..c7a4f66 100644
--- a/core/fxcrt/xml/cfx_xmlnode.cpp
+++ b/core/fxcrt/xml/cfx_xmlnode.cpp
@@ -16,8 +16,9 @@
CFX_XMLNode* CFX_XMLNode::GetRoot() {
CFX_XMLNode* pParent = this;
- while (pParent->GetParent())
+ while (pParent->GetParent()) {
pParent = pParent->GetParent();
+ }
return pParent;
}
diff --git a/core/fxcrt/xml/cfx_xmlparser.cpp b/core/fxcrt/xml/cfx_xmlparser.cpp
index 9ae1a64..8a23786 100644
--- a/core/fxcrt/xml/cfx_xmlparser.cpp
+++ b/core/fxcrt/xml/cfx_xmlparser.cpp
@@ -94,13 +94,15 @@
}
bool CFX_XMLParser::DoSyntaxParse(CFX_XMLDocument* doc) {
- if (xml_plane_size_ <= 0)
+ if (xml_plane_size_ <= 0) {
return false;
+ }
FX_SAFE_SIZE_T alloc_size_safe = xml_plane_size_;
alloc_size_safe += 1; // For NUL.
- if (!alloc_size_safe.IsValid())
+ if (!alloc_size_safe.IsValid()) {
return false;
+ }
size_t current_buffer_idx = 0;
size_t buffer_size = 0;
@@ -117,13 +119,15 @@
while (true) {
if (current_buffer_idx >= buffer_size) {
- if (stream_->IsEOF())
+ if (stream_->IsEOF()) {
return true;
+ }
size_t buffer_chars =
stream_->ReadBlock(pdfium::make_span(buffer).first(xml_plane_size_));
- if (buffer_chars == 0)
+ if (buffer_chars == 0) {
return true;
+ }
current_buffer_idx = 0;
buffer_size = buffer_chars;
@@ -144,8 +148,9 @@
} else {
// Fail if there is text outside of the root element, ignore
// whitespace/null.
- if (node_type_stack.empty() && ch && !FXSYS_iswspace(ch))
+ if (node_type_stack.empty() && ch && !FXSYS_iswspace(ch)) {
return false;
+ }
ProcessTextChar(ch);
current_buffer_idx++;
}
@@ -271,16 +276,18 @@
break;
case FDE_XmlSyntaxState::AttriValue:
if (ch == current_quote_character) {
- if (entity_start_.has_value())
+ if (entity_start_.has_value()) {
return false;
+ }
current_quote_character = 0;
current_buffer_idx++;
current_parser_state = FDE_XmlSyntaxState::AttriName;
CFX_XMLElement* elem = ToXMLElement(current_node_);
- if (elem)
+ if (elem) {
elem->SetAttribute(current_attribute_name, GetTextData());
+ }
current_attribute_name.clear();
} else {
@@ -296,15 +303,17 @@
ProcessTargetData();
} else {
current_buffer_idx++;
- if (node_type_stack.empty())
+ if (node_type_stack.empty()) {
return false;
+ }
node_type_stack.pop();
current_parser_state = FDE_XmlSyntaxState::Text;
if (current_node_ &&
- current_node_->GetType() == CFX_XMLNode::Type::kInstruction)
+ current_node_->GetType() == CFX_XMLNode::Type::kInstruction) {
current_node_ = current_node_->GetParent();
+ }
}
break;
case FDE_XmlSyntaxState::BreakElement:
@@ -320,15 +329,17 @@
case FDE_XmlSyntaxState::CloseElement:
if (!IsXMLNameChar(ch, current_text_.IsEmpty())) {
if (ch == L'>') {
- if (node_type_stack.empty())
+ if (node_type_stack.empty()) {
return false;
+ }
node_type_stack.pop();
current_parser_state = FDE_XmlSyntaxState::Text;
CFX_XMLElement* element = ToXMLElement(current_node_);
- if (!element)
+ if (!element) {
return false;
+ }
WideString element_name = GetTextData();
if (element_name.GetLength() > 0 &&
@@ -379,14 +390,16 @@
if (current_character_to_skip_to == L'\'' ||
current_character_to_skip_to == L'\"') {
current_buffer_idx++;
- if (ch != current_character_to_skip_to)
+ if (ch != current_character_to_skip_to) {
break;
+ }
character_to_skip_too_stack.pop();
- if (character_to_skip_too_stack.empty())
+ if (character_to_skip_too_stack.empty()) {
current_parser_state = FDE_XmlSyntaxState::Text;
- else
+ } else {
current_character_to_skip_to = character_to_skip_too_stack.top();
+ }
} else {
switch (ch) {
case L'<':
@@ -492,23 +505,27 @@
uint32_t ch = 0;
if (iLen > 1 && csEntity[1] == L'x') {
for (size_t i = 2; i < iLen; i++) {
- if (!FXSYS_IsHexDigit(csEntity[i]))
+ if (!FXSYS_IsHexDigit(csEntity[i])) {
break;
+ }
ch = (ch << 4) + FXSYS_HexCharToInt(csEntity[i]);
}
} else {
for (size_t i = 1; i < iLen; i++) {
- if (!FXSYS_IsDecimalDigit(csEntity[i]))
+ if (!FXSYS_IsDecimalDigit(csEntity[i])) {
break;
+ }
ch = ch * 10 + FXSYS_DecimalCharToInt(csEntity[i]);
}
}
- if (ch > kMaxCharRange)
+ if (ch > kMaxCharRange) {
ch = ' ';
+ }
character = static_cast<wchar_t>(ch);
- if (character != 0)
+ if (character != 0) {
current_text_ += character;
+ }
} else {
if (csEntity.EqualsASCII("amp")) {
current_text_ += L'&';
@@ -531,12 +548,14 @@
void CFX_XMLParser::ProcessTargetData() {
WideString target_data = GetTextData();
- if (target_data.IsEmpty())
+ if (target_data.IsEmpty()) {
return;
+ }
CFX_XMLInstruction* instruction = ToXMLInstruction(current_node_);
- if (instruction)
+ if (instruction) {
instruction->AppendData(target_data);
+ }
}
WideString CFX_XMLParser::GetTextData() {