mirror of
https://github.com/vgough/encfs.git
synced 2024-11-24 17:03:13 +01:00
Correct sign-compare warnings
This commit is contained in:
parent
53196f1927
commit
2af7c56254
@ -35,12 +35,12 @@ inline Type min(Type A, Type B) {
|
|||||||
return (B < A) ? B : A;
|
return (B < A) ? B : A;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void clearCache(IORequest &req, int blockSize) {
|
static void clearCache(IORequest &req, unsigned int blockSize) {
|
||||||
memset(req.data, 0, blockSize);
|
memset(req.data, 0, blockSize);
|
||||||
req.dataLen = 0;
|
req.dataLen = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockFileIO::BlockFileIO(int blockSize, const FSConfigPtr &cfg)
|
BlockFileIO::BlockFileIO(unsigned int blockSize, const FSConfigPtr &cfg)
|
||||||
: _blockSize(blockSize), _allowHoles(cfg->config->allowHoles) {
|
: _blockSize(blockSize), _allowHoles(cfg->config->allowHoles) {
|
||||||
CHECK(_blockSize > 1);
|
CHECK(_blockSize > 1);
|
||||||
_cache.data = new unsigned char[_blockSize];
|
_cache.data = new unsigned char[_blockSize];
|
||||||
@ -89,7 +89,7 @@ ssize_t BlockFileIO::cacheReadOneBlock(const IORequest &req) const {
|
|||||||
if (result > 0) {
|
if (result > 0) {
|
||||||
_cache.offset = req.offset;
|
_cache.offset = req.offset;
|
||||||
_cache.dataLen = result; // the amount we really have
|
_cache.dataLen = result; // the amount we really have
|
||||||
if (result > req.dataLen) {
|
if ((size_t)result > req.dataLen) {
|
||||||
result = req.dataLen; // only as much as requested
|
result = req.dataLen; // only as much as requested
|
||||||
}
|
}
|
||||||
memcpy(req.data, _cache.data, result);
|
memcpy(req.data, _cache.data, result);
|
||||||
@ -146,7 +146,7 @@ ssize_t BlockFileIO::read(const IORequest &req) const {
|
|||||||
|
|
||||||
// if we're reading a full block, then read directly into the
|
// if we're reading a full block, then read directly into the
|
||||||
// result buffer instead of using a temporary
|
// result buffer instead of using a temporary
|
||||||
if (partialOffset == 0 && size >= (size_t)_blockSize) {
|
if (partialOffset == 0 && size >= _blockSize) {
|
||||||
blockReq.data = out;
|
blockReq.data = out;
|
||||||
} else {
|
} else {
|
||||||
if (mb.data == nullptr) {
|
if (mb.data == nullptr) {
|
||||||
@ -164,8 +164,8 @@ ssize_t BlockFileIO::read(const IORequest &req) const {
|
|||||||
break; // didn't get enough bytes
|
break; // didn't get enough bytes
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t cpySize = min((size_t)(readSize - partialOffset), size);
|
size_t cpySize = min((size_t)readSize - (size_t)partialOffset, size);
|
||||||
CHECK(cpySize <= readSize);
|
CHECK(cpySize <= (size_t)readSize);
|
||||||
|
|
||||||
// if we read to a temporary buffer, then move the data
|
// if we read to a temporary buffer, then move the data
|
||||||
if (blockReq.data != out) {
|
if (blockReq.data != out) {
|
||||||
@ -256,7 +256,7 @@ ssize_t BlockFileIO::write(const IORequest &req) {
|
|||||||
// if writing an entire block, or writing a partial block that requires
|
// if writing an entire block, or writing a partial block that requires
|
||||||
// no merging with existing data..
|
// no merging with existing data..
|
||||||
if ((toCopy == _blockSize) ||
|
if ((toCopy == _blockSize) ||
|
||||||
(partialOffset == 0 && blockReq.offset + toCopy >= fileSize)) {
|
(partialOffset == 0 && blockReq.offset + (off_t)toCopy >= fileSize)) {
|
||||||
// write directly from buffer
|
// write directly from buffer
|
||||||
blockReq.data = inPtr;
|
blockReq.data = inPtr;
|
||||||
blockReq.dataLen = toCopy;
|
blockReq.dataLen = toCopy;
|
||||||
@ -314,7 +314,7 @@ ssize_t BlockFileIO::write(const IORequest &req) {
|
|||||||
return req.dataLen;
|
return req.dataLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BlockFileIO::blockSize() const { return _blockSize; }
|
unsigned int BlockFileIO::blockSize() const { return _blockSize; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns 0 in case of success, or -errno in case of failure.
|
* Returns 0 in case of success, or -errno in case of failure.
|
||||||
|
@ -38,14 +38,14 @@ namespace encfs {
|
|||||||
*/
|
*/
|
||||||
class BlockFileIO : public FileIO {
|
class BlockFileIO : public FileIO {
|
||||||
public:
|
public:
|
||||||
BlockFileIO(int blockSize, const FSConfigPtr &cfg);
|
BlockFileIO(unsigned int blockSize, const FSConfigPtr &cfg);
|
||||||
virtual ~BlockFileIO();
|
virtual ~BlockFileIO();
|
||||||
|
|
||||||
// implemented in terms of blocks.
|
// implemented in terms of blocks.
|
||||||
virtual ssize_t read(const IORequest &req) const;
|
virtual ssize_t read(const IORequest &req) const;
|
||||||
virtual ssize_t write(const IORequest &req);
|
virtual ssize_t write(const IORequest &req);
|
||||||
|
|
||||||
virtual int blockSize() const;
|
virtual unsigned int blockSize() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int truncateBase(off_t size, FileIO *base);
|
int truncateBase(off_t size, FileIO *base);
|
||||||
@ -59,7 +59,7 @@ class BlockFileIO : public FileIO {
|
|||||||
ssize_t cacheReadOneBlock(const IORequest &req) const;
|
ssize_t cacheReadOneBlock(const IORequest &req) const;
|
||||||
ssize_t cacheWriteOneBlock(const IORequest &req);
|
ssize_t cacheWriteOneBlock(const IORequest &req);
|
||||||
|
|
||||||
int _blockSize;
|
unsigned int _blockSize;
|
||||||
bool _allowHoles;
|
bool _allowHoles;
|
||||||
bool _noCache;
|
bool _noCache;
|
||||||
|
|
||||||
|
@ -377,7 +377,7 @@ ssize_t CipherFileIO::writeOneBlock(const IORequest &req) {
|
|||||||
return -EPERM;
|
return -EPERM;
|
||||||
}
|
}
|
||||||
|
|
||||||
int bs = blockSize();
|
unsigned int bs = blockSize();
|
||||||
off_t blockNum = req.offset / bs;
|
off_t blockNum = req.offset / bs;
|
||||||
|
|
||||||
if (haveHeader && fileIV == 0) {
|
if (haveHeader && fileIV == 0) {
|
||||||
@ -535,7 +535,7 @@ ssize_t CipherFileIO::read(const IORequest &origReq) const {
|
|||||||
* to the data. */
|
* to the data. */
|
||||||
if (req.offset < 0) {
|
if (req.offset < 0) {
|
||||||
headerBytes = -req.offset;
|
headerBytes = -req.offset;
|
||||||
if (req.dataLen < headerBytes) {
|
if (req.dataLen < (size_t)headerBytes) {
|
||||||
headerBytes = req.dataLen; // only up to the number of bytes requested
|
headerBytes = req.dataLen; // only up to the number of bytes requested
|
||||||
}
|
}
|
||||||
VLOG(1) << "Adding " << headerBytes << " header bytes";
|
VLOG(1) << "Adding " << headerBytes << " header bytes";
|
||||||
@ -546,7 +546,7 @@ ssize_t CipherFileIO::read(const IORequest &origReq) const {
|
|||||||
memcpy(req.data, &headerBuf[headerOffset], headerBytes);
|
memcpy(req.data, &headerBuf[headerOffset], headerBytes);
|
||||||
|
|
||||||
// the read does not want data beyond the header
|
// the read does not want data beyond the header
|
||||||
if (headerBytes == req.dataLen) {
|
if ((size_t)headerBytes == req.dataLen) {
|
||||||
return headerBytes;
|
return headerBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ FileIO::FileIO() = default;
|
|||||||
|
|
||||||
FileIO::~FileIO() = default;
|
FileIO::~FileIO() = default;
|
||||||
|
|
||||||
int FileIO::blockSize() const { return 1; }
|
unsigned int FileIO::blockSize() const { return 1; }
|
||||||
|
|
||||||
bool FileIO::setIV(uint64_t iv) {
|
bool FileIO::setIV(uint64_t iv) {
|
||||||
(void)iv;
|
(void)iv;
|
||||||
|
@ -50,7 +50,7 @@ class FileIO {
|
|||||||
virtual Interface interface() const = 0;
|
virtual Interface interface() const = 0;
|
||||||
|
|
||||||
// default implementation returns 1, meaning this is not block oriented.
|
// default implementation returns 1, meaning this is not block oriented.
|
||||||
virtual int blockSize() const;
|
virtual unsigned int blockSize() const;
|
||||||
|
|
||||||
virtual void setFileName(const char *fileName) = 0;
|
virtual void setFileName(const char *fileName) = 0;
|
||||||
virtual const char *getFileName() const = 0;
|
virtual const char *getFileName() const = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user