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>
This commit is contained in:
@@ -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"))
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user