From 6fc4cd86806b349c804cf9dacb2dd04c289a684f Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 25 Jun 2010 08:48:59 -0400 Subject: Fix or cast integer conversions in cmake These were revealed by GCC's -Wconversion option. Fix types where it is easy to do so. Cast in cases we know the integer will not be truncated. --- Source/cmELF.cxx | 2 +- Source/cmGlobalUnixMakefileGenerator3.cxx | 5 +++-- Source/cmGlobalUnixMakefileGenerator3.h | 2 +- Source/cmStringCommand.cxx | 2 +- Source/cmSystemTools.cxx | 6 +++--- Source/cm_utf8.c | 4 ++-- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Source/cmELF.cxx b/Source/cmELF.cxx index 147f6ac..c198727 100644 --- a/Source/cmELF.cxx +++ b/Source/cmELF.cxx @@ -576,7 +576,7 @@ unsigned int cmELFInternalImpl::GetDynamicEntryCount() return i; } } - return this->DynamicSectionEntries.size(); + return static_cast(this->DynamicSectionEntries.size()); } //---------------------------------------------------------------------------- diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx index b687fe1..4e8e7e6 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.cxx +++ b/Source/cmGlobalUnixMakefileGenerator3.cxx @@ -750,8 +750,9 @@ cmGlobalUnixMakefileGenerator3 cmLocalGenerator::FULL, cmLocalGenerator::SHELL); progCmd << " "; - std::vector &progFiles = this->ProgressMap[&t->second].Marks; - for (std::vector::iterator i = progFiles.begin(); + std::vector& progFiles = + this->ProgressMap[&t->second].Marks; + for (std::vector::iterator i = progFiles.begin(); i != progFiles.end(); ++i) { progCmd << " " << *i; diff --git a/Source/cmGlobalUnixMakefileGenerator3.h b/Source/cmGlobalUnixMakefileGenerator3.h index 401888f..f499536 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.h +++ b/Source/cmGlobalUnixMakefileGenerator3.h @@ -177,7 +177,7 @@ protected: TargetProgress(): NumberOfActions(0) {} unsigned long NumberOfActions; std::string VariableFile; - std::vector Marks; + std::vector Marks; void WriteProgressVariables(unsigned long total, unsigned long& current); }; struct ProgressMapCompare { bool operator()(cmTarget*,cmTarget*) const; }; diff --git a/Source/cmStringCommand.cxx b/Source/cmStringCommand.cxx index 3bd47a4..19f5c0f 100644 --- a/Source/cmStringCommand.cxx +++ b/Source/cmStringCommand.cxx @@ -739,7 +739,7 @@ bool cmStringCommand alphabet = cmStringCommandDefaultAlphabet; } - double sizeofAlphabet = alphabet.size(); + double sizeofAlphabet = static_cast(alphabet.size()); if ( sizeofAlphabet < 1 ) { this->SetError("sub-command RANDOM invoked with bad alphabet."); diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 5f7cfa3..5be53c2 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -1204,6 +1204,7 @@ bool cmSystemTools::ComputeFileMD5(const char* source, char* md5out) // Should be efficient enough on most system: const int bufferSize = 4096; char buffer[bufferSize]; + unsigned char const* buffer_uc = reinterpret_cast(buffer); // This copy loop is very sensitive on certain platforms with // slightly broken stream libraries (like HPUX). Normally, it is // incorrect to not check the error condition on the fin.read() @@ -1212,10 +1213,9 @@ bool cmSystemTools::ComputeFileMD5(const char* source, char* md5out) while(fin) { fin.read(buffer, bufferSize); - if(fin.gcount()) + if(int gcount = static_cast(fin.gcount())) { - cmsysMD5_Append(md5, reinterpret_cast(buffer), - fin.gcount()); + cmsysMD5_Append(md5, buffer_uc, gcount); } } cmsysMD5_FinalizeHex(md5, md5out); diff --git a/Source/cm_utf8.c b/Source/cm_utf8.c index 3d4ca16..9c11f2b 100644 --- a/Source/cm_utf8.c +++ b/Source/cm_utf8.c @@ -50,7 +50,7 @@ const char* cm_utf8_decode_character(const char* first, const char* last, unsigned int* pc) { /* Count leading ones in the first byte. */ - unsigned char c = *first++; + unsigned char c = (unsigned char)*first++; unsigned char const ones = cm_utf8_ones[c]; switch(ones) { @@ -65,7 +65,7 @@ const char* cm_utf8_decode_character(const char* first, const char* last, unsigned char left; for(left = ones-1; left && first != last; --left) { - c = *first++; + c = (unsigned char)*first++; if(cm_utf8_ones[c] != 1) { return 0; -- cgit v0.12 From ff1f8d0b53c37336645d4d53fc30134540d17ddd Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 29 Jun 2010 09:52:12 -0400 Subject: Fix or cast more integer conversions in cmake These were revealed by GCC's -Wconversion option. Fix types where it is easy to do so. Cast in cases we know the integer will not be truncated. --- Source/CursesDialog/cmCursesLongMessageForm.cxx | 8 ++++---- Source/CursesDialog/cmCursesMainForm.cxx | 12 ++++++------ Source/CursesDialog/cmCursesMainForm.h | 2 +- Source/cmCTest.cxx | 4 ++-- Source/cmSystemTools.cxx | 8 ++++---- Source/cm_utf8.c | 2 +- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Source/CursesDialog/cmCursesLongMessageForm.cxx b/Source/CursesDialog/cmCursesLongMessageForm.cxx index c66147b..1c48d8c 100644 --- a/Source/CursesDialog/cmCursesLongMessageForm.cxx +++ b/Source/CursesDialog/cmCursesLongMessageForm.cxx @@ -53,13 +53,13 @@ void cmCursesLongMessageForm::UpdateStatusBar() getmaxyx(stdscr, y, x); char bar[cmCursesMainForm::MAX_WIDTH]; - int size = strlen(this->Title.c_str()); + size_t size = strlen(this->Title.c_str()); if ( size >= cmCursesMainForm::MAX_WIDTH ) { size = cmCursesMainForm::MAX_WIDTH-1; } strncpy(bar, this->Title.c_str(), size); - for(int i=size-1; iGetPage(), this->NumberOfPages); - curses_move(0,65-strlen(firstLine)-1); + curses_move(0,65-static_cast(strlen(firstLine))-1); printw(firstLine); } // } @@ -526,8 +526,8 @@ void cmCursesMainForm::UpdateStatusBar(const char* message) // Join the key, help string and pad with spaces // (or truncate) as necessary char bar[cmCursesMainForm::MAX_WIDTH]; - int i, curFieldLen = strlen(curField); - int helpLen = strlen(help); + size_t i, curFieldLen = strlen(curField); + size_t helpLen = strlen(help); int width; if (x < cmCursesMainForm::MAX_WIDTH ) @@ -592,7 +592,7 @@ void cmCursesMainForm::UpdateStatusBar(const char* message) char version[cmCursesMainForm::MAX_WIDTH]; char vertmp[128]; sprintf(vertmp,"CMake Version %s", cmVersion::GetCMakeVersion()); - int sideSpace = (width-strlen(vertmp)); + size_t sideSpace = (width-strlen(vertmp)); for(i=0; iEntries->size(); + size_t size = this->Entries->size(); for(int i=0; i < size; i++) { cmCacheManager::CacheIterator it = @@ -866,7 +866,7 @@ void cmCursesMainForm::HandleInput() std::string searchstr = "Search: " + this->SearchString; this->UpdateStatusBar( searchstr.c_str() ); this->PrintKeys(1); - curses_move(y-5,searchstr.size()); + curses_move(y-5,static_cast(searchstr.size())); //curses_move(1,1); touchwin(stdscr); refresh(); diff --git a/Source/CursesDialog/cmCursesMainForm.h b/Source/CursesDialog/cmCursesMainForm.h index 9751999..4084415 100644 --- a/Source/CursesDialog/cmCursesMainForm.h +++ b/Source/CursesDialog/cmCursesMainForm.h @@ -147,7 +147,7 @@ protected: // Where is cmake executable std::string WhereCMake; // Number of entries shown (depends on mode -normal or advanced-) - int NumberOfVisibleEntries; + size_t NumberOfVisibleEntries; bool AdvancedMode; // Did the iteration converge (no new entries) ? bool OkToGenerate; diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index bd69d6c..4d56257 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -1169,7 +1169,7 @@ int cmCTest::RunMakeCommand(const char* command, std::string* output, if ( tick % tick_line_len == 0 && tick > 0 ) { cmCTestLog(this, HANDLER_OUTPUT, " Size: " - << int((output->size() / 1024.0) + 1) << "K" << std::endl + << int((double(output->size()) / 1024.0) + 1) << "K" << std::endl << " " << std::flush); } } @@ -1181,7 +1181,7 @@ int cmCTest::RunMakeCommand(const char* command, std::string* output, } } cmCTestLog(this, OUTPUT, " Size of output: " - << int(output->size() / 1024.0) << "K" << std::endl); + << int(double(output->size()) / 1024.0) << "K" << std::endl); cmsysProcess_WaitForExit(cp, 0); diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 5be53c2..0badbba 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -1989,9 +1989,9 @@ namespace{ # pragma warn -8066 /* unreachable code */ #endif -int copy_data(struct archive *ar, struct archive *aw) +long copy_data(struct archive *ar, struct archive *aw) { - int r; + long r; const void *buff; size_t size; off_t offset; @@ -2136,7 +2136,7 @@ int cmSystemTools::WaitForLine(cmsysProcess* process, std::string& line, } else if(*outiter == '\n' || *outiter == '\0') { - int length = outiter-out.begin(); + std::vector::size_type length = outiter-out.begin(); if(length > 1 && *(outiter-1) == '\r') { --length; @@ -2159,7 +2159,7 @@ int cmSystemTools::WaitForLine(cmsysProcess* process, std::string& line, } else if(*erriter == '\n' || *erriter == '\0') { - int length = erriter-err.begin(); + std::vector::size_type length = erriter-err.begin(); if(length > 1 && *(erriter-1) == '\r') { --length; diff --git a/Source/cm_utf8.c b/Source/cm_utf8.c index 9c11f2b..c9bf259 100644 --- a/Source/cm_utf8.c +++ b/Source/cm_utf8.c @@ -62,7 +62,7 @@ const char* cm_utf8_decode_character(const char* first, const char* last, /* Extract bits from this multi-byte character. */ { unsigned int uc = c & cm_utf8_mask[ones]; - unsigned char left; + int left; for(left = ones-1; left && first != last; --left) { c = (unsigned char)*first++; -- cgit v0.12 From fec71d80165a74c423b8c56b00993ab4fb917041 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 29 Jun 2010 11:09:36 -0400 Subject: Fix signed/unsigned comparison warnings in ccmake Commit ff1f8d0b (Fix or cast more integer conversions in cmake) changed a member type from int to size_t. Update the types of variables compared to these values to be unsigned also. --- Source/CursesDialog/cmCursesMainForm.cxx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Source/CursesDialog/cmCursesMainForm.cxx b/Source/CursesDialog/cmCursesMainForm.cxx index 805d5ec..389ec7f 100644 --- a/Source/CursesDialog/cmCursesMainForm.cxx +++ b/Source/CursesDialog/cmCursesMainForm.cxx @@ -242,7 +242,7 @@ void cmCursesMainForm::RePost() // Assign the fields: 3 for each entry: label, new entry marker // ('*' or ' ') and entry widget this->Fields = new FIELD*[3*this->NumberOfVisibleEntries+1]; - int cc; + size_t cc; for ( cc = 0; cc < 3 * this->NumberOfVisibleEntries+1; cc ++ ) { this->Fields[cc] = 0; @@ -529,7 +529,7 @@ void cmCursesMainForm::UpdateStatusBar(const char* message) size_t i, curFieldLen = strlen(curField); size_t helpLen = strlen(help); - int width; + size_t width; if (x < cmCursesMainForm::MAX_WIDTH ) { width = x; @@ -796,7 +796,7 @@ void cmCursesMainForm::RemoveEntry(const char* value) void cmCursesMainForm::FillCacheManagerFromUI() { size_t size = this->Entries->size(); - for(int i=0; i < size; i++) + for(size_t i=0; i < size; i++) { cmCacheManager::CacheIterator it = this->CMakeInstance->GetCacheManager()->GetCacheIterator( @@ -961,7 +961,7 @@ void cmCursesMainForm::HandleInput() else if ( key == KEY_DOWN || key == ctrl('n') ) { FIELD* cur = current_field(this->Form); - int findex = field_index(cur); + size_t findex = field_index(cur); if ( findex == 3*this->NumberOfVisibleEntries-1 ) { continue; @@ -1108,7 +1108,7 @@ void cmCursesMainForm::HandleInput() { this->OkToGenerate = false; FIELD* cur = current_field(this->Form); - int findex = field_index(cur); + size_t findex = field_index(cur); // make the next or prev. current field after deletion // each entry consists of fields: label, isnew, value @@ -1199,7 +1199,7 @@ void cmCursesMainForm::JumpToCacheEntry(int idx, const char* astr) str = cmSystemTools::LowerCase(astr); } - if ( idx > this->NumberOfVisibleEntries ) + if ( size_t(idx) > this->NumberOfVisibleEntries ) { return; } @@ -1232,7 +1232,7 @@ void cmCursesMainForm::JumpToCacheEntry(int idx, const char* astr) } } } - if ( findex >= 3* this->NumberOfVisibleEntries-1 ) + if ( size_t(findex) >= 3* this->NumberOfVisibleEntries-1 ) { set_current_field(this->Form, this->Fields[2]); } -- cgit v0.12 From 050af165bb7cc8e6c44121592b07a379cd691cec Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 30 Jun 2010 09:57:07 -0400 Subject: Fix integer conversions in cpack These were revealed by GCC's -Wconversion option. --- Source/CPack/cmCPackDebGenerator.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/CPack/cmCPackDebGenerator.cxx b/Source/CPack/cmCPackDebGenerator.cxx index 9c77cc1..cee24ef 100644 --- a/Source/CPack/cmCPackDebGenerator.cxx +++ b/Source/CPack/cmCPackDebGenerator.cxx @@ -135,7 +135,7 @@ int cmCPackDebGenerator::CompressFiles(const char* outFileName, // now add all directories which have to be compressed // collect all top level install dirs for that // e.g. /opt/bin/foo, /usr/bin/bar and /usr/bin/baz would give /usr and /opt - int topLevelLength = strlen(toplevel); + size_t topLevelLength = strlen(toplevel); std::set installDirs; for (std::vector::const_iterator fileIt = files.begin(); fileIt != files.end(); ++ fileIt ) @@ -371,7 +371,7 @@ static const char * ar_rname(const char *path) typedef struct ar_hdr HDR; static char ar_hb[sizeof(HDR) + 1]; /* real header */ -static int ar_already_written; +static size_t ar_already_written; /* copy_ar -- * Copy size bytes from one file to another - taking care to handle the @@ -431,7 +431,7 @@ static int put_arobj(CF *cfp, struct stat *sb) /* If not truncating names and the name is too long or contains * a space, use extended format 1. */ - unsigned int lname = strlen(name); + size_t lname = strlen(name); uid_t uid = sb->st_uid; gid_t gid = sb->st_gid; if (uid > USHRT_MAX) { @@ -441,7 +441,7 @@ static int put_arobj(CF *cfp, struct stat *sb) gid = USHRT_MAX; } if (lname > sizeof(hdr->ar_name) || strchr(name, ' ')) - (void)sprintf(ar_hb, HDR1, AR_EFMT1, lname, + (void)sprintf(ar_hb, HDR1, AR_EFMT1, (int)lname, (long int)sb->st_mtime, uid, gid, sb->st_mode, (long long)sb->st_size + lname, ARFMAG); else { -- cgit v0.12