mirror of https://github.com/google/snappy.git
When we compare the number of bytes produced with the offset for a
backreference, make the signedness of the bytes produced clear, by sticking it into a size_t. This avoids a signed/unsigned compare warning from MSVC (public issue 71), and also is slightly clearer. Since the line is now so long the explanatory comment about the -1u trick has to go somewhere else anyway, I used the opportunity to explain it in slightly more detail. This is a purely stylistic change; the emitted assembler from GCC is identical. R=jeff git-svn-id: https://snappy.googlecode.com/svn/trunk@79 03e5f5b5-db94-4691-08a0-1a8bf15f6143
This commit is contained in:
parent
2f0aaf8631
commit
7c3c01df77
15
snappy.cc
15
snappy.cc
|
@ -1185,7 +1185,16 @@ class SnappyArrayWriter {
|
||||||
char* op = op_;
|
char* op = op_;
|
||||||
const size_t space_left = op_limit_ - op;
|
const size_t space_left = op_limit_ - op;
|
||||||
|
|
||||||
if (op - base_ <= offset - 1u) { // -1u catches offset==0
|
// Check if we try to append from before the start of the buffer.
|
||||||
|
// Normally this would just be a check for "produced < offset",
|
||||||
|
// but "produced <= offset - 1u" is equivalent for every case
|
||||||
|
// except the one where offset==0, where the right side will wrap around
|
||||||
|
// to a very big number. This is convenient, as offset==0 is another
|
||||||
|
// invalid case that we also want to catch, so that we do not go
|
||||||
|
// into an infinite loop.
|
||||||
|
assert(op >= base_);
|
||||||
|
size_t produced = op - base_;
|
||||||
|
if (produced <= offset - 1u) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (len <= 16 && offset >= 8 && space_left >= 16) {
|
if (len <= 16 && offset >= 8 && space_left >= 16) {
|
||||||
|
@ -1255,7 +1264,9 @@ class SnappyDecompressionValidator {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
inline bool AppendFromSelf(size_t offset, size_t len) {
|
inline bool AppendFromSelf(size_t offset, size_t len) {
|
||||||
if (produced_ <= offset - 1u) return false; // -1u catches offset==0
|
// See SnappyArrayWriter::AppendFromSelf for an explanation of
|
||||||
|
// the "offset - 1u" trick.
|
||||||
|
if (produced_ <= offset - 1u) return false;
|
||||||
produced_ += len;
|
produced_ += len;
|
||||||
return produced_ <= expected_;
|
return produced_ <= expected_;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue