summaryrefslogtreecommitdiff
path: root/compilerplugins/clang/stringconstant.cxx
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2017-09-22 08:16:59 +0200
committerStephan Bergmann <sbergman@redhat.com>2017-09-22 13:45:07 +0200
commit5c54b6523f74db4f79540361fc1630aaee06bcd5 (patch)
tree0bfe23a76b7b6b1fa8bcadc4498613e37ce451d7 /compilerplugins/clang/stringconstant.cxx
parent6d1c8a43586503e703baebabc5330a1898f7ec43 (diff)
loplugin:stringconstant: warn about explicit length mismatch
(just in case) Change-Id: I9eaf6e920fc7fc3ebc8c705df1cdf34b325db74a Reviewed-on: https://gerrit.libreoffice.org/42614 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'compilerplugins/clang/stringconstant.cxx')
-rw-r--r--compilerplugins/clang/stringconstant.cxx12
1 files changed, 10 insertions, 2 deletions
diff --git a/compilerplugins/clang/stringconstant.cxx b/compilerplugins/clang/stringconstant.cxx
index 2eab378e443f..a4e0b79438b2 100644
--- a/compilerplugins/clang/stringconstant.cxx
+++ b/compilerplugins/clang/stringconstant.cxx
@@ -842,11 +842,19 @@ bool StringConstant::VisitCXXConstructExpr(CXXConstructExpr const * expr) {
}
APSInt res;
if (!expr->getArg(1)->EvaluateAsInt(
- res, compiler.getASTContext())
- || res != n)
+ res, compiler.getASTContext()))
{
return true;
}
+ if (res != n) {
+ report(
+ DiagnosticsEngine::Warning,
+ ("suspicious 'rtl::OUString' constructor with literal"
+ " of length %0 and non-matching length argument %1"),
+ expr->getExprLoc())
+ << n << res.toString(10) << expr->getSourceRange();
+ return true;
+ }
if (!expr->getArg(2)->EvaluateAsInt(
res, compiler.getASTContext()))
{