]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 4517 error: comparison between signed and unsigned integer
authorAlex Rousskov <rousskov@measurement-factory.com>
Mon, 23 May 2016 23:20:27 +0000 (17:20 -0600)
committerAlex Rousskov <rousskov@measurement-factory.com>
Mon, 23 May 2016 23:20:27 +0000 (17:20 -0600)
The old cast is required when size_t is unsigned (as it should be).
The new cast is required when size_t is signed (as it may be).

We could cast just the left-hand side to be signed instead, but it feels
slightly wrong to do that here because all values we are casting are
meant to be unsigned and, hence, in theory, might overflow in some
future version of the code if we cast them to a signed value now and
forget to fix that cast later while adding support for larger values.

src/fs/rock/RockIoState.cc
src/fs/ufs/UFSStoreState.cc

index 983adc45c07a001c1b65451f85df1f17c9201499..7d5e8e44f2f61e91ba9461f324e11de2b1aca4fe 100644 (file)
@@ -185,7 +185,7 @@ Rock::IoState::tryWrite(char const *buf, size_t size, off_t coreOff)
     assert(!coreOff || coreOff == -1);
 
     // throw if an accepted unknown-size entry grew too big or max-size changed
-    Must(offset_ + size <= static_cast<uint64_t>(dir->maxObjectSize()));
+    Must(static_cast<uint64_t>(offset_ + size) <= static_cast<uint64_t>(dir->maxObjectSize()));
 
     // allocate the first slice during the first write
     if (!coreOff) {
index e4527a0c09683c9b5b66f604b710cc4c2efa1e3b..799af4e6a4daa319e3647752ace9885d4826eb18 100644 (file)
@@ -169,7 +169,7 @@ Fs::Ufs::UFSStoreState::write(char const *buf, size_t size, off_t aOffset, FREE
     }
 
     const Store::Disk &dir = *INDEXSD(swap_dirn);
-    if (offset_ + size > static_cast<uint64_t>(dir.maxObjectSize())) {
+    if (static_cast<uint64_t>(offset_ + size) > static_cast<uint64_t>(dir.maxObjectSize())) {
         debugs(79, 2, "accepted unknown-size entry grew too big: " <<
                (offset_ + size) << " > " << dir.maxObjectSize());
         free_func((void*)buf);