From: Alex Rousskov Date: Mon, 23 May 2016 23:20:27 +0000 (-0600) Subject: Bug 4517 error: comparison between signed and unsigned integer X-Git-Tag: SQUID_4_0_11~12 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0792f48915b745311fe66aa6389f450861a1df8d;p=thirdparty%2Fsquid.git Bug 4517 error: comparison between signed and unsigned integer 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. --- diff --git a/src/fs/rock/RockIoState.cc b/src/fs/rock/RockIoState.cc index 983adc45c0..7d5e8e44f2 100644 --- a/src/fs/rock/RockIoState.cc +++ b/src/fs/rock/RockIoState.cc @@ -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(dir->maxObjectSize())); + Must(static_cast(offset_ + size) <= static_cast(dir->maxObjectSize())); // allocate the first slice during the first write if (!coreOff) { diff --git a/src/fs/ufs/UFSStoreState.cc b/src/fs/ufs/UFSStoreState.cc index e4527a0c09..799af4e6a4 100644 --- a/src/fs/ufs/UFSStoreState.cc +++ b/src/fs/ufs/UFSStoreState.cc @@ -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(dir.maxObjectSize())) { + if (static_cast(offset_ + size) > static_cast(dir.maxObjectSize())) { debugs(79, 2, "accepted unknown-size entry grew too big: " << (offset_ + size) << " > " << dir.maxObjectSize()); free_func((void*)buf);