Modify

Opened 4 years ago

Closed 4 years ago

Last modified 4 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@…> 4 years ago.
pragma warning disable for msvc is added

Download all attachments as: .zip

Change History (5)

Changed 4 years ago by Bikineev Anton <abikineev@…>

Attachment: loop_warning.patch added

pragma warning disable for msvc is added

comment:1 Changed 4 years ago by anonymous

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

comment:2 Changed 4 years ago by Daniel James

(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 Changed 4 years ago by Daniel James

Resolution: fixed
Status: newclosed

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

comment:4 Changed 4 years ago by qiaozhiqiang@…

unsigned int i, so i >= 0, so i > 0 is i != 0

we should change i > 0 to i != 0 to avoid warning.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Daniel James.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.