summaryrefslogtreecommitdiff
path: root/xfa
diff options
context:
space:
mode:
authordsinclair <dsinclair@chromium.org>2016-04-26 11:05:26 -0700
committerCommit bot <commit-bot@chromium.org>2016-04-26 11:05:26 -0700
commit76c53794b6202ec37f6dcace5f2ae86870e953b6 (patch)
treeb7c9fce179cee0be2ac01ff966e6521169831e03 /xfa
parent186a78eb0a821a2f1feef524cb590d0fea2009ba (diff)
downloadpdfium-chromium/2719.tar.xz
Fix Wvarargs warning in XFA error code.chromium/2722chromium/2721chromium/2719chromium/2718
Chrome has enabled the -Wvarargs warning that was added to clang, this fails with PDFium XFA builds due to two warnings: ../../xfa/fxfa/fm2js/xfa_lexer.cpp:539:16: error: passing an object that undergoes default argument promotion to 'va_start' has undefined behavior [-Werror,-Wvarargs] va_start(ap, msg); ^ ../../xfa/fxfa/fm2js/xfa_lexer.cpp:535:40: note: parameter of type 'XFA_FM_ERRMSG' is declared here void CXFA_FMLexer::Error(XFA_FM_ERRMSG msg, ...) { The issue is that XFA_FM_ERRMSG is an enum and we violate the promotion rules for passing the value to va_start. I removed the enum and named the flags explicitly then pass in the string as the argument. BUG=chromium:606726 Review URL: https://codereview.chromium.org/1921323002
Diffstat (limited to 'xfa')
-rw-r--r--xfa/fxfa/fm2js/xfa_error.cpp22
-rw-r--r--xfa/fxfa/fm2js/xfa_error.h20
-rw-r--r--xfa/fxfa/fm2js/xfa_fmparse.cpp49
-rw-r--r--xfa/fxfa/fm2js/xfa_fmparse.h2
-rw-r--r--xfa/fxfa/fm2js/xfa_lexer.cpp31
-rw-r--r--xfa/fxfa/fm2js/xfa_lexer.h2
6 files changed, 57 insertions, 69 deletions
diff --git a/xfa/fxfa/fm2js/xfa_error.cpp b/xfa/fxfa/fm2js/xfa_error.cpp
index 69ce608318..020d9bc509 100644
--- a/xfa/fxfa/fm2js/xfa_error.cpp
+++ b/xfa/fxfa/fm2js/xfa_error.cpp
@@ -6,16 +6,12 @@
#include "xfa/fxfa/fm2js/xfa_error.h"
-static const FX_WCHAR* const gs_lpStrErrorMsgInfo[] = {
- L"unsupported char '%c'", L"bad suffix on number",
- L"invalidate char '%c'", L"expected identifier instead of '%s'",
- L"expected '%s' instead of '%s'", L"expected 'endif' instead of '%s'",
- L"unexpected expression '%s'", L"expected operator '%s' instead of '%s'",
- L"expected non-empty expression",
-};
-
-const FX_WCHAR* XFA_FM_ErrorMsg(XFA_FM_ERRMSG msg) {
- if (msg < FMERR_MAXIMUM)
- return gs_lpStrErrorMsgInfo[msg];
- return L"";
-}
+const FX_WCHAR kFMErrUnsupportedChar[] = L"unsupported char '%c'";
+const FX_WCHAR kFMErrBadSuffixNumber[] = L"bad suffix on number";
+const FX_WCHAR kFMErrExpectedIdentifier[] =
+ L"expected identifier instead of '%s'";
+const FX_WCHAR kFMErrExpectedToken[] = L"expected '%s' instead of '%s'";
+const FX_WCHAR kFMErrExpectedEndIf[] = L"expected 'endif' instead of '%s'";
+const FX_WCHAR kFMErrUnexpectedExpression[] = L"unexpected expression '%s'";
+const FX_WCHAR kFMErrExpectedNonEmptyExpression[] =
+ L"expected non-empty expression";
diff --git a/xfa/fxfa/fm2js/xfa_error.h b/xfa/fxfa/fm2js/xfa_error.h
index 2415cd3212..6ce102e03e 100644
--- a/xfa/fxfa/fm2js/xfa_error.h
+++ b/xfa/fxfa/fm2js/xfa_error.h
@@ -10,18 +10,13 @@
#include "core/fxcrt/include/fx_string.h"
#include "core/fxcrt/include/fx_system.h"
-enum XFA_FM_ERRMSG {
- FMERR_UNSUPPORTED_CHAR,
- FMERR_BAD_SUFFIX_NUMBER,
- FMERR_INVALIDATE_CHAR,
- FMERR_EXPECTED_IDENTIFIER,
- FMERR_EXPECTED_TOKEN,
- FMERR_EXPECTED_IFEND,
- FMERR_UNEXPECTED_EXPRESSION,
- FMERR_EXPTECTED_OPERATOR,
- FMERR_EXPECTED_NON_EMPTY_EXPRESSION,
- FMERR_MAXIMUM
-};
+extern const FX_WCHAR kFMErrUnsupportedChar[];
+extern const FX_WCHAR kFMErrBadSuffixNumber[];
+extern const FX_WCHAR kFMErrExpectedIdentifier[];
+extern const FX_WCHAR kFMErrExpectedToken[];
+extern const FX_WCHAR kFMErrExpectedEndIf[];
+extern const FX_WCHAR kFMErrUnexpectedExpression[];
+extern const FX_WCHAR kFMErrExpectedNonEmptyExpression[];
class CXFA_FMErrorInfo {
public:
@@ -30,6 +25,5 @@ class CXFA_FMErrorInfo {
uint32_t linenum;
CFX_WideString message;
};
-const FX_WCHAR* XFA_FM_ErrorMsg(XFA_FM_ERRMSG msg);
#endif // XFA_FXFA_FM2JS_XFA_ERROR_H_
diff --git a/xfa/fxfa/fm2js/xfa_fmparse.cpp b/xfa/fxfa/fm2js/xfa_fmparse.cpp
index c99f015fca..a917e23b8b 100644
--- a/xfa/fxfa/fm2js/xfa_fmparse.cpp
+++ b/xfa/fxfa/fm2js/xfa_fmparse.cpp
@@ -30,18 +30,17 @@ void CXFA_FMParse::NextToken() {
void CXFA_FMParse::Check(XFA_FM_TOKEN op) {
if (m_pToken->m_type != op) {
CFX_WideString ws_TempString = m_pToken->m_wstring;
- Error(m_pToken->m_uLinenum, FMERR_EXPECTED_TOKEN,
- XFA_FM_KeywordToString(op), ws_TempString.c_str());
+ Error(m_pToken->m_uLinenum, kFMErrExpectedToken, XFA_FM_KeywordToString(op),
+ ws_TempString.c_str());
}
NextToken();
}
-void CXFA_FMParse::Error(uint32_t lineNum, XFA_FM_ERRMSG msg, ...) {
+void CXFA_FMParse::Error(uint32_t lineNum, const FX_WCHAR* msg, ...) {
m_pErrorInfo->linenum = lineNum;
- const FX_WCHAR* lpMessageInfo = XFA_FM_ErrorMsg(msg);
va_list ap;
va_start(ap, msg);
- m_pErrorInfo->message.FormatV(lpMessageInfo, ap);
+ m_pErrorInfo->message.FormatV(msg, ap);
va_end(ap);
}
@@ -83,7 +82,7 @@ CXFA_FMExpression* CXFA_FMParse::ParseFunction() {
NextToken();
if (m_pToken->m_type != TOKidentifier) {
CFX_WideString ws_TempString = m_pToken->m_wstring;
- Error(m_pToken->m_uLinenum, FMERR_EXPECTED_IDENTIFIER,
+ Error(m_pToken->m_uLinenum, kFMErrExpectedIdentifier,
ws_TempString.c_str());
} else {
ident = m_pToken->m_wstring;
@@ -112,7 +111,7 @@ CXFA_FMExpression* CXFA_FMParse::ParseFunction() {
}
} else {
CFX_WideString ws_TempString = m_pToken->m_wstring;
- Error(m_pToken->m_uLinenum, FMERR_EXPECTED_IDENTIFIER,
+ Error(m_pToken->m_uLinenum, kFMErrExpectedIdentifier,
ws_TempString.c_str());
NextToken();
break;
@@ -182,7 +181,7 @@ CXFA_FMExpression* CXFA_FMParse::ParseExpression() {
break;
default:
CFX_WideString ws_TempString = m_pToken->m_wstring;
- Error(m_pToken->m_uLinenum, FMERR_UNEXPECTED_EXPRESSION,
+ Error(m_pToken->m_uLinenum, kFMErrUnexpectedExpression,
ws_TempString.c_str());
NextToken();
break;
@@ -197,7 +196,7 @@ CXFA_FMExpression* CXFA_FMParse::ParseVarExpression() {
NextToken();
if (m_pToken->m_type != TOKidentifier) {
CFX_WideString ws_TempString = m_pToken->m_wstring;
- Error(m_pToken->m_uLinenum, FMERR_EXPECTED_IDENTIFIER,
+ Error(m_pToken->m_uLinenum, kFMErrExpectedIdentifier,
ws_TempString.c_str());
} else {
ident = m_pToken->m_wstring;
@@ -533,7 +532,7 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParsePrimaryExpression() {
break;
default:
CFX_WideString ws_TempString = m_pToken->m_wstring;
- Error(m_pToken->m_uLinenum, FMERR_UNEXPECTED_EXPRESSION,
+ Error(m_pToken->m_uLinenum, kFMErrUnexpectedExpression,
ws_TempString.c_str());
NextToken();
break;
@@ -568,7 +567,7 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParsePostExpression(
}
if (m_pToken->m_type != TOKrparen) {
CFX_WideString ws_TempString = m_pToken->m_wstring;
- Error(m_pToken->m_uLinenum, FMERR_EXPECTED_TOKEN,
+ Error(m_pToken->m_uLinenum, kFMErrExpectedToken,
XFA_FM_KeywordToString(TOKrparen), ws_TempString.c_str());
}
}
@@ -621,7 +620,7 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParsePostExpression(
}
if (m_pToken->m_type != TOKrparen) {
CFX_WideString ws_TempString = m_pToken->m_wstring;
- Error(m_pToken->m_uLinenum, FMERR_EXPECTED_TOKEN,
+ Error(m_pToken->m_uLinenum, kFMErrExpectedToken,
XFA_FM_KeywordToString(TOKrparen), ws_TempString.c_str());
}
}
@@ -669,7 +668,7 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParsePostExpression(
}
} else {
CFX_WideString ws_TempString = m_pToken->m_wstring;
- Error(m_pToken->m_uLinenum, FMERR_EXPECTED_IDENTIFIER,
+ Error(m_pToken->m_uLinenum, kFMErrExpectedIdentifier,
ws_TempString.c_str());
return e;
}
@@ -697,7 +696,7 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParsePostExpression(
}
} else {
CFX_WideString ws_TempString = m_pToken->m_wstring;
- Error(m_pToken->m_uLinenum, FMERR_EXPECTED_IDENTIFIER,
+ Error(m_pToken->m_uLinenum, kFMErrExpectedIdentifier,
ws_TempString.c_str());
return e;
}
@@ -725,7 +724,7 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParsePostExpression(
}
} else {
CFX_WideString ws_TempString = m_pToken->m_wstring;
- Error(m_pToken->m_uLinenum, FMERR_EXPECTED_IDENTIFIER,
+ Error(m_pToken->m_uLinenum, kFMErrExpectedIdentifier,
ws_TempString.c_str());
return e;
}
@@ -756,7 +755,7 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParseIndexExpression() {
NextToken();
if (m_pToken->m_type != TOKrbracket) {
CFX_WideString ws_TempString = m_pToken->m_wstring;
- Error(m_pToken->m_uLinenum, FMERR_EXPECTED_TOKEN,
+ Error(m_pToken->m_uLinenum, kFMErrExpectedToken,
XFA_FM_KeywordToString(TOKrparen), ws_TempString.c_str());
pExp.reset();
}
@@ -772,7 +771,7 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParseIndexExpression() {
s.reset(ParseSimpleExpression());
if (m_pToken->m_type != TOKrbracket) {
CFX_WideString ws_TempString = m_pToken->m_wstring;
- Error(m_pToken->m_uLinenum, FMERR_EXPECTED_TOKEN,
+ Error(m_pToken->m_uLinenum, kFMErrExpectedToken,
XFA_FM_KeywordToString(TOKrparen), ws_TempString.c_str());
} else {
pExp.reset(
@@ -785,7 +784,7 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParseParenExpression() {
Check(TOKlparen);
if (m_pToken->m_type == TOKrparen) {
- Error(m_pToken->m_uLinenum, FMERR_EXPECTED_NON_EMPTY_EXPRESSION);
+ Error(m_pToken->m_uLinenum, kFMErrExpectedNonEmptyExpression);
NextToken();
return nullptr;
}
@@ -892,7 +891,7 @@ CXFA_FMExpression* CXFA_FMParse::ParseIfExpression() {
break;
default:
CFX_WideString ws_TempString = m_pToken->m_wstring;
- Error(m_pToken->m_uLinenum, FMERR_EXPECTED_IFEND, ws_TempString.c_str());
+ Error(m_pToken->m_uLinenum, kFMErrExpectedEndIf, ws_TempString.c_str());
NextToken();
break;
}
@@ -928,7 +927,7 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParseSubassignmentInForExpression() {
break;
default:
CFX_WideString ws_TempString = m_pToken->m_wstring;
- Error(m_pToken->m_uLinenum, FMERR_UNEXPECTED_EXPRESSION,
+ Error(m_pToken->m_uLinenum, kFMErrUnexpectedExpression,
ws_TempString.c_str());
NextToken();
break;
@@ -942,7 +941,7 @@ CXFA_FMExpression* CXFA_FMParse::ParseForExpression() {
NextToken();
if (m_pToken->m_type != TOKidentifier) {
CFX_WideString ws_TempString = m_pToken->m_wstring;
- Error(m_pToken->m_uLinenum, FMERR_EXPECTED_TOKEN,
+ Error(m_pToken->m_uLinenum, kFMErrExpectedToken,
XFA_FM_KeywordToString(m_pToken->m_type), ws_TempString.c_str());
}
wsVariant = m_pToken->m_wstring;
@@ -953,7 +952,7 @@ CXFA_FMExpression* CXFA_FMParse::ParseForExpression() {
pAssignment.reset(ParseSimpleExpression());
} else {
CFX_WideString ws_TempString = m_pToken->m_wstring;
- Error(m_pToken->m_uLinenum, FMERR_EXPECTED_TOKEN,
+ Error(m_pToken->m_uLinenum, kFMErrExpectedToken,
XFA_FM_KeywordToString(m_pToken->m_type), ws_TempString.c_str());
}
int32_t iDirection = 0;
@@ -963,7 +962,7 @@ CXFA_FMExpression* CXFA_FMParse::ParseForExpression() {
iDirection = -1;
} else {
CFX_WideString ws_TempString = m_pToken->m_wstring;
- Error(m_pToken->m_uLinenum, FMERR_EXPECTED_TOKEN, L"upto or downto",
+ Error(m_pToken->m_uLinenum, kFMErrExpectedToken, L"upto or downto",
ws_TempString.c_str());
}
NextToken();
@@ -994,7 +993,7 @@ CXFA_FMExpression* CXFA_FMParse::ParseForeachExpression() {
NextToken();
if (m_pToken->m_type != TOKidentifier) {
CFX_WideString ws_TempString = m_pToken->m_wstring;
- Error(m_pToken->m_uLinenum, FMERR_EXPECTED_TOKEN,
+ Error(m_pToken->m_uLinenum, kFMErrExpectedToken,
XFA_FM_KeywordToString(m_pToken->m_type), ws_TempString.c_str());
}
wsIdentifier = m_pToken->m_wstring;
@@ -1003,7 +1002,7 @@ CXFA_FMExpression* CXFA_FMParse::ParseForeachExpression() {
Check(TOKlparen);
if (m_pToken->m_type == TOKrparen) {
CFX_WideString ws_TempString = m_pToken->m_wstring;
- Error(m_pToken->m_uLinenum, FMERR_UNEXPECTED_EXPRESSION,
+ Error(m_pToken->m_uLinenum, kFMErrUnexpectedExpression,
ws_TempString.c_str());
NextToken();
} else {
diff --git a/xfa/fxfa/fm2js/xfa_fmparse.h b/xfa/fxfa/fm2js/xfa_fmparse.h
index 288ae90744..014eccee08 100644
--- a/xfa/fxfa/fm2js/xfa_fmparse.h
+++ b/xfa/fxfa/fm2js/xfa_fmparse.h
@@ -18,7 +18,7 @@ class CXFA_FMParse {
int32_t Init(const CFX_WideStringC& wsFormcalc, CXFA_FMErrorInfo* pErrorInfo);
void NextToken();
void Check(XFA_FM_TOKEN op);
- void Error(uint32_t lineNum, XFA_FM_ERRMSG msg, ...);
+ void Error(uint32_t lineNum, const FX_WCHAR* msg, ...);
CFX_PtrArray* ParseTopExpression();
CXFA_FMExpression* ParseFunction();
CXFA_FMExpression* ParseExpression();
diff --git a/xfa/fxfa/fm2js/xfa_lexer.cpp b/xfa/fxfa/fm2js/xfa_lexer.cpp
index dd3b48ff54..f048f42668 100644
--- a/xfa/fxfa/fm2js/xfa_lexer.cpp
+++ b/xfa/fxfa/fm2js/xfa_lexer.cpp
@@ -177,14 +177,14 @@ CXFA_FMToken* CXFA_FMLexer::Scan() {
CXFA_FMToken* p = new CXFA_FMToken(m_uCurrentLine);
if (!XFA_FMDChar::isAvalid(m_ptr)) {
ch = XFA_FMDChar::get(m_ptr);
- Error(FMERR_UNSUPPORTED_CHAR, ch);
+ Error(kFMErrUnsupportedChar, ch);
return p;
}
int iRet = 0;
while (1) {
if (!XFA_FMDChar::isAvalid(m_ptr)) {
ch = XFA_FMDChar::get(m_ptr);
- Error(FMERR_UNSUPPORTED_CHAR, ch);
+ Error(kFMErrUnsupportedChar, ch);
return p;
}
ch = XFA_FMDChar::get(m_ptr);
@@ -227,7 +227,7 @@ CXFA_FMToken* CXFA_FMLexer::Scan() {
iRet = Number(p, m_ptr, pTemp);
m_ptr = pTemp;
if (iRet) {
- Error(FMERR_BAD_SUFFIX_NUMBER);
+ Error(kFMErrBadSuffixNumber);
return p;
}
}
@@ -246,7 +246,7 @@ CXFA_FMToken* CXFA_FMLexer::Scan() {
}
} else {
ch = XFA_FMDChar::get(m_ptr);
- Error(FMERR_UNSUPPORTED_CHAR, ch);
+ Error(kFMErrUnsupportedChar, ch);
return p;
}
break;
@@ -268,7 +268,7 @@ CXFA_FMToken* CXFA_FMLexer::Scan() {
}
} else {
ch = XFA_FMDChar::get(m_ptr);
- Error(FMERR_UNSUPPORTED_CHAR, ch);
+ Error(kFMErrUnsupportedChar, ch);
return p;
}
break;
@@ -286,7 +286,7 @@ CXFA_FMToken* CXFA_FMLexer::Scan() {
}
} else {
ch = XFA_FMDChar::get(m_ptr);
- Error(FMERR_UNSUPPORTED_CHAR, ch);
+ Error(kFMErrUnsupportedChar, ch);
return p;
}
break;
@@ -345,7 +345,7 @@ CXFA_FMToken* CXFA_FMLexer::Scan() {
}
} else {
ch = XFA_FMDChar::get(m_ptr);
- Error(FMERR_UNSUPPORTED_CHAR, ch);
+ Error(kFMErrUnsupportedChar, ch);
return p;
}
break;
@@ -372,7 +372,7 @@ CXFA_FMToken* CXFA_FMLexer::Scan() {
iRet = Number(p, m_ptr, pTemp);
m_ptr = pTemp;
if (iRet) {
- Error(FMERR_BAD_SUFFIX_NUMBER);
+ Error(kFMErrBadSuffixNumber);
}
return p;
} else {
@@ -381,7 +381,7 @@ CXFA_FMToken* CXFA_FMLexer::Scan() {
}
} else {
ch = XFA_FMDChar::get(m_ptr);
- Error(FMERR_UNSUPPORTED_CHAR, ch);
+ Error(kFMErrUnsupportedChar, ch);
return p;
}
case 0x09:
@@ -430,7 +430,7 @@ uint32_t CXFA_FMLexer::String(CXFA_FMToken* t,
ch = XFA_FMDChar::get(p);
pEnd = p;
t->m_wstring = CFX_WideStringC(pStart, (pEnd - pStart));
- Error(FMERR_UNSUPPORTED_CHAR, ch);
+ Error(kFMErrUnsupportedChar, ch);
return 1;
}
if (ch == '"') {
@@ -439,7 +439,7 @@ uint32_t CXFA_FMLexer::String(CXFA_FMToken* t,
ch = XFA_FMDChar::get(p);
pEnd = p;
t->m_wstring = CFX_WideStringC(pStart, (pEnd - pStart));
- Error(FMERR_UNSUPPORTED_CHAR, ch);
+ Error(kFMErrUnsupportedChar, ch);
return 1;
}
ch = XFA_FMDChar::get(p);
@@ -468,7 +468,7 @@ uint32_t CXFA_FMLexer::Identifiers(CXFA_FMToken* t,
if (!XFA_FMDChar::isAvalid(p)) {
pEnd = p;
t->m_wstring = CFX_WideStringC(pStart, (pEnd - pStart));
- Error(FMERR_UNSUPPORTED_CHAR, ch);
+ Error(kFMErrUnsupportedChar, ch);
return 1;
}
ch = XFA_FMDChar::get(p);
@@ -476,7 +476,7 @@ uint32_t CXFA_FMLexer::Identifiers(CXFA_FMToken* t,
if (!XFA_FMDChar::isAvalid(p)) {
pEnd = p;
t->m_wstring = CFX_WideStringC(pStart, (pEnd - pStart));
- Error(FMERR_UNSUPPORTED_CHAR, ch);
+ Error(kFMErrUnsupportedChar, ch);
return 1;
}
ch = XFA_FMDChar::get(p);
@@ -532,12 +532,11 @@ XFA_FM_TOKEN CXFA_FMLexer::IsKeyword(const CFX_WideStringC& str) {
return TOKidentifier;
}
-void CXFA_FMLexer::Error(XFA_FM_ERRMSG msg, ...) {
+void CXFA_FMLexer::Error(const FX_WCHAR* msg, ...) {
m_pErrorInfo->linenum = m_uCurrentLine;
- const FX_WCHAR* lpMessageInfo = XFA_FM_ErrorMsg(msg);
va_list ap;
va_start(ap, msg);
- m_pErrorInfo->message.FormatV(lpMessageInfo, ap);
+ m_pErrorInfo->message.FormatV(msg, ap);
va_end(ap);
}
diff --git a/xfa/fxfa/fm2js/xfa_lexer.h b/xfa/fxfa/fm2js/xfa_lexer.h
index fd89dc72eb..c21c00255a 100644
--- a/xfa/fxfa/fm2js/xfa_lexer.h
+++ b/xfa/fxfa/fm2js/xfa_lexer.h
@@ -119,7 +119,7 @@ class CXFA_FMLexer {
}
const FX_WCHAR* SavePos() { return m_ptr; }
void RestorePos(const FX_WCHAR* pPos) { m_ptr = pPos; }
- void Error(XFA_FM_ERRMSG msg, ...);
+ void Error(const FX_WCHAR* msg, ...);
FX_BOOL HasError() const;
protected: