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>
This commit is contained in:
Stephan Bergmann
2017-09-22 08:16:59 +02:00
parent 6d1c8a4358
commit 5c54b6523f
2 changed files with 12 additions and 2 deletions

View File

@@ -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()))
{