Skip to content

Commit

Permalink
HPCC-21758 Make StringBuffer constructors explicit
Browse files Browse the repository at this point in the history
Catches places where a stringbuffer is passed or returned by value, 99% of
which are either accidental or ill-advised.

Also means you can no longer use StringBuffer x = "xxx"; which is perhaps
unfortunate and required a few changes.

Signed-off-by: Richard Chapman <rchapman@hpccsystems.com>
  • Loading branch information
richardkchapman committed Apr 10, 2019
1 parent 587a7a5 commit 9ff9bae
Show file tree
Hide file tree
Showing 89 changed files with 426 additions and 421 deletions.
2 changes: 1 addition & 1 deletion common/environment/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2318,7 +2318,7 @@ extern ENVIRONMENT_API void closeEnvironment()

extern ENVIRONMENT_API unsigned long readSizeSetting(const char * sizeStr, const unsigned long defaultSize)
{
StringBuffer buf = sizeStr;
StringBuffer buf(sizeStr);
buf.trim();

if (buf.isEmpty())
Expand Down
2 changes: 1 addition & 1 deletion common/remote/rmtssh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class CFRunSSH: public CInterface, implements IFRunSSH



StringBuffer expandCmd(StringBuffer &cmdbuf, unsigned nodenum, unsigned treefrom)
StringBuffer &expandCmd(StringBuffer &cmdbuf, unsigned nodenum, unsigned treefrom)
{
const char *cp=cmd.get();
if (!cp)
Expand Down
12 changes: 6 additions & 6 deletions common/roxiecommlib/roxiecommunicationclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ class CRoxieCommunicationClient: implements IRoxieCommunicationClient, public CI
SocketEndpoint ep;
unsigned roxieTimeout;

IPropertyTree *sendRoxieControlQuery(const StringBuffer &xml, bool deployAll, const char *remoteRoxieIP = NULL)
IPropertyTree *sendRoxieControlQuery(const char *xml, bool deployAll, const char *remoteRoxieIP = NULL)
{
unsigned len = xml.length();
unsigned len = strlen(xml);
size32_t sendlen = len;
_WINREV(sendlen);
Owned<ISocket> sock = getRoxieSocket(remoteRoxieIP);
Expand All @@ -70,7 +70,7 @@ class CRoxieCommunicationClient: implements IRoxieCommunicationClient, public CI
throw MakeStringException(GET_LOCK_FAILURE, "Request Failed! All roxie nodes unable to process this request at this time. Roxie is busy - possibly in the middle of another deployment. Try again later, if problem persists, make sure all nodes are running");

sock->write(&sendlen, sizeof(sendlen));
sock->write(xml.str(), len);
sock->write(xml, len);
StringBuffer response;
for (;;)
{
Expand Down Expand Up @@ -98,9 +98,9 @@ class CRoxieCommunicationClient: implements IRoxieCommunicationClient, public CI
}


const char *sendRoxieOnDemandQuery(const StringBuffer &xml, SCMStringBuffer &response, bool deployAll, const char *remoteRoxieIP = NULL)
const char *sendRoxieOnDemandQuery(const char *xml, SCMStringBuffer &response, bool deployAll, const char *remoteRoxieIP = NULL)
{
unsigned len = xml.length();
unsigned len = strlen(xml);
size32_t sendlen = len;
_WINREV(sendlen);
Owned<ISocket> sock = getRoxieSocket(remoteRoxieIP);
Expand All @@ -109,7 +109,7 @@ class CRoxieCommunicationClient: implements IRoxieCommunicationClient, public CI
throw MakeStringException(GET_LOCK_FAILURE, "Request Failed! All roxie nodes unable to process this request at this time. Roxie is busy - possibly in the middle of another deployment. Try again later, if problem persists, make sure all nodes are running");

sock->write(&sendlen, sizeof(sendlen));
sock->write(xml.str(), len);
sock->write(xml, len);

Owned<IException> exception;
for (;;)
Expand Down
16 changes: 8 additions & 8 deletions common/thorhelper/thorcommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ inline bool TestRwFlag(unsigned flags, RowReaderWriterFlags flag) { return 0 !=

#define COMP_MASK (rw_compress|rw_compressblkcrc|rw_fastlz|rw_lzw|rw_lz4)
#define COMP_TYPE_MASK (rw_fastlz|rw_lzw|rw_lz4)
inline void setCompFlag(const StringBuffer compStr, unsigned &flags)
inline void setCompFlag(const char *compStr, unsigned &flags)
{
flags &= ~COMP_TYPE_MASK;
if (compStr.length())
if (!isEmptyString(compStr))
{
if (0 == stricmp("FLZ", compStr.str()))
if (0 == stricmp("FLZ", compStr))
flags |= rw_fastlz;
else if (0 == stricmp("LZ4", compStr.str()))
else if (0 == stricmp("LZ4", compStr))
flags |= rw_lz4;
else // not specifically FLZ or LZ4 so set to LZW (or rowdif)
flags |= rw_lzw;
Expand All @@ -130,14 +130,14 @@ inline unsigned getCompMethod(unsigned flags)
return compMethod;
}

inline unsigned getCompMethod(const StringBuffer compStr)
inline unsigned getCompMethod(const char *compStr)
{
unsigned compMethod = COMPRESS_METHOD_LZW;
if (compStr.length())
if (!isEmptyString(compStr))
{
if (0 == stricmp("FLZ", compStr.str()))
if (0 == stricmp("FLZ", compStr))
compMethod = COMPRESS_METHOD_FASTLZ;
else if (0 == stricmp("LZ4", compStr.str()))
else if (0 == stricmp("LZ4", compStr))
compMethod = COMPRESS_METHOD_LZ4;
}
else // default is LZ4
Expand Down
6 changes: 3 additions & 3 deletions common/thorhelper/thorsoapcall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ interface IWSCAsyncFor: public IInterface
virtual int readHttpResponse(StringBuffer &response, ISocket *socket) = 0;
virtual void processResponse(Url &url, StringBuffer &response, ColumnProvider * meta) = 0;

virtual StringBuffer getResponsePath() = 0;
virtual const char *getResponsePath() = 0;
virtual ConstPointerArray & getInputRows() = 0;
virtual IWSCHelper * getMaster() = 0;
virtual IEngineRowAllocator * getOutputAllocator() = 0;
Expand Down Expand Up @@ -1559,7 +1559,7 @@ class CWSCAsyncFor : implements IWSCAsyncFor, public CInterface, public CAsyncFo
if (master->httpHeaders.isEmpty() && master->httpHeaderName.get() && master->httpHeaderValue.get())
{
//backward compatibility
StringBuffer hdr = master->httpHeaderName.get();
StringBuffer hdr(master->httpHeaderName.get());
hdr.append(": ").append(master->httpHeaderValue);
if (soapTraceLevel > 6 || master->logXML)
master->logctx.CTXLOG("SOAPCALL: Adding HTTP Header(%s)", hdr.str());
Expand Down Expand Up @@ -2110,7 +2110,7 @@ class CWSCAsyncFor : implements IWSCAsyncFor, public CInterface, public CAsyncFo
}
}
}
inline virtual StringBuffer getResponsePath() { return responsePath; }
inline virtual const char *getResponsePath() { return responsePath; }
inline virtual ConstPointerArray & getInputRows() { return inputRows; }
inline virtual CWSCHelper * getMaster() { return master; }
inline virtual IEngineRowAllocator * getOutputAllocator() { return outputAllocator; }
Expand Down
2 changes: 1 addition & 1 deletion common/workunit/pkgimpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class WORKUNIT_API CPackageNode : implements IHpccPackage, public CInterface

virtual IPropertyTreeIterator *lookupElements(const char *xpath1, const char *xpath2) const = 0;

inline StringBuffer makeSuperFileXPath(StringBuffer &xpath, const char *superFileName) const
inline StringBuffer &makeSuperFileXPath(StringBuffer &xpath, const char *superFileName) const
{
superFileName = skipForeign(superFileName);
return xpath.append("SuperFile[@id='").appendLower(strlen(superFileName), superFileName).append("']");
Expand Down
8 changes: 4 additions & 4 deletions common/workunit/workunit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5440,7 +5440,7 @@ class CDaliWorkUnitFactory : public CWorkUnitFactory, implements IDaliClientShut
const StringArray& values = orFilter->queryValues();
ForEachItemIn(i, values)
{
StringBuffer path = xPath.get();
StringBuffer path(xPath.get());
const char* value = values.item(i);
if (!isEmptyString(value))
{
Expand Down Expand Up @@ -7221,7 +7221,7 @@ class CEnvironmentClusterInfo: implements IConstWUClusterInfo, public CInterface
getRoxieProcessServers(roxie, roxieServers);
clusterWidth = roxieServers.length();
ldapUser.set(roxie->queryProp("@ldapUser"));
StringBuffer encPassword = roxie->queryProp("@ldapPassword");
StringBuffer encPassword (roxie->queryProp("@ldapPassword"));
if (encPassword.length())
decrypt(ldapPassword, encPassword);
const char *redundancyMode = roxie->queryProp("@slaveConfig");
Expand Down Expand Up @@ -7385,7 +7385,7 @@ extern WORKUNIT_API void getDFUServerQueueNames(StringArray &ret, const char *pr
Owned<IEnvironmentFactory> factory = getEnvironmentFactory(true);
Owned<IConstEnvironment> env = factory->openEnvironment();

StringBuffer xpath = "Software/DfuServerProcess";
StringBuffer xpath ("Software/DfuServerProcess");
if (!isEmptyString(process))
xpath.appendf("[@name=\"%s\"]", process);

Expand Down Expand Up @@ -9296,7 +9296,7 @@ bool CLocalWorkUnit::getFieldUsageArray(StringArray & filenames, StringArray & c
{
Owned<IConstWUFileUsage> file = files->get();

StringBuffer filename = file->queryName();
StringBuffer filename(file->queryName());
size32_t length = filename.length();

if (length == 0)
Expand Down
2 changes: 1 addition & 1 deletion dali/daliadmin/daliadmin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3031,7 +3031,7 @@ static void migrateFiles(const char *srcGroup, const char *tgtGroup, const char
try
{
bool doCommit = false;
StringBuffer _tgtClusterGroupText = tgtClusterGroupText;
StringBuffer _tgtClusterGroupText(tgtClusterGroupText);

Owned<IFileDescriptor> fileDesc = deserializeFileDescriptorTree(&root, &queryNamedGroupStore());
unsigned numClusters = fileDesc->numClusters();
Expand Down
17 changes: 0 additions & 17 deletions dali/dfu/dfurunkdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,6 @@

#define FULL_TRACE

static StringBuffer appendb32(StringBuffer &out,unsigned v)
{
if (out.length())
out.append('_');
while (v) {
byte b = (byte)(v%32);
v /= 32;
if (b<26)
out.append((char)(b+'a'));
else
out.append((char)(b-26+'0'));
}
return out;
}



class CDKDPitem : public CInterface
{
SocketEndpoint ep;
Expand Down
2 changes: 1 addition & 1 deletion dali/sasha/saarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ void WUiterate(ISashaCommand *cmd, const char *mask)
cmd->addId(wuid);
else
{
StringBuffer output = wuTree->queryName();
StringBuffer output(wuTree->queryName());
//Append more into the output.
setWUDataTree(wuTree, output);
cmd->addId(output.str());
Expand Down
10 changes: 5 additions & 5 deletions deployment/configenv/xml_jlibpt/ComponentFromXSD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ ComponentFromXSD::~ComponentFromXSD()
}

void ComponentFromXSD::CreateAttributeFromSchema(IPropertyTree& attr,
StringBuffer compName, const char* childElementName)
const char *compName, const char* childElementName)
{
StringBuffer attrname;
StringBuffer strBuf;
Expand Down Expand Up @@ -128,7 +128,7 @@ void ComponentFromXSD::CreateAttributeFromSchema(IPropertyTree& attr,
}

void ComponentFromXSD::AddAttributeFromSchema(IPropertyTree& schemaNode,
StringBuffer elemName, StringBuffer& compName, const char* childElementName)
const char *elemName, StringBuffer& compName, const char* childElementName)
{
CreateAttributeFromSchema(schemaNode, compName, childElementName);
}
Expand Down Expand Up @@ -422,7 +422,7 @@ void ComponentFromXSD::setCompTree(const char* buildSetName, IPropertyTree* pTre
}

void ComponentFromXSD::getValueForTypeInXSD(IPropertyTree& attr,
StringBuffer compName, StringBuffer& wizDefVal)
const char *compName, StringBuffer& wizDefVal)
{
StringBuffer tempPath;
const char* type = attr.queryProp("@type");
Expand All @@ -449,7 +449,7 @@ void ComponentFromXSD::getValueForTypeInXSD(IPropertyTree& attr,
}
else if (!strcmp(attr.queryProp(tempPath.str()), "$processname"))
{
tempPath.clear().appendf("Software/%s[1]/@name",compName.str());
tempPath.clear().appendf("Software/%s[1]/@name",compName);
wizDefVal.clear().append(m_pEnv->queryProp(tempPath.str()));
}
else if(!strcmp(attr.queryProp(tempPath.str()), "$hthorcluster"))
Expand All @@ -473,7 +473,7 @@ void ComponentFromXSD::getValueForTypeInXSD(IPropertyTree& attr,
else
{
wizDefVal.clear().append(attr.queryProp(tempPath.str()));
tempPath.clear().appendf("Software/%s[1]/@buildSet", compName.str());
tempPath.clear().appendf("Software/%s[1]/@buildSet", compName);
if (m_pEnv->queryProp(tempPath.str()))
{
SWProcess * swp = (SWProcess *)m_eh->getEnvSWComp(m_buildSetName.str());
Expand Down
6 changes: 3 additions & 3 deletions deployment/configenv/xml_jlibpt/ComponentFromXSD.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ class ComponentFromXSD
~ComponentFromXSD();

void CreateAttributeFromSchema(IPropertyTree& attr,
StringBuffer compName, const char* childElementName);
const char * compName, const char* childElementName);
void AddAttributeFromSchema(IPropertyTree& schemaNode,
StringBuffer elemName, StringBuffer& compName, const char* childElementName);
const char *elemName, StringBuffer& compName, const char* childElementName);
void AddAttributesFromSchema(IPropertyTree* pSchema,
StringBuffer& compName, const char* childElementName);
void ProcessElementSchemaNode(IPropertyTree* pElement,
Expand All @@ -50,7 +50,7 @@ class ComponentFromXSD
void setCompTree(const char* buildSetName, IPropertyTree* pTree, IPropertyTree* schemaTree, bool allSubTypes);
void setWizardFlag(bool flag) { m_wizFlag = flag; }
void setGenerateOptional(bool flag) { m_genOptional = flag; }
void getValueForTypeInXSD(IPropertyTree& attr, StringBuffer compName, StringBuffer& wizDefVal);
void getValueForTypeInXSD(IPropertyTree& attr, const char *compName, StringBuffer& wizDefVal);

private:

Expand Down
2 changes: 1 addition & 1 deletion deployment/configenv/xml_jlibpt/ConfigEnv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void ConfigEnv::create(IPropertyTree *params)
int roxieNodes=1, thorNodes=1, slavesPerNode=1, supportNodes=1,
espNodes=1, thorChannelsPerSlave=1, roxieChannelsPerSlave=1;
bool roxieOnDemand = true;
MapStringTo<StringBuffer> dirMap;
MapStringTo<StringAttr, const char *> dirMap;
Owned<IPropertyTree> pCfg = createPTreeFromXMLFile(ESP_CONFIG_PATH);
StringArray arrAssignIPRanges;
StringArray arrBuildSetWithAssignedIPs;
Expand Down
2 changes: 1 addition & 1 deletion deployment/configenv/xml_jlibpt/SWComponentBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ IPropertyTree * SWComponentBase::addComponent(IPropertyTree *params)

IPropertyTree * envTree = m_envHelper->getEnvTree();

StringBuffer deployable = m_pBuildSet->queryProp("@" TAG_DEPLOYABLE);
const char *deployable = m_pBuildSet->queryProp("@" TAG_DEPLOYABLE);

IPropertyTree * pt = NULL;

Expand Down
4 changes: 2 additions & 2 deletions deployment/configgen/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ int processRequest(const char* in_cfgname, const char* out_dirname, const char*
{
//first, build a map of all ldapServer/IP
StringBuffer sb1,sb2;
typedef MapStringTo<StringBuffer> strMap;
typedef MapStringTo<StringAttr, const char *> strMap;
strMap ldapServers;
{
xPath.appendf("Software/%s/", XML_TAG_LDAPSERVERPROCESS);
Expand Down Expand Up @@ -430,7 +430,7 @@ int processRequest(const char* in_cfgname, const char* out_dirname, const char*
//If this is ldap server name, lookup and add its IP address
if (0==strcmp(attrs->queryName(), "@name"))
{
StringBuffer * ldapIP = ldapServers.getValue(attrs->queryValue());
StringAttr * ldapIP = ldapServers.getValue(attrs->queryValue());
if (ldapIP)
{
out.appendf("@ldapAddress,%s\n",ldapIP->str());
Expand Down
6 changes: 3 additions & 3 deletions deployment/deploy/DeployTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1938,12 +1938,12 @@ class CDeployTask : public CInterface, implements IDeployTask
virtual IDeploymentCallback& getCallback() const { return *m_pCallback; }

private:
char* getMD5Checksum(StringBuffer filename, char* digestStr)
char* getMD5Checksum(const char *filename, char* digestStr)
{
if (filename.length() < 1)
if (isEmptyString(filename))
return NULL;

if (!checkFileExists(filename.str()))
if (!checkFileExists(filename))
return NULL;

OwnedIFile ifile = createIFile(filename);
Expand Down
Loading

0 comments on commit 9ff9bae

Please sign in to comment.