Fix spin in CFGAS_FormatString::FormatStrNum().
Also remove test in private method duplicated in public wrapper.
Bug: pdfium:1233
Change-Id: I38b773e1037539f8669a611a863956313ce3b606
Reviewed-on: https://pdfium-review.googlesource.com/c/50430
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/xfa/fgas/crt/cfgas_formatstring.cpp b/xfa/fgas/crt/cfgas_formatstring.cpp
index d07f14f..4f766c7 100644
--- a/xfa/fgas/crt/cfgas_formatstring.cpp
+++ b/xfa/fgas/crt/cfgas_formatstring.cpp
@@ -1855,8 +1855,8 @@
bool CFGAS_FormatString::FormatStrNum(WideStringView wsInputNum,
const WideString& wsPattern,
WideString* wsOutput) const {
- if (wsInputNum.IsEmpty() || wsPattern.IsEmpty())
- return false;
+ ASSERT(!wsInputNum.IsEmpty());
+ ASSERT(!wsPattern.IsEmpty());
int32_t dot_index_f = -1;
uint32_t dwNumStyle = 0;
@@ -2019,6 +2019,9 @@
ccf -= 2;
bAddNeg = true;
+ } else {
+ wsOutput->InsertAtFront('r');
+ ccf--;
}
break;
case 'R':
@@ -2026,6 +2029,9 @@
*wsOutput = bNeg ? L"CR" : L" " + *wsOutput;
ccf -= 2;
bAddNeg = true;
+ } else {
+ wsOutput->InsertAtFront('R');
+ ccf--;
}
break;
case 'b':
@@ -2035,6 +2041,9 @@
ccf -= 2;
bAddNeg = true;
+ } else {
+ wsOutput->InsertAtFront('b');
+ ccf--;
}
break;
case 'B':
@@ -2042,6 +2051,9 @@
*wsOutput = bNeg ? L"DB" : L" " + *wsOutput;
ccf -= 2;
bAddNeg = true;
+ } else {
+ wsOutput->InsertAtFront('B');
+ ccf--;
}
break;
case '%': {
@@ -2234,6 +2246,7 @@
WideString* wsOutput) const {
if (wsSrcNum.IsEmpty() || wsPattern.IsEmpty())
return false;
+
return FormatStrNum(wsSrcNum.AsStringView(), wsPattern, wsOutput);
}
diff --git a/xfa/fgas/crt/cfgas_formatstring_unittest.cpp b/xfa/fgas/crt/cfgas_formatstring_unittest.cpp
index 3a8073c..e961265 100644
--- a/xfa/fgas/crt/cfgas_formatstring_unittest.cpp
+++ b/xfa/fgas/crt/cfgas_formatstring_unittest.cpp
@@ -509,6 +509,11 @@
// {L"en", L"-123.5", L"zzz.z)", L"123.5)"},
{L"en", L"123.5", L"zzz.z)", L"123.5 "},
{L"en", L"123.5", L"zzz.z(", L"123.5 "},
+ // https://crbug.com/pdfium/1233
+ {L"en", L"1", L"r9", L"r1"},
+ {L"en", L"1", L"R9", L"R1"},
+ {L"en", L"1", L"b9", L"b1"},
+ {L"en", L"1", L"B9", L"B1"},
};
for (size_t i = 0; i < FX_ArraySize(tests); ++i) {