diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-10-16 10:13:30 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-10-16 12:12:31 +0200 |
commit | 4a96fb8ec0130e1036913093836bcf28bc37a49b (patch) | |
tree | e7aad9be4ca417e9e64f688cc99bee0638037741 /compilerplugins | |
parent | f33b6e341fb7dd1ab3acd4fe5457b716be316e89 (diff) |
loplugin:bufferadd loosen some constraints
and extend O*StringView to have a constructor that takes a pointer and a
length
Change-Id: I6120e96280f030757e855a6596efdae438b7e1e8
Reviewed-on: https://gerrit.libreoffice.org/80872
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/bufferadd.cxx | 36 | ||||
-rw-r--r-- | compilerplugins/clang/test/bufferadd.cxx | 17 |
2 files changed, 24 insertions, 29 deletions
diff --git a/compilerplugins/clang/bufferadd.cxx b/compilerplugins/clang/bufferadd.cxx index deb97bb35c11..a1c9738f0041 100644 --- a/compilerplugins/clang/bufferadd.cxx +++ b/compilerplugins/clang/bufferadd.cxx @@ -51,6 +51,8 @@ public: return false; if (loplugin::isSamePathname(fn, SRCDIR "/writerfilter/source/dmapper/GraphicImport.cxx")) return false; + if (loplugin::isSamePathname(fn, SRCDIR "/sdext/source/pdfimport/pdfparse/pdfparse.cxx")) + return false; return true; } @@ -174,14 +176,15 @@ void BufferAdd::findBufferAssignOrAdd(const Stmt* parentStmt, Stmt const* stmt) return; } auto tc2 = loplugin::TypeCheck(cxxConstructExpr->getArg(0)->getType()); - if (cxxConstructExpr->getArg(0)->getType()->isBuiltinType() - || tc2.LvalueReference().Class("OUStringBuffer") + if (tc2.LvalueReference().Class("OUStringBuffer") || tc2.LvalueReference().Class("OStringBuffer") || tc2.Class("OUStringBuffer") || tc2.Class("OStringBuffer")) { badMap.insert(varDeclLHS); return; } + addToGoodMap(varDeclLHS, parentStmt); + return; } if (!isSideEffectFree(varDeclLHS->getInit())) badMap.insert(varDeclLHS); @@ -289,32 +292,6 @@ bool BufferAdd::isMethodOkToMerge(CXXMemberCallExpr const* memberCall) return false; auto rhs = memberCall->getArg(0); - - if (loplugin::TypeCheck(memberCall->getType()) - .Class("OStringBuffer") - .Namespace("rtl") - .GlobalNamespace()) - { - // because we have no OStringLiteral1 - if (tc2.Char()) - return false; - // Can't see how to make the call to append(sal_Unicode*pStart, sal_Unicode*pEnd) work - if (memberCall->getNumArgs() == 2 && loplugin::TypeCheck(rhs->getType()).Pointer()) - return false; - } - if (loplugin::TypeCheck(memberCall->getType()) - .Class("OUStringBuffer") - .Namespace("rtl") - .GlobalNamespace()) - { - // character literals we do with OUStringBuffer, not variables of type sal_Unicode/char - if (tc2.Typedef("sal_Unicode").GlobalNamespace() && !isa<CharacterLiteral>(rhs)) - return false; - // Can't see how to make the call to append(sal_Unicode*pStart, sal_Unicode*pEnd) work - if (memberCall->getNumArgs() == 2 - && loplugin::TypeCheck(memberCall->getArg(0)->getType()).Pointer()) - return false; - } if (!isSideEffectFree(rhs)) return false; return true; @@ -357,7 +334,8 @@ bool BufferAdd::isSideEffectFree(Expr const* expr) if (calleeMethodDecl && calleeMethodDecl->getIdentifier()) { auto name = calleeMethodDecl->getName(); - if (name == "number" || name == "unacquired") + if (callExpr->getNumArgs() > 0 + && (name == "number" || name == "unacquired" || name == "boolean")) { auto tc = loplugin::TypeCheck(calleeMethodDecl->getParent()); if (tc.Class("OUString") || tc.Class("OString")) diff --git a/compilerplugins/clang/test/bufferadd.cxx b/compilerplugins/clang/test/bufferadd.cxx index 1b08dcacb1bf..7d8d9a693b9f 100644 --- a/compilerplugins/clang/test/bufferadd.cxx +++ b/compilerplugins/clang/test/bufferadd.cxx @@ -29,6 +29,23 @@ void f2() OUStringBuffer v; v.append("xxx").append("aaaa"); } +void f3(OString class_name) +{ + // expected-error@+1 {{convert this append sequence into a *String + sequence [loplugin:bufferadd]}} + OStringBuffer sig_buf(5 + class_name.getLength()); + sig_buf.append("(I)L"); + //sig_buf.append( class_name.replace( '.', '/' ) ); + sig_buf.append(';'); + OString sig(sig_buf.makeStringAndClear()); + (void)sig; +} +void f4(sal_Unicode const* pPathBegin) +{ + // expected-error@+1 {{convert this append sequence into a *String + sequence [loplugin:bufferadd]}} + OUStringBuffer v; + v.append(pPathBegin, 12); + v.append("aaaa"); +} } namespace test2 |