gcc: Fixed some compiler warnings when using -Wsign-conversion. Ticket: #1487

This commit is contained in:
Daniel Marjamäki 2010-08-06 19:38:21 +02:00
parent 3adfc61eca
commit 290d02780f
2 changed files with 26 additions and 26 deletions

View File

@ -41,7 +41,7 @@ Preprocessor::Preprocessor(Settings *settings, ErrorLogger *errorLogger) : _sett
} }
void Preprocessor::writeError(const std::string &fileName, const int linenr, ErrorLogger *errorLogger, const std::string &errorType, const std::string &errorText) void Preprocessor::writeError(const std::string &fileName, const unsigned int linenr, ErrorLogger *errorLogger, const std::string &errorType, const std::string &errorText)
{ {
if (!errorLogger) if (!errorLogger)
return; return;
@ -183,7 +183,7 @@ std::string Preprocessor::read(std::istream &istr, const std::string &filename,
// Just some code.. // Just some code..
else else
{ {
code << std::string(1, ch); code << char(ch);
// if there has been <backspace><newline> sequences, add extra newlines.. // if there has been <backspace><newline> sequences, add extra newlines..
if (ch == '\n' && newlines > 0) if (ch == '\n' && newlines > 0)
@ -209,7 +209,7 @@ static bool hasbom(const std::string &str)
std::string Preprocessor::removeComments(const std::string &str, const std::string &filename, Settings *settings) std::string Preprocessor::removeComments(const std::string &str, const std::string &filename, Settings *settings)
{ {
// For the error report // For the error report
int lineno = 1; unsigned int lineno = 1;
// handling <backspace><newline> // handling <backspace><newline>
// when this is encountered the <backspace><newline> will be "skipped". // when this is encountered the <backspace><newline> will be "skipped".
@ -219,9 +219,9 @@ std::string Preprocessor::removeComments(const std::string &str, const std::stri
unsigned char previous = 0; unsigned char previous = 0;
std::vector<std::string> suppressionIDs; std::vector<std::string> suppressionIDs;
for (std::string::size_type i = hasbom(str) ? 3 : 0; i < str.length(); ++i) for (std::string::size_type i = static_cast<unsigned char>(hasbom(str) ? 3 : 0); i < str.length(); ++i)
{ {
unsigned char ch = str[i]; unsigned char ch = static_cast<unsigned char>(str[i]);
if (ch & 0x80) if (ch & 0x80)
{ {
std::ostringstream errmsg; std::ostringstream errmsg;
@ -294,7 +294,7 @@ std::string Preprocessor::removeComments(const std::string &str, const std::stri
{ {
chPrev = ch; chPrev = ch;
++i; ++i;
ch = str[i]; ch = static_cast<unsigned char>(str[i]);
if (ch == '\n') if (ch == '\n')
{ {
++newlines; ++newlines;
@ -306,8 +306,8 @@ std::string Preprocessor::removeComments(const std::string &str, const std::stri
// String or char constants.. // String or char constants..
else if (ch == '\"' || ch == '\'') else if (ch == '\"' || ch == '\'')
{ {
code << std::string(1, ch); code << char(ch);
unsigned char chNext; char chNext;
do do
{ {
++i; ++i;
@ -320,15 +320,15 @@ std::string Preprocessor::removeComments(const std::string &str, const std::stri
++newlines; ++newlines;
else else
{ {
code << std::string(1, chNext); code << chNext;
code << std::string(1, chSeq); code << chSeq;
previous = chSeq; previous = static_cast<unsigned char>(chSeq);
} }
} }
else else
{ {
code << std::string(1, chNext); code << chNext;
previous = chNext; previous = static_cast<unsigned char>(chNext);
} }
} }
while (i < str.length() && chNext != ch && chNext != '\n'); while (i < str.length() && chNext != ch && chNext != '\n');
@ -344,7 +344,7 @@ std::string Preprocessor::removeComments(const std::string &str, const std::stri
} }
else else
{ {
code << std::string(1, ch); code << char(ch);
previous = ch; previous = ch;
} }
@ -514,11 +514,11 @@ void Preprocessor::preprocess(std::istream &istr, std::map<std::string, std::str
std::string Preprocessor::removeSpaceNearNL(const std::string &str) std::string Preprocessor::removeSpaceNearNL(const std::string &str)
{ {
std::string tmp; std::string tmp;
int prev = -1; char prev = 0;
for (unsigned int i = 0; i < str.size(); i++) for (unsigned int i = 0; i < str.size(); i++)
{ {
if (str[i] == ' ' && if (str[i] == ' ' &&
((i > 0 && tmp[prev] == '\n') || ((i > 0 && prev == '\n') ||
(i + 1 < str.size() && str[i+1] == '\n') (i + 1 < str.size() && str[i+1] == '\n')
) )
) )
@ -528,7 +528,7 @@ std::string Preprocessor::removeSpaceNearNL(const std::string &str)
else else
{ {
tmp.append(1, str[i]); tmp.append(1, str[i]);
++prev; prev = str[i];
} }
} }
@ -992,7 +992,7 @@ std::list<std::string> Preprocessor::getcfgs(const std::string &filedata, const
for (std::string::size_type pos = 0; pos < s.length(); ++pos) for (std::string::size_type pos = 0; pos < s.length(); ++pos)
{ {
const unsigned char c = s[pos]; const unsigned char c = static_cast<unsigned char>(s[pos]);
// ok with ";" // ok with ";"
if (c == ';') if (c == ';')
@ -1339,7 +1339,7 @@ Preprocessor::HeaderTypes Preprocessor::getHeaderFileName(std::string &str)
return NoHeader; return NoHeader;
} }
unsigned char c = str[i]; char c = str[i];
if (c == '<') if (c == '<')
c = '>'; c = '>';
@ -1493,7 +1493,7 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filePath
*/ */
static void skipstring(const std::string &line, std::string::size_type &pos) static void skipstring(const std::string &line, std::string::size_type &pos)
{ {
const unsigned char ch = line[pos]; const char ch = line[pos];
++pos; ++pos;
while (pos < line.size() && line[pos] != ch) while (pos < line.size() && line[pos] != ch)
@ -1923,23 +1923,23 @@ static bool getlines(std::istream &istr, std::string &line)
return false; return false;
line = ""; line = "";
int parlevel = 0; int parlevel = 0;
for (unsigned char ch = (unsigned char)istr.get(); istr.good(); ch = (unsigned char)istr.get()) for (char ch = istr.get(); istr.good(); ch = istr.get())
{ {
if (ch == '\'' || ch == '\"') if (ch == '\'' || ch == '\"')
{ {
line += ch; line += ch;
unsigned char c = 0; char c = 0;
while (istr.good() && c != ch) while (istr.good() && c != ch)
{ {
if (c == '\\') if (c == '\\')
{ {
c = (unsigned char)istr.get(); c = istr.get();
if (!istr.good()) if (!istr.good())
return true; return true;
line += c; line += c;
} }
c = (unsigned char)istr.get(); c = istr.get();
if (!istr.good()) if (!istr.good())
return true; return true;
if (c == '\n' && line.compare(0, 1, "#") == 0) if (c == '\n' && line.compare(0, 1, "#") == 0)
@ -1957,7 +1957,7 @@ static bool getlines(std::istream &istr, std::string &line)
if (line.compare(0, 1, "#") == 0) if (line.compare(0, 1, "#") == 0)
return true; return true;
if ((char)istr.peek() == '#') if (istr.peek() == '#')
{ {
line += ch; line += ch;
return true; return true;

View File

@ -117,7 +117,7 @@ protected:
* @param errorType id string for error * @param errorType id string for error
* @param errorText Plain text * @param errorText Plain text
*/ */
static void writeError(const std::string &fileName, const int linenr, ErrorLogger *errorLogger, const std::string &errorType, const std::string &errorText); static void writeError(const std::string &fileName, const unsigned int linenr, ErrorLogger *errorLogger, const std::string &errorType, const std::string &errorText);
/** /**
* Replace "#if defined" with "#ifdef" where possible * Replace "#if defined" with "#ifdef" where possible