Fix a loplugin:bufferadd false positive

(which would hit some yet-to-be-committed code)

Change-Id: I101ae4f7d00ece9d48c96764114668484b0fdd5f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/198660
Reviewed-by: Stephan Bergmann <stephan.bergmann@collabora.com>
Tested-by: Jenkins
This commit is contained in:
Stephan Bergmann
2026-02-04 16:54:59 +01:00
parent f6feaad3bf
commit 96cc64e29c
2 changed files with 40 additions and 0 deletions
+30
View File
@@ -83,6 +83,7 @@ public:
bool VisitStmt(Stmt const*);
bool VisitCallExpr(CallExpr const*);
bool VisitCXXMemberCallExpr(CXXMemberCallExpr const*);
bool VisitCXXConstructExpr(CXXConstructExpr const*);
bool VisitUnaryOperator(UnaryOperator const*);
@@ -143,6 +144,35 @@ bool BufferAdd::VisitCallExpr(CallExpr const* callExpr)
return true;
}
bool BufferAdd::VisitCXXMemberCallExpr(CXXMemberCallExpr const* expr)
{
if (ignoreLocation(expr))
{
return true;
}
auto const e = dyn_cast<DeclRefExpr>(expr->getImplicitObjectArgument()->IgnoreParenImpCasts());
if (e == nullptr)
{
return true;
}
auto const d = dyn_cast<VarDecl>(e->getDecl());
if (d == nullptr)
{
return true;
}
auto const tc = loplugin::TypeCheck(d->getType());
if (!(tc.Class("OStringBuffer").Namespace("rtl").GlobalNamespace()
|| tc.Class("OUStringBuffer").Namespace("rtl").GlobalNamespace()))
{
return true;
}
if (!isMethodOkToMerge(expr))
{
badMap.insert(d);
}
return true;
}
bool BufferAdd::VisitCXXConstructExpr(CXXConstructExpr const* callExpr)
{
if (ignoreLocation(callExpr))
+10
View File
@@ -117,6 +117,16 @@ void f7()
OStringBuffer noelf7("xxx");
noelf7 = "xxx" + noelf7 + "xxx";
}
char16_t rnd();
void f8(sal_Int32 n)
{
OUStringBuffer buf;
auto p = buf.appendUninitialized(n);
for (sal_Int32 i = 0; i != n; ++i)
{
*p++ = rnd();
}
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */