From 4663356079da1c578ab0f7762b4c9d87327b80c3 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 11 Aug 2010 09:47:04 -0400 Subject: [PATCH] cmArchiveWrite: Fix signed/unsigned again Some stream libraries return size_t from gcount() and some return ssize_t. Add an explicit cast to ios::streamsize for its return value. Also refactor use of nnext to reduce the use of casts. --- Source/cmArchiveWrite.cxx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Source/cmArchiveWrite.cxx b/Source/cmArchiveWrite.cxx index 88874aa6e..94c97e64e 100644 --- a/Source/cmArchiveWrite.cxx +++ b/Source/cmArchiveWrite.cxx @@ -216,24 +216,24 @@ bool cmArchiveWrite::AddData(const char* file, size_t size) size_t nleft = size; while(nleft > 0) { - cmsys_ios::streamsize nnext = static_cast( - nleft > sizeof(buffer)? sizeof(buffer) : nleft); - fin.read(buffer, nnext); + typedef cmsys_ios::streamsize ssize_type; + size_t const nnext = nleft > sizeof(buffer)? sizeof(buffer) : nleft; + ssize_type const nnext_s = static_cast(nnext); + fin.read(buffer, nnext_s); // Some stream libraries (older HPUX) return failure at end of // file on the last read even if some data were read. Check // gcount instead of trusting the stream error status. - if(fin.gcount() != nnext) + if(static_cast(fin.gcount()) != nnext) { break; } - if(archive_write_data(this->Archive, buffer, - static_cast(nnext)) != nnext) + if(archive_write_data(this->Archive, buffer, nnext) != nnext_s) { this->Error = "archive_write_data: "; this->Error += archive_error_string(this->Archive); return false; } - nleft -= static_cast(nnext); + nleft -= nnext; } if(nleft > 0) {