summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsnappy.mirrorbot@gmail.com <snappy.mirrorbot@gmail.com@03e5f5b5-db94-4691-08a0-1a8bf15f6143>2013-07-29 11:06:44 +0000
committersnappy.mirrorbot@gmail.com <snappy.mirrorbot@gmail.com@03e5f5b5-db94-4691-08a0-1a8bf15f6143>2013-07-29 11:06:44 +0000
commitdbec3104c85b199721edc6ac94e2ea5f6dc58b84 (patch)
treede1b3ec62aec395640cc52bcfb0ce09d6e709a7d
parent6d852fa5e3f04286a7b36336d2cca0a609dc89b2 (diff)
downloadsnappy-dbec3104c85b199721edc6ac94e2ea5f6dc58b84.tar.gz
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: http://snappy.googlecode.com/svn/trunk@79 03e5f5b5-db94-4691-08a0-1a8bf15f6143
-rw-r--r--snappy.cc15
1 files changed, 13 insertions, 2 deletions
diff --git a/snappy.cc b/snappy.cc
index 341c9a0..f8d0d23 100644
--- a/snappy.cc
+++ b/snappy.cc
@@ -1185,7 +1185,16 @@ class SnappyArrayWriter {
char* op = 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;
}
if (len <= 16 && offset >= 8 && space_left >= 16) {
@@ -1255,7 +1264,9 @@ class SnappyDecompressionValidator {
return false;
}
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;
return produced_ <= expected_;
}