#8568 closed Bugs (fixed)
Infinite loop in hash_value_signed/hash_value_unsigned
| Reported by: | Owned by: | Daniel James | |
|---|---|---|---|
| Milestone: | To Be Determined | Component: | hash |
| Version: | Boost 1.53.0 | Severity: | Problem |
| Keywords: | Cc: |
Description
Visual C++ 2012 static analysis found these two infinite loop warnings in hash.hpp:
for(unsigned int i = length * size_t_bits; i > 0; i -= size_t_bits)
{
seed ^= (std::size_t) (positive >> i) + (seed<<6) + (seed>>2);
}
Warning message:
hash.hpp(156): warning : C6295: Ill-defined for-loop: 'unsigned int' values are always of range '0' to '4294967295'. Loop executes infinitely. hash.hpp(176): warning : C6295: Ill-defined for-loop: 'unsigned int' values are always of range '0' to '4294967295'. Loop executes infinitely.
Attachments (1)
Change History (5)
by , 9 years ago
| Attachment: | loop_warning.patch added |
|---|
comment:1 by , 9 years ago
| Component: | functional → hash |
|---|---|
| Owner: | changed from to |
comment:2 by , 9 years ago
(In [85248]) Fix Visual C++ warning in hash. Refs #8568.
I changed this a little from the patch on #8568. I moved the pragmas to the start and end of the file because I don't like to little the body of the code with them (this does mean I've disabled a potentially useful warning, but the code is pretty stable nowadays).
I also removed the version checks, as the warning should be present in later versions.
comment:3 by , 9 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
comment:4 by , 9 years ago
unsigned int i, so i >= 0, so i > 0 is i != 0
we should change i > 0 to i != 0 to avoid warning.

pragma warning disable for msvc is added