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

View File

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

View File

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

View File

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