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.
This commit is contained in:
parent
aef672311a
commit
4663356079
|
@ -216,24 +216,24 @@ bool cmArchiveWrite::AddData(const char* file, size_t size)
|
||||||
size_t nleft = size;
|
size_t nleft = size;
|
||||||
while(nleft > 0)
|
while(nleft > 0)
|
||||||
{
|
{
|
||||||
cmsys_ios::streamsize nnext = static_cast<cmsys_ios::streamsize>(
|
typedef cmsys_ios::streamsize ssize_type;
|
||||||
nleft > sizeof(buffer)? sizeof(buffer) : nleft);
|
size_t const nnext = nleft > sizeof(buffer)? sizeof(buffer) : nleft;
|
||||||
fin.read(buffer, nnext);
|
ssize_type const nnext_s = static_cast<ssize_type>(nnext);
|
||||||
|
fin.read(buffer, nnext_s);
|
||||||
// Some stream libraries (older HPUX) return failure at end of
|
// Some stream libraries (older HPUX) return failure at end of
|
||||||
// file on the last read even if some data were read. Check
|
// file on the last read even if some data were read. Check
|
||||||
// gcount instead of trusting the stream error status.
|
// gcount instead of trusting the stream error status.
|
||||||
if(fin.gcount() != nnext)
|
if(static_cast<size_t>(fin.gcount()) != nnext)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(archive_write_data(this->Archive, buffer,
|
if(archive_write_data(this->Archive, buffer, nnext) != nnext_s)
|
||||||
static_cast<size_t>(nnext)) != nnext)
|
|
||||||
{
|
{
|
||||||
this->Error = "archive_write_data: ";
|
this->Error = "archive_write_data: ";
|
||||||
this->Error += archive_error_string(this->Archive);
|
this->Error += archive_error_string(this->Archive);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
nleft -= static_cast<size_t>(nnext);
|
nleft -= nnext;
|
||||||
}
|
}
|
||||||
if(nleft > 0)
|
if(nleft > 0)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue