const string& fileName, uint64 fileSize, time_t mtime) {
DBT key; memset(&key, 0, sizeof(DBT));
key.data = const_cast<char*>(fileName.c_str());
- key.size = fileName.size();
+ key.size = (u_int32_t)fileName.size(); // filename size is safely
+ // less than 32 bits!
AutoCursor cursor;
// Cursor with no transaction id, no flags
time_t& resultMtime) {
DBT key; memset(&key, 0, sizeof(DBT));
key.data = const_cast<char*>(fileName.c_str());
- key.size = fileName.size();
+ key.size = (u_int32_t)fileName.size(); // filename size is safely
+ // less than 32 bits!
AutoCursor cursor;
// Cursor with no transaction id, no flags
void* tmp = realloc(data.data, USER_DATA + inSize);
if (tmp == 0) throw bad_alloc();
data.data = tmp;
- data.size = USER_DATA + inSize;
+ data.size = (u_int32_t)(USER_DATA + inSize);
return static_cast<byte*>(tmp) + USER_DATA;
}
// Insert in database
DBT key; memset(&key, 0, sizeof(DBT));
key.data = const_cast<char*>(fileName.c_str());
- key.size = fileName.size();
+ key.size = (u_int32_t)fileName.size(); // filename size is safely
+ // less than 32 bits!
db->put(db, 0, &key, &data, 0); // No transaction, overwrite
// cerr << "CacheFile write `"<<fileName<<'\'';
// Absolute minimum for --min-length (i.e. blockLength), in bytes
const size_t MINIMUM_BLOCKLENGTH = 256;
-char optHelp = '\0';
+int optHelp = '\0';
bool optVersion = false;
// Return value of main(), for "delayed error exit"
} else {
/* Same length as previous - to reduce cursor flicker, only redraw
as much as necessary */
- int i = s.size() - 1;
+ ssize_t i = s.size() - 1;
while (i >= 0 && s[i] == prevLine[i]) --i;
- for (int j = 0; j <= i; ++j) cerr << s[j];
+ for (ssize_t j = 0; j <= i; ++j) cerr << s[j];
}
// Should the message just printed be overwritten on next call?
uint64 descLen = 4 + 6*2; // Length of DESC part
unsigned bufLen = 4 + 6;
for (const_iterator i = begin(), e = end(); i != e; ++i) {
- unsigned s = (*i)->serialSizeOf();
+ unsigned s = (unsigned)(*i)->serialSizeOf();
bufLen = max(bufLen, s);
descLen += s;
}
unmatched image data is already compressed, which means that
when it is compressed again by jigdo, it will get slightly
larger. */
- auto_ptr<Zibstream> data(new Zibstream(*templ, readAmount + 8*1024));
+ auto_ptr<Zibstream> data(new Zibstream(*templ, (unsigned int)readAmount + 8*1024));
# if HAVE_WORKING_FSTREAM
if (img == 0) img = &cout; // EEEEEK!
# else
reporter.error(_("Premature end of template data"));
return 3;
}
- data->read(buf, (toWrite < readAmount ? toWrite : readAmount));
+ data->read(buf, (unsigned int)(toWrite < readAmount ? toWrite : readAmount));
size_t n = data->gcount();
writeBytes(*img, buf, n);
reportBytesWritten(n, off, nextReport, totalBytes, reporter);
const size_t bufferLength, Zobstream* zip) {
Paranoid(begin <= bufferLength && end <= bufferLength);
if (begin < end) {
- zip->write(buf + begin, end - begin);
+ zip->write(buf + begin, (unsigned int)(end - begin));
} else {
- zip->write(buf + begin, bufferLength - begin);
- zip->write(buf, end);
+ zip->write(buf + begin, (unsigned int)(bufferLength - begin));
+ zip->write(buf, (unsigned int)end);
}
}
//____________________
readBytes(*inputFile, tmpBuf.get(),
(readAmount < count ? readAmount : count));
size_t n = inputFile->gcount();
- zip->write(tmpBuf.get(), n); // will catch Zerror "upstream"
+ zip->write(tmpBuf.get(), (unsigned int)n); // will catch Zerror "upstream"
Paranoid(n <= count);
count -= n;
}
nextAlignedOff += blockLength;
Assert(nextAlignedOff > off);
- unsigned len = nextAlignedOff - off;
+ unsigned long len = nextAlignedOff - off;
if (len > nextEvent - off) len = nextEvent - off;
// Advance rsum by len bytes in one go
# if DEBUG
}
// Hash table performance drops when linked lists become long => "+1"
- int blockBits = bitWidth(fileCount) + 1;
+ int blockBits = bitWidth((uint32)fileCount) + 1;
uint32 blockMask = (1 << blockBits) - 1;
block.resize(blockMask + 1);
//@{
template<class NumType, class Iterator>
inline Iterator serialize1(NumType x, Iterator i) {
- *i = x & 0xff; ++i;
+ *i = (unsigned char)(x & 0xff); ++i;
return i;
}
template<class NumType, class ConstIterator>
template<class NumType, class Iterator>
inline Iterator serialize4(NumType x, Iterator i) {
- *i = x & 0xff; ++i;
- *i = (x >> 8) & 0xff; ++i;
- *i = (x >> 16) & 0xff; ++i;
- *i = (x >> 24) & 0xff; ++i;
+ *i = (unsigned char)(x & 0xff); ++i;
+ *i = (unsigned char)((x >> 8) & 0xff); ++i;
+ *i = (unsigned char)((x >> 16) & 0xff); ++i;
+ *i = (unsigned char)((x >> 24) & 0xff); ++i;
return i;
}
template<class NumType, class ConstIterator>
if (zeroes) {
cerr << "Will fill with zero bytes\n";
for (size_t i = 0; i < BUF_SIZE; ++i) buf[i] = 0;
- zeroFile = files.size();
+ zeroFile = (int)files.size();
}
size_t sizeLeft = size;
while (sizeLeft > 0 && o) {
size_t n = (sizeLeft < BUF_SIZE ? sizeLeft : BUF_SIZE);
if (!zeroes)
- for (size_t i = 0; i < n; ++i) buf[i] = rand.get(8);
+ for (size_t i = 0; i < n; ++i) buf[i] = (byte)rand.get(8);
writeBytes(o, buf, n);
if (!o) cerr << "Argh - write() failed! (" << strerror(errno)
<< ')' << endl;
size_t add = 128 - left_over > len ? len : 128 - left_over;
memcpy (&ctx->buffer[left_over], buffer, add);
- ctx->buflen += add;
+ ctx->buflen += (uint32)add;
if (ctx->buflen > 64)
{
left_over -= 64;
memcpy (ctx->buffer, &ctx->buffer[64], left_over);
}
- ctx->buflen = left_over;
+ ctx->buflen = (uint32)left_over;
}
}
/* First increment the byte count. RFC 1321 specifies the possible
length of the file up to 2^64 bits. Here we only compute the
number of bytes. Do a double word increment. */
- ctx->total[0] += len;
+ ctx->total[0] += (uint32)len;
if (ctx->total[0] < len)
++ctx->total[1];
Logger msg("general");
Logger::Logger(const char* unitName, bool enabled)
- : unitNameVal(unitName), unitNameLen(strlen(unitName)),
+ : unitNameVal(unitName), unitNameLen((unsigned char)strlen(unitName)),
enabledVal(enabled), next(list) {
list = this;
}
unsigned i = 0;
string word;
bool enable;
- unsigned len = s.length();
+ unsigned long len = s.length();
while (i < len) {
word.erase();
enable = true;
RsyncSum& RsyncSum::removeFront(const byte* mem, size_t len,
size_t areaSize) {
RsyncSum front(mem, len);
- uint32 a = sum;
- uint32 b = sum >> 16;
+ unsigned long a = sum;
+ unsigned long b = sum >> 16;
/* The following is much cheaper than subtracting
(areaSize-i)*(mem[i]+CHAR_OFFSET) from b for each i, 0<=i<len,
because only one multiplication is needed, not len. */
RsyncSum& RsyncSum::addBackNtimes(byte x, size_t n) {
uint32 a = sum;
uint32 b = sum >> 16;
- b += n * a + (n * (n + 1) / 2) * (x + CHAR_OFFSET); // Gauß
- a += n * (x + CHAR_OFFSET);
+ uint32 tn = (uint32)n;
+ b += tn * a + (tn * (tn + 1) / 2) * (x + CHAR_OFFSET); // Gauß
+ a += tn * (x + CHAR_OFFSET);
sum = ((a & 0xffff) + (b << 16)) & 0xffffffff;
return *this;
}
RsyncSum& RsyncSum::removeFront(byte x, size_t areaSize) {
uint32 a = sum;
uint32 b = sum >> 16;
- b -= areaSize * (x + CHAR_OFFSET);
+ uint32 ta = (uint32)areaSize;
+ b -= ta * (x + CHAR_OFFSET);
a -= x + CHAR_OFFSET;
sum = ((a & 0xffff) + (b << 16)) & 0xffffffff;
return *this;
// gaussProd = n*(n+1)/2, but need to do the "/2" before the "*",
// otherwise bit 31 of result is lost on 32-bit architectures.
uint32 gaussProd;
- if (n % 2 == 0)
- gaussProd = (n / 2) * (n + 1);
+ uint32 tn = (uint32)n;
+ if (tn % 2 == 0)
+ gaussProd = (tn / 2) * (tn + 1);
else
- gaussProd = ((n + 1) / 2) * n;
- sumHi = (sumHi + n * sumLo + gaussProd * charTable[x]) & 0xffffffff;
- sumLo = (sumLo + n * charTable[x]) & 0xffffffff;
+ gaussProd = ((tn + 1) / 2) * tn;
+ sumHi = (sumHi + tn * sumLo + gaussProd * charTable[x]) & 0xffffffff;
+ sumLo = (sumLo + tn * charTable[x]) & 0xffffffff;
return *this;
}
// Create output
string result;
const char* i = format - 1;
- char max = '1' + args;
+ int max = '1' + args;
while (*++i != '\0') {
if (*i != '%') { result += *i; continue; }
++i;
virtual unsigned partId();
virtual void deflateEnd();
virtual void deflateReset();
- virtual unsigned totalOut() const { return z.total_out; }
- virtual unsigned totalIn() const { return z.total_in; }
+ virtual unsigned totalOut() const { return (unsigned)z.total_out; }
+ virtual unsigned totalIn() const { return (unsigned)z.total_in; }
virtual unsigned availOut() const { return z.avail_out; }
virtual unsigned availIn() const { return z.avail_in; }
virtual byte* nextOut() const { return z.next_out; }
ZibstreamGz() : status(0), memReleased(true) { }
~ZibstreamGz() { Assert(memReleased); }
- virtual unsigned totalOut() const { return z.total_out; }
- virtual unsigned totalIn() const { return z.total_in; }
+ virtual unsigned totalOut() const { return (unsigned)z.total_out; }
+ virtual unsigned totalIn() const { return (unsigned)z.total_in; }
virtual unsigned availOut() const { return z.avail_out; }
virtual unsigned availIn() const { return z.avail_in; }
virtual byte* nextOut() const { return z.next_out; }
//____________________
// Read data from file into buffer?
- unsigned toRead = (dataLen < bufSize ? dataLen : bufSize);
+ unsigned long toRead = (dataLen < bufSize ? dataLen : bufSize);
byte* b = &buf[0];
z->setNextIn(b);
- z->setAvailIn(toRead);
+ z->setAvailIn((unsigned int)toRead);
dataLen -= toRead;
while (*stream && toRead > 0) {
readBytes(*stream, b, toRead);
- unsigned n = stream->gcount();
+ unsigned n = (unsigned)stream->gcount();
b += n;
toRead -= n;
}