View Issue Details

IDProjectCategoryView StatusLast Update
0030720Open CASCADEOCCT:Codingpublic2019-10-23 12:04
ReportertizmayloAssigned Tobugmaster  
PrioritynormalSeverityminor 
Status closedResolutionfixed 
Product Version7.4.0 
Target Version7.4.0Fixed in Version7.4.0 
Summary0030720: Coding - fix HashCode() function problems that are not resolved with 30550
DescriptionThere are some problems that were not resolved with 0030550:

  • undefined behavior caused by left shift operations in TopLoc_Location::HashCode() function is not fixed (look at the places where the local variable depth is used);

  • HashCode() functions are not fixed in OCC Products;

  • HashCode() function overload for unsigned int behaves differently on 32-bit and 64-bit platforms (on 32-bit platform it is disabled via SFINAE and HashCode() function overload for std::size_t type is used because std::size_t == unsigned int).


To solve the problem with other projects it may be useful to add asserts to methods of map classes that are dealing with hash codes to check their values to be strictly one-based (not zero-based).
Steps To ReproduceNot required
TagsNo tags attached.
Test case numberNot required

Relationships

child of 0030550 closedbugmaster Community Coding - Integer overflow in Standard_CString HashCodes 

Activities

git

2019-09-05 19:59

administrator   ~0086817

Branch CR30720 has been created by tizmaylo.

SHA-1: 58828d2acf8b61ec40f099a46b27b9a49b5a4f26


Detailed log of new commits:

Author: tiv
Date: Thu Sep 5 19:30:47 2019 +0300

    0030720: Coding - fix HashCode() function problems that are not resolved with 30550
    
    Undefined behavior caused by left shift operations in TopLoc_Location::HashCode() function is fixed.
    HashCode() function overload for Standard_Size type is made available only if Standard_Size and "unsigned int" are different types (it is usually true for 64-bit platforms). The overload for "unsigned int" is made simple non-templated function (so it behaves the same on 32-bit and 64-bit platforms).

tizmaylo

2019-09-05 20:16

developer   ~0086819

Patch is ready for review (at the time of writing, the tests have not passed yet, but I hope everything will be OK): http://jenkins-test-12.nnov.opencascade.com:8080/view/CR30720-master-TIV/view/ALL/

OCCT branch: CR30720
Branch in OCCT Products: CR30720

bugmaster

2019-09-06 22:09

administrator   ~0086914

Regressions on Products:

http://jenkins-test-12.nnov.opencascade.com/view/CR30720-master-TIV/view/COMPARE/

git

2019-09-24 12:14

administrator   ~0087466

Branch CR30720 has been updated forcibly by tizmaylo.

SHA-1: 7d309b94bf82625152942c96202fd0ebe35cc17c

git

2019-09-24 16:48

administrator   ~0087488

Branch CR30720 has been updated by tizmaylo.

SHA-1: 86eb424f30f5cffd39c6bdc16be633e8a8fbf2c6


Detailed log of new commits:

Author: tiv
Date: Tue Sep 24 16:39:56 2019 +0300

    # HashCode() overload for Standard_Utf32Char type is fixed to be compilable with old version of compilers (e.g. MSVS 2010).

git

2019-09-24 16:48

administrator   ~0087489

Branch CR30720_1 has been created by tizmaylo.

SHA-1: 238bfda1dcaf1d1dfde4d29a5960212ddea36352


Detailed log of new commits:

Author: tiv
Date: Tue Sep 24 16:42:21 2019 +0300

    0030720: Coding - fix HashCode() function problems that are not resolved with 30550
    
    Undefined behavior caused by left shift operations in TopLoc_Location::HashCode() function is fixed.
    HashCode() function overload for Standard_Size type is made available only if Standard_Size and "unsigned int" are different types (it is usually true for 64-bit platforms). The overload for "unsigned int" is made simple non-templated function (so it behaves the same on 32-bit and 64-bit platforms).
    HashCode() function overload for Standard_Utf32Char type is made available only if Standard_Utf32Char and "unsigned int" are different types (it is needed for some old compilers).

tizmaylo

2019-09-24 18:53

developer   ~0087494

Patch is ready for review: http://vm-jenkins-test-12.nnov.opencascade.com:8080/view/CR30720-master-TIV/view/ALL/

OCCT branch: CR30720
OCCT branch with squashed commits: CR30720_1
OCCT Products branch: CR30720
OCCT Products branch with squashed commits: CR30720_1

kgv

2019-09-24 20:34

developer   ~0087495

Last edited: 2019-09-24 20:35

Practically speaking, Font_BRepFont and OpenGl_Font are the only two places using Standard_Utf32Char as a key in map.
Therefore, moving hasher to dedicated structure for Standard_Utf32Char type would fix global collision of Hash/IsEqual methods.
> NCollection_DataMap<Standard_Utf32Char, Standard_Integer> myGlyphMap;
> NCollection_DataMap<Standard_Utf32Char, TopoDS_Shape> myCache;

bugmaster

2019-09-25 15:56

administrator   ~0087511

Combination -
OCCT branch : CR30720_1
master SHA - 238bfda1dcaf1d1dfde4d29a5960212ddea36352
5f5b1aed1c6e139bbd34314eca77ae7abcd8895c
Products branch : CR30720_1 SHA - 83df4cb7aa05ca0b1f190a68462fc970ee162d17
was compiled on Linux, MacOS and Windows platforms and tested in optimize mode.

Number of compiler warnings:
No new/fixed warnings

Regressions/Differences/Improvements:
No regressions/differences

CPU differences:
Debian80-64:
OCCT
Total CPU difference: 16819.760000000093 / 16808.79000000008 [+0.07%]
Products
Total CPU difference: 10575.410000000034 / 10573.91000000004 [+0.01%]
Windows-64-VC14:
OCCT
Total CPU difference: 18320.0625 / 18298.78125 [+0.12%]
Products
Total CPU difference: 12486.3125 / 12507.671875 [-0.17%]


Image differences :
No differences that require special attention

Memory differences :
No differences that require special attention

git

2019-09-29 12:36

administrator   ~0087615

Branch CR30720 has been deleted by inv.

SHA-1: 86eb424f30f5cffd39c6bdc16be633e8a8fbf2c6

git

2019-09-29 12:36

administrator   ~0087616

Branch CR30720_1 has been deleted by inv.

SHA-1: 238bfda1dcaf1d1dfde4d29a5960212ddea36352

Related Changesets

occt: master 467e864a

2019-09-24 13:42:21

tiv


Committer: bugmaster Details Diff
0030720: Coding - fix HashCode() function problems that are not resolved with 30550

Undefined behavior caused by left shift operations in TopLoc_Location::HashCode() function is fixed.
HashCode() function overload for Standard_Size type is made available only if Standard_Size and "unsigned int" are different types (it is usually true for 64-bit platforms). The overload for "unsigned int" is made simple non-templated function (so it behaves the same on 32-bit and 64-bit platforms).
HashCode() function overload for Standard_Utf32Char type is made available only if Standard_Utf32Char and "unsigned int" are different types (it is needed for some old compilers).
Affected Issues
0030720
mod - src/Standard/Standard_Integer.hxx Diff File
mod - src/Standard/Standard_Size.hxx Diff File
mod - src/TopLoc/TopLoc_Location.cxx Diff File

Issue History

Date Modified Username Field Change
2019-05-20 12:37 tizmaylo New Issue
2019-05-20 12:37 tizmaylo Assigned To => kgv
2019-05-20 12:42 kgv Relationship added child of 0030550
2019-05-20 12:43 kgv Description Updated
2019-05-21 18:41 tizmaylo Description Updated
2019-09-04 17:11 kgv Product Version => 7.4.0
2019-09-04 17:11 kgv Target Version 7.4.0 => 7.5.0
2019-09-04 17:33 kgv Assigned To kgv => tizmaylo
2019-09-04 17:33 kgv Status new => assigned
2019-09-04 17:33 kgv Target Version 7.5.0 => 7.4.0
2019-09-05 19:59 git Note Added: 0086817
2019-09-05 20:16 tizmaylo Note Added: 0086819
2019-09-05 20:18 tizmaylo Assigned To tizmaylo => abv
2019-09-05 20:18 tizmaylo Status assigned => resolved
2019-09-05 20:18 tizmaylo Steps to Reproduce Updated
2019-09-06 11:12 kgv Assigned To abv => bugmaster
2019-09-06 11:12 kgv Status resolved => reviewed
2019-09-06 22:09 bugmaster Note Added: 0086914
2019-09-06 22:09 bugmaster Assigned To bugmaster => tizmaylo
2019-09-06 22:09 bugmaster Status reviewed => assigned
2019-09-17 06:50 abv Target Version 7.4.0 => 7.5.0
2019-09-24 12:14 git Note Added: 0087466
2019-09-24 16:48 git Note Added: 0087488
2019-09-24 16:48 git Note Added: 0087489
2019-09-24 18:53 tizmaylo Note Added: 0087494
2019-09-24 18:54 tizmaylo Assigned To tizmaylo => kgv
2019-09-24 18:54 tizmaylo Status assigned => resolved
2019-09-24 20:34 kgv Note Added: 0087495
2019-09-24 20:34 kgv Assigned To kgv => bugmaster
2019-09-24 20:34 kgv Status resolved => reviewed
2019-09-24 20:34 kgv Target Version 7.5.0 => 7.4.0
2019-09-24 20:35 kgv Note Edited: 0087495
2019-09-25 15:53 bugmaster Test case number => Not required
2019-09-25 15:56 bugmaster Note Added: 0087511
2019-09-25 15:56 bugmaster Status reviewed => tested
2019-09-29 12:19 bugmaster Changeset attached => occt master 467e864a
2019-09-29 12:19 bugmaster Status tested => verified
2019-09-29 12:19 bugmaster Resolution open => fixed
2019-09-29 12:36 git Note Added: 0087615
2019-09-29 12:36 git Note Added: 0087616