diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2019-10-21 17:00:06 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2019-10-21 20:05:49 +0200 |
commit | 61dc9b6aab2870faeb7cf26cdfb3d3e941642a59 (patch) | |
tree | de4b6baa29e2f7d4ca9dbbbd07b4a45c72f1d86b /compilerplugins/clang/stringconstant.cxx | |
parent | 6fab4144b669b4896932350d090e447d50e44821 (diff) |
Make loplugin:stringcostant find some misuses of OUStringBuffer::append
...like the one manually found at 06845c14a17146b0ec50dd3704b6af9ee13927bc "This
should have become a UTF-16 string literal". (No further misuses were found
across the code base.)
Change-Id: I0b604bdaaa38bd9248440ff7bd7bf0545fc6426a
Reviewed-on: https://gerrit.libreoffice.org/81250
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'compilerplugins/clang/stringconstant.cxx')
-rw-r--r-- | compilerplugins/clang/stringconstant.cxx | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/compilerplugins/clang/stringconstant.cxx b/compilerplugins/clang/stringconstant.cxx index 309bf900e377..2360ef2e3620 100644 --- a/compilerplugins/clang/stringconstant.cxx +++ b/compilerplugins/clang/stringconstant.cxx @@ -772,6 +772,12 @@ bool StringConstant::VisitCallExpr(CallExpr const * expr) { } return true; } + if (dc.Function("append").Class("OUStringBuffer").Namespace("rtl").GlobalNamespace() + && fdecl->getNumParams() == 1) + { + handleChar(expr, 0, fdecl, "", TreatEmpty::Error, false); + return true; + } if ((dc.Function("appendAscii").Class("OUStringBuffer").Namespace("rtl") .GlobalNamespace()) && fdecl->getNumParams() == 1) @@ -1847,14 +1853,16 @@ void StringConstant::handleChar( } std::string repl(replacement); checkEmpty(expr, callee, treatEmpty, n, &repl); - reportChange( - expr, ChangeKind::Char, callee->getQualifiedNameAsString(), repl, - (literal - ? (n == 0 - ? PassThrough::EmptyConstantString - : PassThrough::NonEmptyConstantString) - : PassThrough::No), - nonArray, rewriteFrom, rewriteTo); + if (!repl.empty()) { + reportChange( + expr, ChangeKind::Char, callee->getQualifiedNameAsString(), repl, + (literal + ? (n == 0 + ? PassThrough::EmptyConstantString + : PassThrough::NonEmptyConstantString) + : PassThrough::No), + nonArray, rewriteFrom, rewriteTo); + } } void StringConstant::handleCharLen( |