diff options
author | snappy.mirrorbot@gmail.com <snappy.mirrorbot@gmail.com@03e5f5b5-db94-4691-08a0-1a8bf15f6143> | 2013-07-29 11:06:44 +0000 |
---|---|---|
committer | snappy.mirrorbot@gmail.com <snappy.mirrorbot@gmail.com@03e5f5b5-db94-4691-08a0-1a8bf15f6143> | 2013-07-29 11:06:44 +0000 |
commit | 7c3c01df77e191ad1f8377448961fe88db2802e9 (patch) | |
tree | de1b3ec62aec395640cc52bcfb0ce09d6e709a7d | |
parent | 2f0aaf8631d8fb2475ca1a6687c181efb14ed286 (diff) | |
download | snappy-git-7c3c01df77e191ad1f8377448961fe88db2802e9.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: https://snappy.googlecode.com/svn/trunk@79 03e5f5b5-db94-4691-08a0-1a8bf15f6143
-rw-r--r-- | snappy.cc | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -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_; } |