From eb1e46d57db04a2f94a1a4709a67d8fb8f986400 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C5=BEenan=20Zuki=C4=87?= Date: Tue, 14 Jan 2025 14:03:30 -0500 Subject: [PATCH] COMP: Improve type size correctness --- kwsCheckHeader.cxx | 4 ++-- kwsCheckIndent.cxx | 4 ++-- kwsCheckVariablePerLine.cxx | 2 +- kwsGenerator.cxx | 8 ++++---- kwsParser.cxx | 6 +++--- kwsParser.h | 2 +- kwsXMLReader.cxx | 28 +++++++++++++--------------- kwsXMLReader.h | 2 +- metaCommand.cxx | 10 +++++----- 9 files changed, 32 insertions(+), 34 deletions(-) diff --git a/kwsCheckHeader.cxx b/kwsCheckHeader.cxx index e96b20a6..c65c3ffd 100644 --- a/kwsCheckHeader.cxx +++ b/kwsCheckHeader.cxx @@ -126,7 +126,7 @@ bool Parser::CheckHeader(const char* filename, bool considerSpaceEOL,bool useCVS unsigned int pos = 0; unsigned int posh = 0; - int line = -1; + long line = -1; while((ith != buffer.end()) && (it != m_Buffer.end())) @@ -245,7 +245,7 @@ bool Parser::CheckHeader(const char* filename, bool considerSpaceEOL,bool useCVS //hasError = true; // We report the wrong word and the line - int l = this->GetLineNumber(pos); + long l = this->GetLineNumber(pos); if(l != line) { line = l; diff --git a/kwsCheckIndent.cxx b/kwsCheckIndent.cxx index 1ddd4b01..f568ed4b 100644 --- a/kwsCheckIndent.cxx +++ b/kwsCheckIndent.cxx @@ -413,7 +413,7 @@ bool Parser::CheckIndent(IndentType itype, isCheckingComment = false; } - unsigned int poswithoutcomment = static_cast(this->GetPositionWithoutComments(pos)); + size_t poswithoutcomment = this->GetPositionWithoutComments(pos); if((currentIndent != wantedIndent) && ((inComment @@ -435,7 +435,7 @@ bool Parser::CheckIndent(IndentType itype, auto bracket = static_cast(m_Buffer.find_last_of('{', pos)); if(bracket != -1) { - unsigned int l = static_cast(this->FindPreviousWord(bracket-1,true).size()); + size_t l = this->FindPreviousWord(bracket-1,true).size(); if(this->FindPreviousWord(bracket-l-2,true) == "enum") { isInsideEnum = true; diff --git a/kwsCheckVariablePerLine.cxx b/kwsCheckVariablePerLine.cxx index fdfc1407..0f6c2c01 100644 --- a/kwsCheckVariablePerLine.cxx +++ b/kwsCheckVariablePerLine.cxx @@ -117,7 +117,7 @@ bool Parser::CheckVariablePerLine(unsigned long max) } // Check if we are not at the end of the line bool endofline = true; - int eof = pos+1; + long eof = pos+1; while(eof < (int)line.size()) { if(line[eof] != ' ' && line[eof] != '\n' diff --git a/kwsGenerator.cxx b/kwsGenerator.cxx index b0c988ee..b16c18de 100644 --- a/kwsGenerator.cxx +++ b/kwsGenerator.cxx @@ -553,13 +553,13 @@ bool Generator::GenerateHTML(const char* dir,bool showAllErrors) file << R"()" << std::endl; // To speedup the process we list the lines that have errors - using ErrorLineType = std::pair>; + using ErrorLineType = std::pair>; std::vector errorLines; const Parser::ErrorVectorType errors = (*it).GetErrors(); auto itError = errors.begin(); while (itError != errors.end()) { - for (unsigned int index = (*itError).line; index <= (*itError).line2; + for (unsigned long index = (*itError).line; index <= (*itError).line2; index++) { ErrorLineType errLine; errLine.first = index; @@ -588,7 +588,7 @@ bool Generator::GenerateHTML(const char* dir,bool showAllErrors) for(i=0;i::const_iterator errorLineIt = errorLines.begin(); @@ -859,7 +859,7 @@ void Generator::ExportHTML(std::ostream & output) for(unsigned int i=0;i<(*it).GetNumberOfLines();i++) { // Look in the errors if there is a match for this line - int error = -1; + long error = -1; std::string errorTag = ""; const Parser::ErrorVectorType errors = (*it).GetErrors(); diff --git a/kwsParser.cxx b/kwsParser.cxx index 49910ed7..aefdcedf 100644 --- a/kwsParser.cxx +++ b/kwsParser.cxx @@ -454,7 +454,7 @@ bool Parser::Check(const char* name, const char* value) } std::string v1 = val.substr(0,pos); std::string v2 = val.substr(pos+1,val.length()-pos-1); - this->CheckOperator(std::stoul(v1.c_str()),std::stoul(v2.c_str())); + this->CheckOperator(std::stoul(v1),std::stoul(v2)); } else if(!strcmp(name,"Comma")) { @@ -467,7 +467,7 @@ bool Parser::Check(const char* name, const char* value) } std::string v1 = val.substr(0,pos); std::string v2 = val.substr(pos+1,val.length()-pos-1); - this->CheckComma(std::stoul(v1.c_str()),std::stoul(v2.c_str())); + this->CheckComma(std::stoul(v1),std::stoul(v2)); } else if(!strcmp(name,"Parenthesis")) { @@ -506,7 +506,7 @@ bool Parser::HasBeenPerformed(unsigned int test) const } /** Return the test description given the erro number) */ -std::string Parser::GetTestDescription(unsigned int test) const +std::string Parser::GetTestDescription(size_t test) const { return m_TestsDescription[test]; } diff --git a/kwsParser.h b/kwsParser.h index d587e122..b94d550f 100644 --- a/kwsParser.h +++ b/kwsParser.h @@ -339,7 +339,7 @@ class Parser bool HasBeenPerformed(unsigned int test) const; /** Return the test description given the error number) */ - std::string GetTestDescription(unsigned int test) const; + std::string GetTestDescription(size_t test) const; /** Given the name of the check to perform and the default value perform the check */ bool Check(const char* name, const char* value); diff --git a/kwsXMLReader.cxx b/kwsXMLReader.cxx index f071d5bf..1c0de8c7 100644 --- a/kwsXMLReader.cxx +++ b/kwsXMLReader.cxx @@ -78,9 +78,8 @@ std::string XMLReader::GetTag() comment_start = static_cast(m_Buffer.find("", comment_start)); - if(comment_end!=-1) + auto comment_end = m_Buffer.find("-->", comment_start); + if(comment_end != std::string::npos) { m_CurrentPos=comment_end+3; } @@ -104,9 +103,8 @@ std::string XMLReader::GetTag() std::string m_EndTag = "(m_Buffer.find(m_EndTag, begin_tag_end + 1)); - if(end_tag_begin == -1) + auto end_tag_begin = m_Buffer.find(m_EndTag, begin_tag_end + 1); + if(end_tag_begin == std::string::npos) { std::cout << "XML parsing error, cannot find close tag for " << m_Tag.c_str() << std::endl; @@ -122,26 +120,26 @@ std::string XMLReader::GetTag() // by comas. This assume that the order of the tags is correct and present and // that we only have 1 level in the XML tree. unsigned int i=0; - auto pos1 = static_cast(value.find("<", 0)); - while(pos1 != -1) + auto pos1 = value.find("<", 0); + while(pos1 != std::string::npos) { if(i>0) { m_Value += ","; } - auto pos2 = static_cast(value.find(">", pos1)); - auto pos3 = static_cast(value.find("<", pos2)); - - if (i == 0) { - m_Value = value.substr(pos2 + 1, pos3 - pos2 - 1); + auto pos2 = value.find(">", pos1); + auto pos3 = value.find("<", pos2); + if (i == 0) + { + m_Value = value.substr(pos2 + 1, pos3 - pos2 - 1); } else { - m_Value += value.substr(pos2+1,pos3-pos2-1); + m_Value += value.substr(pos2 + 1, pos3 - pos2 - 1); } - pos1 = static_cast(value.find("<",pos3+1)); + pos1 = value.find("<",pos3 + 1); i++; } return m_Tag; diff --git a/kwsXMLReader.h b/kwsXMLReader.h index 42370e67..21e93096 100644 --- a/kwsXMLReader.h +++ b/kwsXMLReader.h @@ -44,7 +44,7 @@ class XMLReader std::string m_Value; std::string m_Tag; std::string m_Buffer; - unsigned int m_CurrentPos; + size_t m_CurrentPos; }; diff --git a/metaCommand.cxx b/metaCommand.cxx index 48b49ab1..73574203 100644 --- a/metaCommand.cxx +++ b/metaCommand.cxx @@ -1195,9 +1195,9 @@ bool MetaCommand::Parse(int argc, const char* argv[]) bool inArgument = false; METAIO_STL::string tag = ""; - unsigned int currentField = 0; // current field position - int currentOption = 0; // id of the option to fill - unsigned int valuesRemaining=0; + long currentField = 0; // current field position + long currentOption = 0; // id of the option to fill + size_t valuesRemaining=0; bool isComplete = false; // check if the option should be parse until the next tag is found METAIO_STL::string completeString = ""; @@ -1239,7 +1239,7 @@ bool MetaCommand::Parse(int argc, const char* argv[]) if(this->OptionExistsByMinusTag(tag)) { inArgument = true; - valuesRemaining = static_cast(this->GetOptionByMinusTag(tag)->fields.size()); + valuesRemaining = this->GetOptionByMinusTag(tag)->fields.size(); currentOption = this->GetOptionId(this->GetOptionByMinusTag(tag)); if(currentOption < 0) @@ -1290,7 +1290,7 @@ bool MetaCommand::Parse(int argc, const char* argv[]) { // Look for the field to add auto it = m_OptionVector.begin(); - unsigned long pos = 0; + long pos = 0; bool found = false; while(it != m_OptionVector.end()) {