DiscussionsIssue archiveOCCT:Visualization

Archived issue #0029165

Visualization - misuse of enumeration in Prs3d_DatumAspect

Open CASCADEOCCT:Visualizationclosed7 public notes

Search issues

Description

When OCCT is built with GCC 7.1 compiler (MinGw-64), it reports warning "enum constant in boolean context" [-Wint-in-bool-context] in Prs3d_DatumAspect.

The code looks as follows:

void Prs3d_DatumAspect::SetDrawFirstAndSecondAxis (Standard_Boolean theToDraw)
{
  if (theToDraw)
  {
    myAxes = Prs3d_DatumAxes(myAxes | Prs3d_DA_XAxis | Prs3d_DA_YAxis);
  }
  else
  {
    myAxes = Prs3d_DatumAxes(myAxes & !Prs3d_DA_XAxis & !Prs3d_DA_YAxis);
  }
}

The expressions in parentheses yield integers. It is not correct to cast integer to enum, as it is not guaranteed to yield a valid value for that enum.

Here Prs3d_DatumAxes is enum with defined single bit values for X=1, Y=2, Z=4, and bit combinations XY, XZ, YZ, XYZ. The second assignment will yield zero if myAxes in the beginning equal to e.g. Prs3d_DA_XAxis. However, zero is not valid value for Prs3d_DatumAxes enum.

Steps to reproduce

Build OCCT with GCC 7.1 (e.g. with MinGw-64)

Public activity

7 archived notes

Participants are labeled by their role within this record.

01Commenter 2
Branch [archived branch] has been created by Author.

[revision removed]


Detailed log of new commits:

Author: Author
Date: Fri Sep 29 19:04:13 2017 +0300

    0029165: Visualization - misuse of enumeration in Prs3d_DatumAspect
    
    Methods SetDrawFirstAndSecondAxis() and SetDrawThirdAxis() of the class Prs3d_DatumAspect are corrected to ensure that myAxis may be set only to valid values of the enum, and avoid unsafe operations.
02Commenter 2
Branch [archived branch] has been updated forcibly by Author.

[revision removed]
03Commenter 2
Branch [archived branch] has been updated forcibly by Author.

[revision removed]
04Commenter 4
Fix is pushed to branch CR29165, please review
05Commenter 3
Please test the patch.
06Commenter 1
Tested in framework of testing issue 29170
07Commenter 2
Branch [archived branch] has been deleted by Commenter 3.

[revision removed]

Related records