Avoid logical operations with {Byte,Wide}String::Compare()
The code is correct, but it is too easy to get this wrong when
mapping the expected 1/0/-1 result into a bool, so use explicit
comparisons against 0.
Change-Id: Ibed1d76e299744fa3e7a008fe5f242ee1c26f956
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/79871
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/fpdfsdk/fpdf_editpage.cpp b/fpdfsdk/fpdf_editpage.cpp
index 8441c09..7c7f2c6 100644
--- a/fpdfsdk/fpdf_editpage.cpp
+++ b/fpdfsdk/fpdf_editpage.cpp
@@ -64,7 +64,7 @@
return false;
const CPDF_Object* pObject = pFormDict->GetObjectFor("Type")->GetDirect();
- return pObject && !pObject->GetString().Compare("Page");
+ return pObject && pObject->GetString().Compare("Page") == 0;
}
void CalcBoundingBox(CPDF_PageObject* pPageObj) {
diff --git a/fpdfsdk/fpdf_ppo.cpp b/fpdfsdk/fpdf_ppo.cpp
index 5c0fa6f..554c210 100644
--- a/fpdfsdk/fpdf_ppo.cpp
+++ b/fpdfsdk/fpdf_ppo.cpp
@@ -150,7 +150,7 @@
pDict->GetObjectFor(pdfium::page_object::kType)->GetDirect();
if (!ToName(pType))
return nullptr;
- if (pType->GetString().Compare("Page"))
+ if (pType->GetString().Compare("Page") != 0)
return nullptr;
const CPDF_Dictionary* pp = ToDictionary(
diff --git a/xfa/fxfa/fm2js/cxfa_fmexpression.cpp b/xfa/fxfa/fm2js/cxfa_fmexpression.cpp
index c1462ac..92880c0 100644
--- a/xfa/fxfa/fm2js/cxfa_fmexpression.cpp
+++ b/xfa/fxfa/fm2js/cxfa_fmexpression.cpp
@@ -450,7 +450,7 @@
return val.Compare(iter.m_wsSomMethodName) > 0;
});
if (result != std::end(gs_FMSomMethods) &&
- !methodName.Compare(result->m_wsSomMethodName)) {
+ methodName.Compare(result->m_wsSomMethodName) == 0) {
return result->m_dParameters;
}
return 0;