Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#8568 closed Bugs (fixed)

Infinite loop in hash_value_signed/hash_value_unsigned

Reported by: alex@… 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)

loop_warning.patch (1.7 KB ) - added by Bikineev Anton <abikineev@…> 9 years ago.
pragma warning disable for msvc is added

Download all attachments as: .zip

Change History (5)

by Bikineev Anton <abikineev@…>, 9 years ago

Attachment: loop_warning.patch added

pragma warning disable for msvc is added

comment:1 by anonymous, 9 years ago

Component: functionalhash
Owner: changed from No-Maintainer to Daniel James

comment:2 by Daniel James, 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 Daniel James, 9 years ago

Resolution: fixed
Status: newclosed

(In [85389]) Merge Hash. Fixes #8568, Refs #8822.#8822.#8822.

comment:4 by qiaozhiqiang@…, 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.

Note: See TracTickets for help on using tickets.