fix several compile warnings (-Wsign-compare)

This commit is contained in:
James Buren 2019-03-01 20:56:46 +01:00 committed by Juergen Daubert
parent decb4e383c
commit 75285a0dd9
5 changed files with 24 additions and 24 deletions

View File

@ -926,7 +926,7 @@ void PrtGet::printDiff()
const map<string, string>& installed = m_pkgDB->installedPackages();
map<string, string>::const_iterator it = installed.begin();
const Package* p = 0;
int count = 0;
size_t count = 0;
COMP_RESULT result;
for ( ; it != installed.end(); ++it ) {
@ -1941,28 +1941,28 @@ void PrtGet::remove()
}
void PrtGet::assertMaxArgCount(int count)
void PrtGet::assertMaxArgCount(size_t count)
{
if ( m_parser->otherArgs().size() > count ) {
argCountFailure(count, "at most");
}
}
void PrtGet::assertExactArgCount(int count)
void PrtGet::assertExactArgCount(size_t count)
{
if ( m_parser->otherArgs().size() != count ) {
argCountFailure(count, "exactly");
}
}
void PrtGet::assertMinArgCount(int count)
void PrtGet::assertMinArgCount(size_t count)
{
if ( m_parser->otherArgs().size() < count ) {
argCountFailure(count, "at least");
}
}
void PrtGet::argCountFailure(int count, const string& specifier)
void PrtGet::argCountFailure(size_t count, const string& specifier)
{
cerr << m_appName << " "
<< m_parser->commandName() << " takes " << specifier << " "

View File

@ -146,10 +146,10 @@ protected:
static const string DEFAULT_CACHE_FILE;
void assertMinArgCount(int count);
void assertMaxArgCount(int count);
void assertExactArgCount(int count);
void argCountFailure(int count, const string& specifier);
void assertMinArgCount(size_t count);
void assertMaxArgCount(size_t count);
void assertExactArgCount(size_t count);
void argCountFailure(size_t count, const string& specifier);
VersionComparator::COMP_RESULT
compareVersions( const string& v1, const string& v2 );

View File

@ -58,18 +58,18 @@ string stripWhiteSpace( const string& s )
return s;
}
int pos = 0;
size_t pos = 0;
string line = s;
string::size_type len = line.length();
size_t len = line.length();
while ( pos < len && isspace( line[pos] ) ) {
++pos;
}
line.erase( 0, pos );
pos = line.length()-1;
while ( pos > -1 && isspace( line[pos] ) ) {
while ( pos != (size_t) -1 && isspace( line[pos] ) ) {
--pos;
}
if ( pos != -1 ) {
if ( pos != (size_t) -1 ) {
line.erase( pos+1 );
}
return line;

View File

@ -39,16 +39,16 @@ COMP_RESULT compareVersions(const string& v1, const string& v2)
tokenizeIntoBlocks(v1, blocks1);
tokenizeIntoBlocks(v2, blocks2);
int blockLen = normalizeVectors(blocks1, blocks2);
size_t blockLen = normalizeVectors(blocks1, blocks2);
for (int i = 0; i < blockLen; ++i) {
for (size_t i = 0; i < blockLen; ++i) {
vector<string> tokens1;
vector<string> tokens2;
split(blocks1[i], '.', tokens1);
split(blocks2[i], '.', tokens2);
int tokLen = normalizeVectors(tokens1, tokens2);
size_t tokLen = normalizeVectors(tokens1, tokens2);
for (int j = 0; j < tokLen; ++j) {
for (size_t j = 0; j < tokLen; ++j) {
if (tokens1[j] == tokens2[j]) {
continue;
}
@ -67,8 +67,8 @@ COMP_RESULT compareVersions(const string& v1, const string& v2)
tokenizeMixed(tokens1[j], subtokens1);
tokenizeMixed(tokens2[j], subtokens2);
int subTokLen = normalizeVectors(subtokens1, subtokens2);
for (int k = 0; k < subTokLen; ++k) {
size_t subTokLen = normalizeVectors(subtokens1, subtokens2);
for (size_t k = 0; k < subTokLen; ++k) {
long sl1 = strtol(subtokens1[k].c_str(), &error1, 10);
long sl2 = strtol(subtokens2[k].c_str(), &error2, 10);
if (*error1 == 0 && *error2 == 0) {
@ -123,9 +123,9 @@ COMP_RESULT compareVersions(const string& v1, const string& v2)
return EQUAL;
}
int normalizeVectors(vector<string>& v1, vector<string>& v2)
size_t normalizeVectors(vector<string>& v1, vector<string>& v2)
{
int length = max(v1.size(), v2.size());
size_t length = max(v1.size(), v2.size());
while (v1.size() < length) {
v1.push_back("-1");
@ -140,14 +140,14 @@ int normalizeVectors(vector<string>& v1, vector<string>& v2)
void tokenizeMixed(const string& s, vector<string>& tokens)
{
vector<bool> digitMask;
for (int i = 0; i < s.length(); ++i) {
for (size_t i = 0; i < s.length(); ++i) {
digitMask.push_back(isdigit(s[i]));
}
bool state = digitMask[0];
string tok;
tok = s[0];
for (int i = 1; i < digitMask.size(); ++i) {
for (size_t i = 1; i < digitMask.size(); ++i) {
if (digitMask[i] != state) {
tokens.push_back(tok);
tok = s[i];

View File

@ -19,7 +19,7 @@ enum COMP_RESULT { LESS, GREATER, EQUAL, UNDEFINED };
COMP_RESULT compareVersions(const string& v1, const string& v2) ;
void tokenizeIntoBlocks(const string& version, vector<string>& blocks);
int normalizeVectors(vector<string>& v1, vector<string>& v2);
size_t normalizeVectors(vector<string>& v1, vector<string>& v2);
void tokenizeMixed(const string& s, vector<string>& tokens);
}