Skip to content

Commit

Permalink
[lldb-mi] Use size_t where appropriate.
Browse files Browse the repository at this point in the history
Summary:
Many places should have been using size_t rather than MIuint or
MIint. This is particularly true for code that uses std::string::find(),
std::string::rfind(), std::string::size(), and related methods.

Reviewers: abidh, ki.stfu, domipheus

Subscribers: lldb-commits

Differential Revision: http://reviews.llvm.org/D10931

llvm-svn: 241360
  • Loading branch information
waywardmonkeys committed Jul 3, 2015
1 parent 201dec7 commit e86c6fa
Show file tree
Hide file tree
Showing 14 changed files with 178 additions and 178 deletions.
14 changes: 7 additions & 7 deletions lldb/tools/lldb-mi/MICmdArgContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,16 @@ CMICmdArgContext::RemoveArg(const CMIUtilString &vArg)
if (vArg.empty())
return MIstatus::success;

const MIuint nLen = vArg.length();
const MIuint nLenCntxt = m_strCmdArgsAndOptions.length();
const size_t nLen = vArg.length();
const size_t nLenCntxt = m_strCmdArgsAndOptions.length();
if (nLen > nLenCntxt)
return MIstatus::failure;

MIuint nExtraSpace = 0;
MIint nPos = m_strCmdArgsAndOptions.find(vArg);
size_t nExtraSpace = 0;
size_t nPos = m_strCmdArgsAndOptions.find(vArg);
while (1)
{
if (nPos == (MIint)std::string::npos)
if (nPos == std::string::npos)
return MIstatus::success;

bool bPass1 = false;
Expand All @@ -106,7 +106,7 @@ CMICmdArgContext::RemoveArg(const CMIUtilString &vArg)
else
bPass1 = true;

const MIuint nEnd = nPos + nLen;
const size_t nEnd = nPos + nLen;

if (bPass1)
{
Expand All @@ -129,7 +129,7 @@ CMICmdArgContext::RemoveArg(const CMIUtilString &vArg)
nPos = m_strCmdArgsAndOptions.find(vArg, nEnd);
}

const MIuint nPosEnd = nLen + nExtraSpace;
const size_t nPosEnd = nLen + nExtraSpace;
m_strCmdArgsAndOptions = m_strCmdArgsAndOptions.replace(nPos, nPosEnd, "").c_str();
m_strCmdArgsAndOptions = m_strCmdArgsAndOptions.Trim();

Expand Down
6 changes: 3 additions & 3 deletions lldb/tools/lldb-mi/MICmdArgValFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ CMICmdArgValFile::GetFileNamePath(const CMIUtilString &vrTxt) const

// Look for a space in the path
const char cSpace = ' ';
const MIint nPos = fileNamePath.find(cSpace);
if (nPos != (MIint)std::string::npos)
const size_t nPos = fileNamePath.find(cSpace);
if (nPos != std::string::npos)
fileNamePath = CMIUtilString::Format("\"%s\"", fileNamePath.c_str());

return fileNamePath;
Expand All @@ -146,7 +146,7 @@ CMICmdArgValFile::IsFilePath(const CMIUtilString &vrFileNamePath) const
const bool bHaveBckSlash = (vrFileNamePath.find_first_of("\\") != std::string::npos);

// Look for --someLongOption
MIint nPos = vrFileNamePath.find_first_of("--");
size_t nPos = vrFileNamePath.find_first_of("--");
const bool bLong = (nPos == 0);
if (bLong)
return false;
Expand Down
2 changes: 1 addition & 1 deletion lldb/tools/lldb-mi/MICmdArgValOptionLong.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ CMICmdArgValOptionLong::IsArgLongOption(const CMIUtilString &vrTxt) const
if (bHavePosSlash || bHaveBckSlash)
return false;

const MIint nPos = vrTxt.find_first_of("--");
const size_t nPos = vrTxt.find_first_of("--");
if (nPos != 0)
return false;

Expand Down
28 changes: 14 additions & 14 deletions lldb/tools/lldb-mi/MICmdArgValString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,12 @@ CMICmdArgValString::IsStringArgQuotedText(const CMIUtilString &vrTxt) const

// CODETAG_QUOTEDTEXT_SIMILAR_CODE
const char cQuote = '"';
const MIint nPos = vrTxt.find(cQuote);
if (nPos == (MIint)std::string::npos)
const size_t nPos = vrTxt.find(cQuote);
if (nPos == std::string::npos)
return false;

// Is one and only quote at end of the string
if (nPos == (MIint)(vrTxt.length() - 1))
if (nPos == (vrTxt.length() - 1))
return false;

// Quote must be the first character in the string or be preceded by a space
Expand All @@ -283,8 +283,8 @@ CMICmdArgValString::IsStringArgQuotedText(const CMIUtilString &vrTxt) const
return false;

// Need to find the other quote
const MIint nPos2 = vrTxt.rfind(cQuote);
if (nPos2 == (MIint)std::string::npos)
const size_t nPos2 = vrTxt.rfind(cQuote);
if (nPos2 == std::string::npos)
return false;

// Make sure not same quote, need two quotes
Expand All @@ -309,8 +309,8 @@ CMICmdArgValString::IsStringArgQuotedTextEmbedded(const CMIUtilString &vrTxt) co
{
// CODETAG_QUOTEDTEXT_SIMILAR_CODE
const char cBckSlash = '\\';
const MIint nPos = vrTxt.find(cBckSlash);
if (nPos == (MIint)std::string::npos)
const size_t nPos = vrTxt.find(cBckSlash);
if (nPos == std::string::npos)
return false;

// Slash must be the first character in the string or be preceded by a space
Expand All @@ -319,8 +319,8 @@ CMICmdArgValString::IsStringArgQuotedTextEmbedded(const CMIUtilString &vrTxt) co
return false;

// Need to find the other matching slash
const MIint nPos2 = vrTxt.rfind(cBckSlash);
if (nPos2 == (MIint)std::string::npos)
const size_t nPos2 = vrTxt.rfind(cBckSlash);
if (nPos2 == std::string::npos)
return false;

// Make sure not same back slash, need two slashes
Expand All @@ -343,15 +343,15 @@ CMICmdArgValString::IsStringArgQuotedTextEmbedded(const CMIUtilString &vrTxt) co
bool
CMICmdArgValString::IsStringArgQuotedQuotedTextEmbedded(const CMIUtilString &vrTxt) const
{
const MIint nPos = vrTxt.find("\"\\\"");
if (nPos == (MIint)std::string::npos)
const size_t nPos = vrTxt.find("\"\\\"");
if (nPos == std::string::npos)
return false;

const MIint nPos2 = vrTxt.rfind("\\\"\"");
if (nPos2 == (MIint)std::string::npos)
const size_t nPos2 = vrTxt.rfind("\\\"\"");
if (nPos2 == std::string::npos)
return false;

const MIint nLen = vrTxt.length();
const size_t nLen = vrTxt.length();
if ((nLen > 5) && ((nPos + 2) == (nPos2 - 2)))
return false;

Expand Down
38 changes: 19 additions & 19 deletions lldb/tools/lldb-mi/MICmdCmdData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1681,8 +1681,8 @@ CMICmdCmdDataInfoLine::Execute(void)
}
else
{
const MIuint nLineStartPos = strLocation.rfind(':');
if ((nLineStartPos == (MIuint)std::string::npos) || (nLineStartPos == 0) || (nLineStartPos == strLocation.length() - 1))
const size_t nLineStartPos = strLocation.rfind(':');
if ((nLineStartPos == std::string::npos) || (nLineStartPos == 0) || (nLineStartPos == strLocation.length() - 1))
{
SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_INVALID_LOCATION_FORMAT), m_cmdData.strMiCmd.c_str(), strLocation.c_str())
.c_str());
Expand Down Expand Up @@ -1739,9 +1739,9 @@ CMICmdCmdDataInfoLine::Acknowledge(void)

// LineEntry: \[0x0000000100000f37-0x0000000100000f45\): /path/to/file:3[:1]
// ^^^^^^^^^ -- property
const MIuint nPropertyStartPos = rLine.find_first_not_of(' ');
const MIuint nPropertyEndPos = rLine.find(':');
const MIuint nPropertyLen = nPropertyEndPos - nPropertyStartPos;
const size_t nPropertyStartPos = rLine.find_first_not_of(' ');
const size_t nPropertyEndPos = rLine.find(':');
const size_t nPropertyLen = nPropertyEndPos - nPropertyStartPos;
const CMIUtilString strProperty(rLine.substr(nPropertyStartPos, nPropertyLen).c_str());

// Skip all except LineEntry
Expand All @@ -1750,18 +1750,18 @@ CMICmdCmdDataInfoLine::Acknowledge(void)

// LineEntry: \[0x0000000100000f37-0x0000000100000f45\): /path/to/file:3[:1]
// ^^^^^^^^^^^^^^^^^^ -- start address
const MIuint nStartAddressStartPos = rLine.find("[");
const MIuint nStartAddressEndPos = rLine.find("-");
const MIuint nStartAddressLen = nStartAddressEndPos - nStartAddressStartPos - 1;
const size_t nStartAddressStartPos = rLine.find("[");
const size_t nStartAddressEndPos = rLine.find("-");
const size_t nStartAddressLen = nStartAddressEndPos - nStartAddressStartPos - 1;
const CMIUtilString strStartAddress(rLine.substr(nStartAddressStartPos + 1, nStartAddressLen).c_str());
const CMICmnMIValueConst miValueConst(strStartAddress);
const CMICmnMIValueResult miValueResult("start", miValueConst);
CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done, miValueResult);

// LineEntry: \[0x0000000100000f37-0x0000000100000f45\): /path/to/file:3[:1]
// ^^^^^^^^^^^^^^^^^^ -- end address
const MIuint nEndAddressEndPos = rLine.find(")");
const MIuint nEndAddressLen = nEndAddressEndPos - nStartAddressEndPos - 1;
const size_t nEndAddressEndPos = rLine.find(")");
const size_t nEndAddressLen = nEndAddressEndPos - nStartAddressEndPos - 1;
const CMIUtilString strEndAddress(rLine.substr(nStartAddressEndPos + 1, nEndAddressLen).c_str());
const CMICmnMIValueConst miValueConst2(strEndAddress);
const CMICmnMIValueResult miValueResult2("end", miValueConst2);
Expand All @@ -1773,11 +1773,11 @@ CMICmdCmdDataInfoLine::Acknowledge(void)
// ^^^^^^^^^^^^^ -- file
// ^ -- line
// ^ -- column (optional)
const MIuint nFileStartPos = rLine.find_first_not_of(' ', nEndAddressEndPos + 2);
const MIuint nFileOrLineEndPos = rLine.rfind(':');
const MIuint nFileOrLineStartPos = rLine.rfind(':', nFileOrLineEndPos - 1);
const MIuint nFileEndPos = nFileStartPos < nFileOrLineStartPos ? nFileOrLineStartPos : nFileOrLineEndPos;
const MIuint nFileLen = nFileEndPos - nFileStartPos;
const size_t nFileStartPos = rLine.find_first_not_of(' ', nEndAddressEndPos + 2);
const size_t nFileOrLineEndPos = rLine.rfind(':');
const size_t nFileOrLineStartPos = rLine.rfind(':', nFileOrLineEndPos - 1);
const size_t nFileEndPos = nFileStartPos < nFileOrLineStartPos ? nFileOrLineStartPos : nFileOrLineEndPos;
const size_t nFileLen = nFileEndPos - nFileStartPos;
const CMIUtilString strFile(rLine.substr(nFileStartPos, nFileLen).c_str());
const CMICmnMIValueConst miValueConst3(strFile);
const CMICmnMIValueResult miValueResult3("file", miValueConst3);
Expand All @@ -1787,10 +1787,10 @@ CMICmdCmdDataInfoLine::Acknowledge(void)

// LineEntry: \[0x0000000100000f37-0x0000000100000f45\): /path/to/file:3[:1]
// ^ -- line
const MIuint nLineStartPos = nFileEndPos + 1;
const MIuint nLineEndPos = rLine.find(':', nLineStartPos);
const MIuint nLineLen = nLineEndPos != (MIuint)std::string::npos ? nLineEndPos - nLineStartPos - 1
: (MIuint)std::string::npos;
const size_t nLineStartPos = nFileEndPos + 1;
const size_t nLineEndPos = rLine.find(':', nLineStartPos);
const size_t nLineLen = nLineEndPos != std::string::npos ? nLineEndPos - nLineStartPos - 1
: std::string::npos;
const CMIUtilString strLine(rLine.substr(nLineStartPos, nLineLen).c_str());
const CMICmnMIValueConst miValueConst4(strLine);
const CMICmnMIValueResult miValueResult4("line", miValueConst4);
Expand Down
8 changes: 4 additions & 4 deletions lldb/tools/lldb-mi/MICmdCmdSymbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,18 @@ CMICmdCmdSymbolListLines::Acknowledge(void)

// 0x0000000100000e70: /path/to/file:3[:4]
// ^^^^^^^^^^^^^^^^^^ -- pc
const MIuint nAddrEndPos = rLine.find(':');
const size_t nAddrEndPos = rLine.find(':');
const CMIUtilString strAddr(rLine.substr(0, nAddrEndPos).c_str());
const CMICmnMIValueConst miValueConst(strAddr);
const CMICmnMIValueResult miValueResult("pc", miValueConst);
CMICmnMIValueTuple miValueTuple(miValueResult);

// 0x0000000100000e70: /path/to/file:3[:4]
// ^ -- line
const MIuint nLineOrColumnStartPos = rLine.rfind(':');
const size_t nLineOrColumnStartPos = rLine.rfind(':');
const CMIUtilString strLineOrColumn(rLine.substr(nLineOrColumnStartPos + 1).c_str());
const MIuint nPathOrLineStartPos = rLine.rfind(':', nLineOrColumnStartPos - 1);
const MIuint nPathOrLineLen = nLineOrColumnStartPos - nPathOrLineStartPos - 1;
const size_t nPathOrLineStartPos = rLine.rfind(':', nLineOrColumnStartPos - 1);
const size_t nPathOrLineLen = nLineOrColumnStartPos - nPathOrLineStartPos - 1;
const CMIUtilString strPathOrLine(rLine.substr(nPathOrLineStartPos + 1, nPathOrLineLen).c_str());
const CMIUtilString strLine(strPathOrLine.IsNumber() ? strPathOrLine : strLineOrColumn);
const CMICmnMIValueConst miValueConst2(strLine);
Expand Down
4 changes: 2 additions & 2 deletions lldb/tools/lldb-mi/MICmdFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ CMICmdFactory::IsValid(const CMIUtilString &vMiCmd) const
return false;
}

const MIint nPos = vMiCmd.find(" ");
if (nPos != (MIint)std::string::npos)
const size_t nPos = vMiCmd.find(" ");
if (nPos != std::string::npos)
bValid = false;

return bValid;
Expand Down
16 changes: 8 additions & 8 deletions lldb/tools/lldb-mi/MICmdInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ bool
CMICmdInterpreter::MiHasCmdTokenEndingHyphen(const CMIUtilString &vTextLine)
{
// The hyphen is mandatory
const MIint nPos = vTextLine.find("-", 0);
if ((nPos == (MIint)std::string::npos))
const size_t nPos = vTextLine.find("-", 0);
if ((nPos == std::string::npos))
return false;

if (MiHasCmdTokenPresent(vTextLine))
Expand Down Expand Up @@ -215,7 +215,7 @@ CMICmdInterpreter::MiHasCmdTokenEndingAlpha(const CMIUtilString &vTextLine)
bool
CMICmdInterpreter::MiHasCmdTokenPresent(const CMIUtilString &vTextLine)
{
const MIint nPos = vTextLine.find("-", 0);
const size_t nPos = vTextLine.find("-", 0);
return (nPos > 0);
}

Expand All @@ -233,11 +233,11 @@ CMICmdInterpreter::MiHasCmdTokenPresent(const CMIUtilString &vTextLine)
bool
CMICmdInterpreter::MiHasCmd(const CMIUtilString &vTextLine)
{
MIint nPos = 0;
size_t nPos = 0;
if (m_miCmdData.bMIOldStyle)
{
char cChar = vTextLine[0];
MIuint i = 0;
size_t i = 0;
while (::isdigit(cChar) != 0)
{
cChar = vTextLine[++i];
Expand All @@ -250,9 +250,9 @@ CMICmdInterpreter::MiHasCmd(const CMIUtilString &vTextLine)
}

bool bFoundCmd = false;
const MIint nLen = vTextLine.length();
const MIint nPos2 = vTextLine.find(" ", nPos);
if (nPos2 != (MIint)std::string::npos)
const size_t nLen = vTextLine.length();
const size_t nPos2 = vTextLine.find(" ", nPos);
if (nPos2 != std::string::npos)
{
if (nPos2 == nLen)
return false;
Expand Down
12 changes: 6 additions & 6 deletions lldb/tools/lldb-mi/MICmnLogMediumFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ CMICmnLogMediumFile::MassagedData(const CMIUtilString &vData, const CMICmnLog::E
data = ConvertCr(data);

// Look for EOL...
const MIint pos = vData.rfind(strCr);
if (pos == (MIint)vData.size())
const size_t pos = vData.rfind(strCr);
if (pos == vData.size())
return data;

// ... did not have an EOL so add one
Expand Down Expand Up @@ -382,11 +382,11 @@ CMICmnLogMediumFile::ConvertCr(const CMIUtilString &vData) const
if (strCr == rCrCmpat)
return vData;

const MIuint nSizeCmpat(rCrCmpat.size());
const MIuint nSize(strCr.size());
const size_t nSizeCmpat(rCrCmpat.size());
const size_t nSize(strCr.size());
CMIUtilString strConv(vData);
MIint pos = strConv.find(strCr);
while (pos != (MIint)CMIUtilString::npos)
size_t pos = strConv.find(strCr);
while (pos != CMIUtilString::npos)
{
strConv.replace(pos, nSize, rCrCmpat);
pos = strConv.find(strCr, pos + nSizeCmpat);
Expand Down
4 changes: 2 additions & 2 deletions lldb/tools/lldb-mi/MIDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ CMIDriver::WrapCLICommandIntoMICommand(const CMIUtilString &vTextLine) const
// Also possible case when command not found:
// 001
// ^ -- i.e. only tokens are present (or empty string at all)
const MIuint nCommandOffset = vTextLine.find_first_not_of(digits);
const size_t nCommandOffset = vTextLine.find_first_not_of(digits);

// 2. Check if command is empty
// For example:
Expand All @@ -872,7 +872,7 @@ CMIDriver::WrapCLICommandIntoMICommand(const CMIUtilString &vTextLine) const
// or:
// 001
// ^ -- command wasn't found
const bool bIsEmptyCommand = (nCommandOffset == (MIuint)CMIUtilString::npos);
const bool bIsEmptyCommand = (nCommandOffset == CMIUtilString::npos);

// 3. Check and exit if it isn't a CLI command
// For example:
Expand Down
2 changes: 1 addition & 1 deletion lldb/tools/lldb-mi/MIDriverMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ CMIDriverMgr::ParseArgs(const int argc, const char *argv[], bool &vwbExiting)
}
if (0 == strArg.compare(0,10,"--log-dir="))
{
strLogDir = strArg.substr(10,CMIUtilString::npos);
strLogDir = strArg.substr(10, CMIUtilString::npos);
bHaveArgLogDir = true;
}
if ((0 == strArg.compare("--help")) || (0 == strArg.compare("-h")))
Expand Down
6 changes: 3 additions & 3 deletions lldb/tools/lldb-mi/MIUtilFileStd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,9 @@ CMIUtilFileStd::GetLineReturn(void) const
CMIUtilString
CMIUtilFileStd::StripOffFileName(const CMIUtilString &vDirectoryPath)
{
const MIint nPos = vDirectoryPath.rfind('\\');
MIint nPos2 = vDirectoryPath.rfind('/');
if ((nPos == (MIint)std::string::npos) && (nPos2 == (MIint)std::string::npos))
const size_t nPos = vDirectoryPath.rfind('\\');
size_t nPos2 = vDirectoryPath.rfind('/');
if ((nPos == std::string::npos) && (nPos2 == std::string::npos))
return vDirectoryPath;

if (nPos > nPos2)
Expand Down
Loading

0 comments on commit e86c6fa

Please sign in to comment.