-
Notifications
You must be signed in to change notification settings - Fork 283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Correct sign-compare warnings #446
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,12 +35,12 @@ inline Type min(Type A, Type B) { | |
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); | ||
req.dataLen = 0; | ||
} | ||
|
||
BlockFileIO::BlockFileIO(int blockSize, const FSConfigPtr &cfg) | ||
BlockFileIO::BlockFileIO(unsigned int blockSize, const FSConfigPtr &cfg) | ||
: _blockSize(blockSize), _allowHoles(cfg->config->allowHoles) { | ||
CHECK(_blockSize > 1); | ||
_cache.data = new unsigned char[_blockSize]; | ||
|
@@ -89,7 +89,7 @@ ssize_t BlockFileIO::cacheReadOneBlock(const IORequest &req) const { | |
if (result > 0) { | ||
_cache.offset = req.offset; | ||
_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 | ||
} | ||
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 | ||
// result buffer instead of using a temporary | ||
if (partialOffset == 0 && size >= (size_t)_blockSize) { | ||
if (partialOffset == 0 && size >= _blockSize) { | ||
blockReq.data = out; | ||
} else { | ||
if (mb.data == nullptr) { | ||
|
@@ -164,8 +164,8 @@ ssize_t BlockFileIO::read(const IORequest &req) const { | |
break; // didn't get enough bytes | ||
} | ||
|
||
size_t cpySize = min((size_t)(readSize - partialOffset), size); | ||
CHECK(cpySize <= readSize); | ||
size_t cpySize = min((size_t)readSize - (size_t)partialOffset, size); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't partialOffset be unsigned? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Literally yes, but as req.offset is signed (from which it is calculated), I would say no. |
||
CHECK(cpySize <= (size_t)readSize); | ||
|
||
// if we read to a temporary buffer, then move the data | ||
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 | ||
// no merging with existing data.. | ||
if ((toCopy == _blockSize) || | ||
(partialOffset == 0 && blockReq.offset + toCopy >= fileSize)) { | ||
(partialOffset == 0 && blockReq.offset + (off_t)toCopy >= fileSize)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. toCopy is not signed, is it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, so without the cast this leads to a comparison between size_t and off_t : |
||
// write directly from buffer | ||
blockReq.data = inPtr; | ||
blockReq.dataLen = toCopy; | ||
|
@@ -314,7 +314,7 @@ ssize_t BlockFileIO::write(const IORequest &req) { | |
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. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -377,7 +377,7 @@ ssize_t CipherFileIO::writeOneBlock(const IORequest &req) { | |
return -EPERM; | ||
} | ||
|
||
int bs = blockSize(); | ||
unsigned int bs = blockSize(); | ||
off_t blockNum = req.offset / bs; | ||
|
||
if (haveHeader && fileIV == 0) { | ||
|
@@ -535,7 +535,7 @@ ssize_t CipherFileIO::read(const IORequest &origReq) const { | |
* to the data. */ | ||
if (req.offset < 0) { | ||
headerBytes = -req.offset; | ||
if (req.dataLen < headerBytes) { | ||
if (req.dataLen < (size_t)headerBytes) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't headerBytes be unsigned? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, but HEADER_SIZE itself is a int... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had an additional look, if we make HEADER_SIZE unsigned, other casts will be needed as it is compared to st_size which is an off_t... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm. Maybe we should move everything to ssize_t or int64_t. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also thought about it, but I think |
||
headerBytes = req.dataLen; // only up to the number of bytes requested | ||
} | ||
VLOG(1) << "Adding " << headerBytes << " header bytes"; | ||
|
@@ -546,7 +546,7 @@ ssize_t CipherFileIO::read(const IORequest &origReq) const { | |
memcpy(req.data, &headerBuf[headerOffset], headerBytes); | ||
|
||
// the read does not want data beyond the header | ||
if (headerBytes == req.dataLen) { | ||
if ((size_t)headerBytes == req.dataLen) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok I looked through all of the casts again. Everything seems safe except this one. It looks like headerBytes may be negative at this point. Rather cast req.dataLen to int? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mmmmh I'm not sure how I think casting Thx 👍 |
||
return headerBytes; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't _blockSize be unsigned from the start?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is unsigned now, thanks to this PR.
Here I then remove a cast which is no more needed, as size_t is unsigned.